Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add spring-javaformat checkstyle and formatting #8946

Closed
wants to merge 73 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
73 commits
Select commit Hold shift + click to select a range
307700d
Rename *Test.java -> *Tests.java
philwebb Aug 6, 2020
26ce3f9
Add noformat blocks around http config
philwebb Jul 23, 2020
804582c
Add noformat blocks around auth config
philwebb Jul 23, 2020
ffad5cb
Add noformat blocks around User.withUsername
philwebb Jul 23, 2020
f30dd16
Add noformat blocks around withDefaultPasswordEncoder
philwebb Jul 23, 2020
b88437a
Fix malformed formatter-on/off javadoc
philwebb Jul 23, 2020
8ae849c
Add spring-javaformat plugin
philwebb Jul 23, 2020
9de39f9
Reformat code using spring-javaformat
philwebb Aug 5, 2020
194c28b
Remove superfluous comments
philwebb Jul 23, 2020
fd5c8e3
Add Spring Checkstyle with all checks disabled
philwebb Jul 24, 2020
9e6d5c0
Use compact annotation style
philwebb Jul 24, 2020
b4bddc5
Suppress third-party code from checkstyle
philwebb Jul 24, 2020
b9d6aa0
Remove array style checkstyle suppression
philwebb Jul 24, 2020
19bca4a
Use consistent "@" tag order in Javadoc
philwebb Jul 24, 2020
142a6c6
Organize imports
philwebb Aug 5, 2020
d7600c6
Remove empty block
philwebb Jul 25, 2020
baee873
Make classes final where possible
philwebb Jul 25, 2020
8f9bcba
Always use 'this.' when accessing fields
philwebb Jul 26, 2020
121f659
Apply code cleanup rules to projects
philwebb Jul 26, 2020
037d970
Avoid inner assignments
philwebb Aug 6, 2020
b20c11a
Move inner-types so that they are always last
philwebb Jul 26, 2020
daf24ba
Remove (non-Javadoc) comments
philwebb Aug 6, 2020
ad10682
Ignore existing InterfaceIsType violations
philwebb Jul 27, 2020
e4a4df6
Use consistent modifier order
philwebb Jul 27, 2020
9998f64
Make all exception classes immutable
philwebb Jul 27, 2020
5d989d1
Remove "need braces" checkstyle suppression
philwebb Jul 27, 2020
ebf0add
Reduce the number of nested if statements
philwebb Jul 27, 2020
d5ea743
Ensure all files end with a new line
philwebb Jul 27, 2020
4c8aba7
Ensure no whitespace before lines
philwebb Jul 27, 2020
88cff31
Ensure classes are defined in their own files
philwebb Jul 27, 2020
d9d571b
Fix parenthesis padding issues
philwebb Jul 27, 2020
5bfffed
Remove "redundant import" checkstyle suppression
philwebb Jul 27, 2020
dbfeee9
Migrate SwitchUserWebFilterTests AssertJ
philwebb Jul 27, 2020
74d645e
Migrate to BDD Mockito
philwebb Jul 27, 2020
4347884
Simplify boolean expression
philwebb Jul 28, 2020
009e45b
Simplify boolean returns
philwebb Jul 28, 2020
78a4eca
Remove restricted static imports
philwebb Jul 28, 2020
b964f7a
Update exception variable names
philwebb Jul 29, 2020
bb760fa
Remove superfluous comments
philwebb Jul 29, 2020
9443ef7
Add whitespace after copyright header
philwebb Jul 29, 2020
f6a7852
Enforce checkstyle header rule
philwebb Jul 29, 2020
ce562d4
Hide utility class constructors
philwebb Jul 29, 2020
bde378b
Use parenthesis with single-arg lambdas
philwebb Jul 30, 2020
c0529da
Remove unnecessary lambda blocks
philwebb Jul 30, 2020
1d503db
Use consistent equals/hashCode/toString order
philwebb Jul 30, 2020
099e7cc
Reduce method visibility when possible
philwebb Jul 30, 2020
abc05b7
Use consistent ternary expression style
philwebb Jul 30, 2020
e38ffc9
Fix whitespace issues in format-off code
philwebb Jul 30, 2020
4141645
Polish spring-security-acl main code
philwebb Jul 30, 2020
6695021
Polish spring-security-cas main code
philwebb Aug 6, 2020
3ede183
Polish spring-security-config main code
philwebb Jul 30, 2020
f33548b
Polish spring-security-core main code
philwebb Jul 31, 2020
a7f5bc2
Polish spring-security-crypto main code
philwebb Jul 31, 2020
695c4f9
Polish spring-security-data main code
philwebb Jul 31, 2020
e1449cf
Polish spring-security-ldap main code
philwebb Jul 31, 2020
91ea9bf
Polish spring-security-messaging main code
philwebb Jul 31, 2020
7bacec2
Polish spring-security-oauth2-client main code
philwebb Aug 1, 2020
0a94406
Polish spring-security-oauth2-core main code
philwebb Aug 1, 2020
0edfff7
Polish spring-security-oauth2-jose main code
philwebb Aug 1, 2020
9ddc5d8
Polish spring-security-oauth2-resource-server main code
philwebb Aug 1, 2020
0ac2e2b
Polish spring-security-openid main code
philwebb Aug 1, 2020
e2cd3b1
Polish spring-security-remoting main code
philwebb Aug 1, 2020
1f07611
Polish spring-security-rsocket main code
philwebb Aug 1, 2020
9bb8edf
Polish spring-security-saml2 main code
philwebb Aug 1, 2020
b4c5ee5
Polish spring-security-taglibs main code
philwebb Aug 1, 2020
24bf959
Polish spring-security-test main code
philwebb Aug 1, 2020
41f6ecd
Polish spring-security-web main code
philwebb Aug 4, 2020
025fd90
Remove blank lines from all tests
philwebb Aug 2, 2020
2db5129
Remove incorrect AssertJ imports
philwebb Aug 4, 2020
23b8afe
Use assertThatObject to save casting
philwebb Aug 4, 2020
d649a05
Move @Mock annotations
philwebb Aug 4, 2020
d5c6645
Use assertThat instead of Java assert
philwebb Aug 4, 2020
4f3e599
Migrate to assertThatExceptionOfType
philwebb Aug 4, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
151 changes: 59 additions & 92 deletions acl/src/main/java/org/springframework/security/acls/AclEntryVoter.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.springframework.security.acls;

import java.lang.reflect.InvocationTargetException;
Expand All @@ -24,6 +25,7 @@
import org.aopalliance.intercept.MethodInvocation;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import org.springframework.security.access.AuthorizationServiceException;
import org.springframework.security.access.ConfigAttribute;
import org.springframework.security.access.vote.AbstractAclVoter;
Expand All @@ -39,6 +41,7 @@
import org.springframework.security.acls.model.SidRetrievalStrategy;
import org.springframework.security.core.Authentication;
import org.springframework.util.Assert;
import org.springframework.util.ObjectUtils;
import org.springframework.util.StringUtils;

/**
Expand Down Expand Up @@ -92,73 +95,57 @@
* <p>
* All comparisons and prefixes are case sensitive.
*
*
* @author Ben Alex
*/
public class AclEntryVoter extends AbstractAclVoter {
// ~ Static fields/initializers
// =====================================================================================

private static final Log logger = LogFactory.getLog(AclEntryVoter.class);

// ~ Instance fields
// ================================================================================================
private final AclService aclService;

private final String processConfigAttribute;

private final List<Permission> requirePermission;

private AclService aclService;
private ObjectIdentityRetrievalStrategy objectIdentityRetrievalStrategy = new ObjectIdentityRetrievalStrategyImpl();

private SidRetrievalStrategy sidRetrievalStrategy = new SidRetrievalStrategyImpl();
private String internalMethod;
private String processConfigAttribute;
private List<Permission> requirePermission;

// ~ Constructors
// ===================================================================================================
private String internalMethod;

public AclEntryVoter(AclService aclService, String processConfigAttribute,
Permission[] requirePermission) {
public AclEntryVoter(AclService aclService, String processConfigAttribute, Permission[] requirePermission) {
Assert.notNull(processConfigAttribute, "A processConfigAttribute is mandatory");
Assert.notNull(aclService, "An AclService is mandatory");

if ((requirePermission == null) || (requirePermission.length == 0)) {
throw new IllegalArgumentException(
"One or more requirePermission entries is mandatory");
}

Assert.isTrue(!ObjectUtils.isEmpty(requirePermission), "One or more requirePermission entries is mandatory");
this.aclService = aclService;
this.processConfigAttribute = processConfigAttribute;
this.requirePermission = Arrays.asList(requirePermission);
}

// ~ Methods
// ========================================================================================================

/**
* Optionally specifies a method of the domain object that will be used to obtain a
* contained domain object. That contained domain object will be used for the ACL
* evaluation. This is useful if a domain object contains a parent that an ACL
* evaluation should be targeted for, instead of the child domain object (which
* perhaps is being created and as such does not yet have any ACL permissions)
*
* @return <code>null</code> to use the domain object, or the name of a method (that
* requires no arguments) that should be invoked to obtain an <code>Object</code>
* which will be the domain object used for ACL evaluation
*/
protected String getInternalMethod() {
return internalMethod;
return this.internalMethod;
}

public void setInternalMethod(String internalMethod) {
this.internalMethod = internalMethod;
}

protected String getProcessConfigAttribute() {
return processConfigAttribute;
return this.processConfigAttribute;
}

public void setObjectIdentityRetrievalStrategy(
ObjectIdentityRetrievalStrategy objectIdentityRetrievalStrategy) {
Assert.notNull(objectIdentityRetrievalStrategy,
"ObjectIdentityRetrievalStrategy required");
public void setObjectIdentityRetrievalStrategy(ObjectIdentityRetrievalStrategy objectIdentityRetrievalStrategy) {
Assert.notNull(objectIdentityRetrievalStrategy, "ObjectIdentityRetrievalStrategy required");
this.objectIdentityRetrievalStrategy = objectIdentityRetrievalStrategy;
}

Expand All @@ -167,108 +154,88 @@ public void setSidRetrievalStrategy(SidRetrievalStrategy sidRetrievalStrategy) {
this.sidRetrievalStrategy = sidRetrievalStrategy;
}

@Override
public boolean supports(ConfigAttribute attribute) {
return (attribute.getAttribute() != null)
&& attribute.getAttribute().equals(getProcessConfigAttribute());
return (attribute.getAttribute() != null) && attribute.getAttribute().equals(getProcessConfigAttribute());
}

public int vote(Authentication authentication, MethodInvocation object,
Collection<ConfigAttribute> attributes) {

@Override
public int vote(Authentication authentication, MethodInvocation object, Collection<ConfigAttribute> attributes) {
for (ConfigAttribute attr : attributes) {

if (!this.supports(attr)) {
if (!supports(attr)) {
continue;
}

// Need to make an access decision on this invocation
// Attempt to locate the domain object instance to process
Object domainObject = getDomainObjectInstance(object);

// If domain object is null, vote to abstain
if (domainObject == null) {
if (logger.isDebugEnabled()) {
logger.debug("Voting to abstain - domainObject is null");
}

logger.debug("Voting to abstain - domainObject is null");
return ACCESS_ABSTAIN;
}

// Evaluate if we are required to use an inner domain object
if (StringUtils.hasText(internalMethod)) {
try {
Class<?> clazz = domainObject.getClass();
Method method = clazz.getMethod(internalMethod, new Class[0]);
domainObject = method.invoke(domainObject);
}
catch (NoSuchMethodException nsme) {
throw new AuthorizationServiceException("Object of class '"
+ domainObject.getClass()
+ "' does not provide the requested internalMethod: "
+ internalMethod);
}
catch (IllegalAccessException iae) {
logger.debug("IllegalAccessException", iae);

throw new AuthorizationServiceException(
"Problem invoking internalMethod: " + internalMethod
+ " for object: " + domainObject);
}
catch (InvocationTargetException ite) {
logger.debug("InvocationTargetException", ite);

throw new AuthorizationServiceException(
"Problem invoking internalMethod: " + internalMethod
+ " for object: " + domainObject);
}
if (StringUtils.hasText(this.internalMethod)) {
domainObject = invokeInternalMethod(domainObject);
}

// Obtain the OID applicable to the domain object
ObjectIdentity objectIdentity = objectIdentityRetrievalStrategy
.getObjectIdentity(domainObject);
ObjectIdentity objectIdentity = this.objectIdentityRetrievalStrategy.getObjectIdentity(domainObject);

// Obtain the SIDs applicable to the principal
List<Sid> sids = sidRetrievalStrategy.getSids(authentication);
List<Sid> sids = this.sidRetrievalStrategy.getSids(authentication);

Acl acl;

try {
// Lookup only ACLs for SIDs we're interested in
acl = aclService.readAclById(objectIdentity, sids);
acl = this.aclService.readAclById(objectIdentity, sids);
}
catch (NotFoundException nfe) {
if (logger.isDebugEnabled()) {
logger.debug("Voting to deny access - no ACLs apply for this principal");
}

catch (NotFoundException ex) {
logger.debug("Voting to deny access - no ACLs apply for this principal");
return ACCESS_DENIED;
}

try {
if (acl.isGranted(requirePermission, sids, false)) {
if (logger.isDebugEnabled()) {
logger.debug("Voting to grant access");
}

if (acl.isGranted(this.requirePermission, sids, false)) {
logger.debug("Voting to grant access");
return ACCESS_GRANTED;
}
else {
if (logger.isDebugEnabled()) {
logger.debug("Voting to deny access - ACLs returned, but insufficient permissions for this principal");
}

return ACCESS_DENIED;
}
logger.debug("Voting to deny access - ACLs returned, but insufficient permissions for this principal");
return ACCESS_DENIED;
}
catch (NotFoundException nfe) {
if (logger.isDebugEnabled()) {
logger.debug("Voting to deny access - no ACLs apply for this principal");
}

catch (NotFoundException ex) {
logger.debug("Voting to deny access - no ACLs apply for this principal");
return ACCESS_DENIED;
}
}

// No configuration attribute matched, so abstain
return ACCESS_ABSTAIN;
}

private Object invokeInternalMethod(Object domainObject) {
try {
Class<?> domainObjectType = domainObject.getClass();
Method method = domainObjectType.getMethod(this.internalMethod, new Class[0]);
return method.invoke(domainObject);
}
catch (NoSuchMethodException ex) {
throw new AuthorizationServiceException("Object of class '" + domainObject.getClass()
+ "' does not provide the requested internalMethod: " + this.internalMethod);
}
catch (IllegalAccessException ex) {
logger.debug("IllegalAccessException", ex);
throw new AuthorizationServiceException(
"Problem invoking internalMethod: " + this.internalMethod + " for object: " + domainObject);
}
catch (InvocationTargetException ex) {
logger.debug("InvocationTargetException", ex);
throw new AuthorizationServiceException(
"Problem invoking internalMethod: " + this.internalMethod + " for object: " + domainObject);
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.springframework.security.acls;

import java.util.ArrayList;
Expand All @@ -21,6 +22,8 @@

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import org.springframework.core.log.LogMessage;
import org.springframework.security.access.PermissionCacheOptimizer;
import org.springframework.security.acls.domain.ObjectIdentityRetrievalStrategyImpl;
import org.springframework.security.acls.domain.SidRetrievalStrategyImpl;
Expand All @@ -38,45 +41,42 @@
* @since 3.1
*/
public class AclPermissionCacheOptimizer implements PermissionCacheOptimizer {

private final Log logger = LogFactory.getLog(getClass());

private final AclService aclService;

private SidRetrievalStrategy sidRetrievalStrategy = new SidRetrievalStrategyImpl();

private ObjectIdentityRetrievalStrategy oidRetrievalStrategy = new ObjectIdentityRetrievalStrategyImpl();

public AclPermissionCacheOptimizer(AclService aclService) {
this.aclService = aclService;
}

@Override
public void cachePermissionsFor(Authentication authentication, Collection<?> objects) {
if (objects.isEmpty()) {
return;
}

List<ObjectIdentity> oidsToCache = new ArrayList<>(objects.size());

for (Object domainObject : objects) {
if (domainObject == null) {
continue;
if (domainObject != null) {
ObjectIdentity oid = this.oidRetrievalStrategy.getObjectIdentity(domainObject);
oidsToCache.add(oid);
}
ObjectIdentity oid = oidRetrievalStrategy.getObjectIdentity(domainObject);
oidsToCache.add(oid);
}

List<Sid> sids = sidRetrievalStrategy.getSids(authentication);

if (logger.isDebugEnabled()) {
logger.debug("Eagerly loading Acls for " + oidsToCache.size() + " objects");
}

aclService.readAclsById(oidsToCache, sids);
List<Sid> sids = this.sidRetrievalStrategy.getSids(authentication);
this.logger.debug(LogMessage.of(() -> "Eagerly loading Acls for " + oidsToCache.size() + " objects"));
this.aclService.readAclsById(oidsToCache, sids);
}

public void setObjectIdentityRetrievalStrategy(
ObjectIdentityRetrievalStrategy objectIdentityRetrievalStrategy) {
public void setObjectIdentityRetrievalStrategy(ObjectIdentityRetrievalStrategy objectIdentityRetrievalStrategy) {
this.oidRetrievalStrategy = objectIdentityRetrievalStrategy;
}

public void setSidRetrievalStrategy(SidRetrievalStrategy sidRetrievalStrategy) {
this.sidRetrievalStrategy = sidRetrievalStrategy;
}

}
Loading