diff --git a/core/src/main/java/org/springframework/security/runas/RunAsManagerImpl.java b/core/src/main/java/org/springframework/security/runas/RunAsManagerImpl.java index 17b3f3c762..aaaf744c59 100644 --- a/core/src/main/java/org/springframework/security/runas/RunAsManagerImpl.java +++ b/core/src/main/java/org/springframework/security/runas/RunAsManagerImpl.java @@ -38,11 +38,11 @@ import org.springframework.util.Assert; * RUN_AS_ keyword. For example, RUN_AS_FOO will result in the creation of a granted * authority of ROLE_RUN_AS_FOO. *

- * The role prefix may be overriden from the default, to match that used elsewhere, for example when using an + * The role prefix may be overridden from the default, to match that used elsewhere, for example when using an * existing role database with another prefix. An empty role prefix may also be specified. Note however that there are * potential issues with using an empty role prefix since different categories of {@link ConfigAttribute} can not be * properly discerned based on the prefix, with possible consequences when performing voting and other actions. - * However, this option may be of some use when using preexisting role names without a prefix, and no ability exists to + * However, this option may be of some use when using pre-existing role names without a prefix, and no ability exists to * prefix them with a role prefix on reading them in, such as provided for example in * {@link org.springframework.security.userdetails.jdbc.JdbcDaoImpl}. * @@ -62,10 +62,10 @@ public class RunAsManagerImpl implements RunAsManager, InitializingBean { Assert.notNull(key, "A Key is required and should match that configured for the RunAsImplAuthenticationProvider"); } - public Authentication buildRunAs(Authentication authentication, Object object, List config) { + public Authentication buildRunAs(Authentication authentication, Object object, List attributes) { List newAuthorities = new ArrayList(); - for(ConfigAttribute attribute : config) { + for (ConfigAttribute attribute : attributes) { if (this.supports(attribute)) { GrantedAuthority extraAuthority = new GrantedAuthorityImpl(getRolePrefix() + attribute.getAttribute()); newAuthorities.add(extraAuthority); @@ -79,11 +79,8 @@ public class RunAsManagerImpl implements RunAsManager, InitializingBean { // Add existing authorities newAuthorities.addAll(authentication.getAuthorities()); -// GrantedAuthority[] resultType = {new GrantedAuthorityImpl("holder")}; - GrantedAuthority[] newAuthoritiesAsArray = newAuthorities.toArray(new GrantedAuthority[0]); - return new RunAsUserToken(this.key, authentication.getPrincipal(), authentication.getCredentials(), - newAuthoritiesAsArray, authentication.getClass()); + newAuthorities, authentication.getClass()); } public String getKey() { @@ -99,8 +96,8 @@ public class RunAsManagerImpl implements RunAsManager, InitializingBean { } /** - * Allows the default role prefix of ROLE_ to be overriden. May be set to an empty value, - * although this is usually not desireable. + * Allows the default role prefix of ROLE_ to be overridden. May be set to an empty value, + * although this is usually not desirable. * * @param rolePrefix the new prefix */ @@ -109,11 +106,7 @@ public class RunAsManagerImpl implements RunAsManager, InitializingBean { } public boolean supports(ConfigAttribute attribute) { - if ((attribute.getAttribute() != null) && attribute.getAttribute().startsWith("RUN_AS_")) { - return true; - } else { - return false; - } + return attribute.getAttribute() != null && attribute.getAttribute().startsWith("RUN_AS_"); } /** @@ -121,7 +114,7 @@ public class RunAsManagerImpl implements RunAsManager, InitializingBean { * * @param clazz the secure object * - * @return alwaus true + * @return always true */ public boolean supports(Class clazz) { return true; diff --git a/core/src/main/java/org/springframework/security/runas/RunAsUserToken.java b/core/src/main/java/org/springframework/security/runas/RunAsUserToken.java index 6fb23e3801..586b0c4c45 100644 --- a/core/src/main/java/org/springframework/security/runas/RunAsUserToken.java +++ b/core/src/main/java/org/springframework/security/runas/RunAsUserToken.java @@ -16,7 +16,9 @@ package org.springframework.security.runas; import java.util.Arrays; +import java.util.List; +import org.springframework.security.Authentication; import org.springframework.security.GrantedAuthority; import org.springframework.security.providers.AbstractAuthenticationToken; @@ -32,7 +34,7 @@ public class RunAsUserToken extends AbstractAuthenticationToken { //~ Instance fields ================================================================================================ private static final long serialVersionUID = 1L; - private Class originalAuthentication; + private Class originalAuthentication; private Object credentials; private Object principal; private int keyHash; @@ -40,8 +42,13 @@ public class RunAsUserToken extends AbstractAuthenticationToken { //~ Constructors =================================================================================================== public RunAsUserToken(String key, Object principal, Object credentials, GrantedAuthority[] authorities, - Class originalAuthentication) { - super(Arrays.asList(authorities)); + Class originalAuthentication) { + this(key, principal, credentials, Arrays.asList(authorities), originalAuthentication); + } + + public RunAsUserToken(String key, Object principal, Object credentials, List authorities, + Class originalAuthentication) { + super(authorities); this.keyHash = key.hashCode(); this.principal = principal; this.credentials = credentials; @@ -59,7 +66,7 @@ public class RunAsUserToken extends AbstractAuthenticationToken { return this.keyHash; } - public Class getOriginalAuthentication() { + public Class getOriginalAuthentication() { return this.originalAuthentication; }