From 93432b7626786ca175877f0a12c3bbd3c313e10e Mon Sep 17 00:00:00 2001 From: Luke Taylor Date: Thu, 28 Feb 2008 12:28:17 +0000 Subject: [PATCH] SEC-680: Missed some additional method, method parameter & field names, JavaDoc http://jira.springframework.org/browse/SEC-680 --- .../Attributes2GrantedAuthoritiesMapper.java | 12 ++-- ...leAttributes2GrantedAuthoritiesMapper.java | 72 +++++++++---------- .../SimpleMappableAttributesRetriever.java | 14 ++-- .../XmlMappableAttributesRetriever.java | 20 +++--- ...leRoles2GrantedAuthoritiesMapperTests.java | 24 +++---- ...edWebAuthenticationDetailsSourceTests.java | 6 +- 6 files changed, 74 insertions(+), 74 deletions(-) diff --git a/core/src/main/java/org/springframework/security/authoritymapping/Attributes2GrantedAuthoritiesMapper.java b/core/src/main/java/org/springframework/security/authoritymapping/Attributes2GrantedAuthoritiesMapper.java index 9d6f26fb90..23543d4317 100755 --- a/core/src/main/java/org/springframework/security/authoritymapping/Attributes2GrantedAuthoritiesMapper.java +++ b/core/src/main/java/org/springframework/security/authoritymapping/Attributes2GrantedAuthoritiesMapper.java @@ -11,14 +11,14 @@ import org.springframework.security.GrantedAuthority; */ public interface Attributes2GrantedAuthoritiesMapper { /** - * Implementations of this method should map the given list of roles to a + * Implementations of this method should map the given list of attributes to a * list of Spring Security GrantedAuthorities. There are no restrictions for the - * mapping process; a single role can be mapped to multiple Acegi - * GrantedAuthorities, all roles can be mapped to a single Acegi - * GrantedAuthority, some roles may not be mapped, etc. + * mapping process; a single attribute can be mapped to multiple Spring Security + * GrantedAuthorities, all attributes can be mapped to a single Spring Security + * GrantedAuthority, some attributes may not be mapped, etc. * - * @param roles the roles to be mapped + * @param attribute the attributes to be mapped * @return the list of mapped GrantedAuthorities */ - public GrantedAuthority[] getGrantedAuthorities(String[] roles); + public GrantedAuthority[] getGrantedAuthorities(String[] attributes); } diff --git a/core/src/main/java/org/springframework/security/authoritymapping/SimpleAttributes2GrantedAuthoritiesMapper.java b/core/src/main/java/org/springframework/security/authoritymapping/SimpleAttributes2GrantedAuthoritiesMapper.java index 0aa1d860f9..0cba9a6dd7 100755 --- a/core/src/main/java/org/springframework/security/authoritymapping/SimpleAttributes2GrantedAuthoritiesMapper.java +++ b/core/src/main/java/org/springframework/security/authoritymapping/SimpleAttributes2GrantedAuthoritiesMapper.java @@ -11,22 +11,22 @@ import org.springframework.util.Assert; /** *

* This class implements the Attributes2GrantedAuthoritiesMapper interface by doing a - * one-on-one mapping from roles to Acegi GrantedAuthorities. Optionally a - * prefix can be added, and the role name can be converted to upper or lower + * one-to-one mapping from roles to Spring Security GrantedAuthorities. Optionally a + * prefix can be added, and the attribute name can be converted to upper or lower * case. *

- * By default, the role is prefixed with "ROLE_" unless it already starts with + * By default, the attribute is prefixed with "ROLE_" unless it already starts with * "ROLE_", and no case conversion is done. * * @author Ruud Senden * @since 2.0 */ public class SimpleAttributes2GrantedAuthoritiesMapper implements Attributes2GrantedAuthoritiesMapper, InitializingBean { - private String rolePrefix = "ROLE_"; + private String attributePrefix = "ROLE_"; - private boolean convertRoleToUpperCase = false; + private boolean convertAttributeToUpperCase = false; - private boolean convertRoleToLowerCase = false; + private boolean convertAttributeToLowerCase = false; private boolean addPrefixIfAlreadyExisting = false; @@ -34,64 +34,64 @@ public class SimpleAttributes2GrantedAuthoritiesMapper implements Attributes2Gra * Check whether all properties have been set to correct values. */ public void afterPropertiesSet() throws Exception { - Assert.isTrue(!(isConvertRoleToUpperCase() && isConvertRoleToLowerCase()), - "Either convertRoleToUpperCase or convertRoleToLowerCase can be set to true, but not both"); + Assert.isTrue(!(isConvertAttributeToUpperCase() && isConvertAttributeToLowerCase()), + "Either convertAttributeToUpperCase or convertAttributeToLowerCase can be set to true, but not both"); } /** - * Map the given list of roles one-on-one to Acegi GrantedAuthorities. + * Map the given list of string attributes one-to-one to Spring Security GrantedAuthorities. */ - public GrantedAuthority[] getGrantedAuthorities(String[] roles) { - GrantedAuthority[] result = new GrantedAuthority[roles.length]; - for (int i = 0; i < roles.length; i++) { - result[i] = getGrantedAuthority(roles[i]); + public GrantedAuthority[] getGrantedAuthorities(String[] attributes) { + GrantedAuthority[] result = new GrantedAuthority[attributes.length]; + for (int i = 0; i < attributes.length; i++) { + result[i] = getGrantedAuthority(attributes[i]); } return result; } /** - * Map the given role ono-on-one to an Acegi GrantedAuthority, optionally + * Map the given role one-on-one to a Spring Security GrantedAuthority, optionally * doing case conversion and/or adding a prefix. * - * @param role - * The role for which to get a GrantedAuthority + * @param attribute + * The attribute for which to get a GrantedAuthority * @return GrantedAuthority representing the given role. */ - private GrantedAuthority getGrantedAuthority(String role) { - if (isConvertRoleToLowerCase()) { - role = role.toLowerCase(Locale.getDefault()); - } else if (isConvertRoleToUpperCase()) { - role = role.toUpperCase(Locale.getDefault()); + private GrantedAuthority getGrantedAuthority(String attribute) { + if (isConvertAttributeToLowerCase()) { + attribute = attribute.toLowerCase(Locale.getDefault()); + } else if (isConvertAttributeToUpperCase()) { + attribute = attribute.toUpperCase(Locale.getDefault()); } - if (isAddPrefixIfAlreadyExisting() || !role.startsWith(getRolePrefix())) { - return new GrantedAuthorityImpl(getRolePrefix() + role); + if (isAddPrefixIfAlreadyExisting() || !attribute.startsWith(getAttributePrefix())) { + return new GrantedAuthorityImpl(getAttributePrefix() + attribute); } else { - return new GrantedAuthorityImpl(role); + return new GrantedAuthorityImpl(attribute); } } - private boolean isConvertRoleToLowerCase() { - return convertRoleToLowerCase; + private boolean isConvertAttributeToLowerCase() { + return convertAttributeToLowerCase; } - public void setConvertRoleToLowerCase(boolean b) { - convertRoleToLowerCase = b; + public void setConvertAttributeToLowerCase(boolean b) { + convertAttributeToLowerCase = b; } - private boolean isConvertRoleToUpperCase() { - return convertRoleToUpperCase; + private boolean isConvertAttributeToUpperCase() { + return convertAttributeToUpperCase; } - public void setConvertRoleToUpperCase(boolean b) { - convertRoleToUpperCase = b; + public void setConvertAttributeToUpperCase(boolean b) { + convertAttributeToUpperCase = b; } - private String getRolePrefix() { - return rolePrefix == null ? "" : rolePrefix; + private String getAttributePrefix() { + return attributePrefix == null ? "" : attributePrefix; } - public void setRolePrefix(String string) { - rolePrefix = string; + public void seAttributePrefix(String string) { + attributePrefix = string; } private boolean isAddPrefixIfAlreadyExisting() { diff --git a/core/src/main/java/org/springframework/security/authoritymapping/SimpleMappableAttributesRetriever.java b/core/src/main/java/org/springframework/security/authoritymapping/SimpleMappableAttributesRetriever.java index 6e94098af5..5e46376142 100755 --- a/core/src/main/java/org/springframework/security/authoritymapping/SimpleMappableAttributesRetriever.java +++ b/core/src/main/java/org/springframework/security/authoritymapping/SimpleMappableAttributesRetriever.java @@ -4,14 +4,14 @@ import org.springframework.util.Assert; /** * This class implements the MappableAttributesRetriever interface by just returning - * a list of mappable roles as previously set using the corresponding setter + * a list of mappable attributes as previously set using the corresponding setter * method. * * @author Ruud Senden * @since 2.0 */ public class SimpleMappableAttributesRetriever implements MappableAttributesRetriever { - private String[] mappableRoles = null; + private String[] mappableAttributes = null; /* * (non-Javadoc) @@ -19,15 +19,15 @@ public class SimpleMappableAttributesRetriever implements MappableAttributesRetr * @see org.springframework.security.authoritymapping.MappableAttributesRetriever#getMappableAttributes() */ public String[] getMappableAttributes() { - Assert.notNull(mappableRoles, "No mappable roles have been set"); - String[] copy = new String[mappableRoles.length]; - System.arraycopy(mappableRoles, 0, copy, 0, copy.length); + Assert.notNull(mappableAttributes, "No mappable roles have been set"); + String[] copy = new String[mappableAttributes.length]; + System.arraycopy(mappableAttributes, 0, copy, 0, copy.length); return copy; } public void setMappableAttributes(String[] aMappableRoles) { - this.mappableRoles = new String[aMappableRoles.length]; - System.arraycopy(aMappableRoles, 0, mappableRoles, 0, mappableRoles.length); + this.mappableAttributes = new String[aMappableRoles.length]; + System.arraycopy(aMappableRoles, 0, mappableAttributes, 0, mappableAttributes.length); } } diff --git a/core/src/main/java/org/springframework/security/authoritymapping/XmlMappableAttributesRetriever.java b/core/src/main/java/org/springframework/security/authoritymapping/XmlMappableAttributesRetriever.java index acce137a0c..c4451795b8 100755 --- a/core/src/main/java/org/springframework/security/authoritymapping/XmlMappableAttributesRetriever.java +++ b/core/src/main/java/org/springframework/security/authoritymapping/XmlMappableAttributesRetriever.java @@ -27,7 +27,7 @@ import org.xml.sax.SAXException; /** * This implementation for the MappableAttributesRetriever interface retrieves the - * list of mappable roles from an XML file. + * list of mappable attributes from an XML file. *

* This class is defined as abstract because it is too generic to be used * directly. As this class is usually used to read very specific XML files (e.g. @@ -41,7 +41,7 @@ import org.xml.sax.SAXException; public abstract class XmlMappableAttributesRetriever implements MappableAttributesRetriever, InitializingBean { private static final Log logger = LogFactory.getLog(XmlMappableAttributesRetriever.class); - private String[] mappableRoles = null; + private String[] mappableAttributes = null; private InputStream xmlInputStream = null; @@ -55,27 +55,27 @@ public abstract class XmlMappableAttributesRetriever implements MappableAttribut public void afterPropertiesSet() throws Exception { Assert.notNull(xmlInputStream, "An XML InputStream must be set"); Assert.notNull(xpathExpression, "An XPath expression must be set"); - mappableRoles = getMappableRoles(xmlInputStream); + mappableAttributes = getMappableAttributes(xmlInputStream); } public String[] getMappableAttributes() { - String[] copy = new String[mappableRoles.length]; - System.arraycopy(mappableRoles, 0, copy, 0, copy.length); + String[] copy = new String[mappableAttributes.length]; + System.arraycopy(mappableAttributes, 0, copy, 0, copy.length); return copy; } /** * Get the mappable roles from the specified XML document. */ - private String[] getMappableRoles(InputStream aStream) { + private String[] getMappableAttributes(InputStream aStream) { if (logger.isDebugEnabled()) { - logger.debug("Reading mappable roles from XML document"); + logger.debug("Reading mappable attributes from XML document"); } try { Document doc = getDocument(aStream); - String[] roles = getMappableRoles(doc); + String[] roles = getMappableAttributes(doc); if (logger.isDebugEnabled()) { - logger.debug("Mappable roles from XML document: " + ArrayUtils.toString(roles)); + logger.debug("Mappable attributes from XML document: " + ArrayUtils.toString(roles)); } return roles; } finally { @@ -118,7 +118,7 @@ public abstract class XmlMappableAttributesRetriever implements MappableAttribut * @return String[] the list of roles. * @throws JaxenException */ - private String[] getMappableRoles(Document doc) { + private String[] getMappableAttributes(Document doc) { try { DOMXPath xpath = new DOMXPath(xpathExpression); List roleElements = xpath.selectNodes(doc); diff --git a/core/src/test/java/org/springframework/security/authoritymapping/SimpleRoles2GrantedAuthoritiesMapperTests.java b/core/src/test/java/org/springframework/security/authoritymapping/SimpleRoles2GrantedAuthoritiesMapperTests.java index f6422407c5..61d33a0b1d 100755 --- a/core/src/test/java/org/springframework/security/authoritymapping/SimpleRoles2GrantedAuthoritiesMapperTests.java +++ b/core/src/test/java/org/springframework/security/authoritymapping/SimpleRoles2GrantedAuthoritiesMapperTests.java @@ -17,8 +17,8 @@ public class SimpleRoles2GrantedAuthoritiesMapperTests extends TestCase { public final void testAfterPropertiesSetConvertToUpperAndLowerCase() { SimpleAttributes2GrantedAuthoritiesMapper mapper = new SimpleAttributes2GrantedAuthoritiesMapper(); - mapper.setConvertRoleToLowerCase(true); - mapper.setConvertRoleToUpperCase(true); + mapper.setConvertAttributeToLowerCase(true); + mapper.setConvertAttributeToUpperCase(true); try { mapper.afterPropertiesSet(); fail("Expected exception not thrown"); @@ -48,7 +48,7 @@ public class SimpleRoles2GrantedAuthoritiesMapperTests extends TestCase { String[] roles = { "Role1", "Role2" }; String[] expectedGas = { "ROLE1", "ROLE2" }; SimpleAttributes2GrantedAuthoritiesMapper mapper = getDefaultMapper(); - mapper.setConvertRoleToUpperCase(true); + mapper.setConvertAttributeToUpperCase(true); testGetGrantedAuthorities(mapper, roles, expectedGas); } @@ -56,7 +56,7 @@ public class SimpleRoles2GrantedAuthoritiesMapperTests extends TestCase { String[] roles = { "Role1", "Role2" }; String[] expectedGas = { "role1", "role2" }; SimpleAttributes2GrantedAuthoritiesMapper mapper = getDefaultMapper(); - mapper.setConvertRoleToLowerCase(true); + mapper.setConvertAttributeToLowerCase(true); testGetGrantedAuthorities(mapper, roles, expectedGas); } @@ -65,7 +65,7 @@ public class SimpleRoles2GrantedAuthoritiesMapperTests extends TestCase { String[] expectedGas = { "ROLE_Role1", "ROLE_Role2", "ROLE_ROLE_Role3" }; SimpleAttributes2GrantedAuthoritiesMapper mapper = getDefaultMapper(); mapper.setAddPrefixIfAlreadyExisting(true); - mapper.setRolePrefix("ROLE_"); + mapper.seAttributePrefix("ROLE_"); testGetGrantedAuthorities(mapper, roles, expectedGas); } @@ -74,7 +74,7 @@ public class SimpleRoles2GrantedAuthoritiesMapperTests extends TestCase { String[] expectedGas = { "ROLE_Role1", "ROLE_Role2", "ROLE_Role3" }; SimpleAttributes2GrantedAuthoritiesMapper mapper = getDefaultMapper(); mapper.setAddPrefixIfAlreadyExisting(false); - mapper.setRolePrefix("ROLE_"); + mapper.seAttributePrefix("ROLE_"); testGetGrantedAuthorities(mapper, roles, expectedGas); } @@ -83,7 +83,7 @@ public class SimpleRoles2GrantedAuthoritiesMapperTests extends TestCase { String[] expectedGas = { "ROLE_Role1", "ROLE_Role2", "ROLE_role_Role3" }; SimpleAttributes2GrantedAuthoritiesMapper mapper = getDefaultMapper(); mapper.setAddPrefixIfAlreadyExisting(false); - mapper.setRolePrefix("ROLE_"); + mapper.seAttributePrefix("ROLE_"); testGetGrantedAuthorities(mapper, roles, expectedGas); } @@ -92,8 +92,8 @@ public class SimpleRoles2GrantedAuthoritiesMapperTests extends TestCase { String[] expectedGas = { "ROLE_ROLE1", "ROLE_ROLE2", "ROLE_ROLE3" }; SimpleAttributes2GrantedAuthoritiesMapper mapper = getDefaultMapper(); mapper.setAddPrefixIfAlreadyExisting(false); - mapper.setConvertRoleToUpperCase(true); - mapper.setRolePrefix("ROLE_"); + mapper.setConvertAttributeToUpperCase(true); + mapper.seAttributePrefix("ROLE_"); testGetGrantedAuthorities(mapper, roles, expectedGas); } @@ -111,9 +111,9 @@ public class SimpleRoles2GrantedAuthoritiesMapperTests extends TestCase { private SimpleAttributes2GrantedAuthoritiesMapper getDefaultMapper() { SimpleAttributes2GrantedAuthoritiesMapper mapper = new SimpleAttributes2GrantedAuthoritiesMapper(); - mapper.setRolePrefix(""); - mapper.setConvertRoleToLowerCase(false); - mapper.setConvertRoleToUpperCase(false); + mapper.seAttributePrefix(""); + mapper.setConvertAttributeToLowerCase(false); + mapper.setConvertAttributeToUpperCase(false); mapper.setAddPrefixIfAlreadyExisting(false); return mapper; } diff --git a/core/src/test/java/org/springframework/security/ui/preauth/j2ee/J2eeBasedPreAuthenticatedWebAuthenticationDetailsSourceTests.java b/core/src/test/java/org/springframework/security/ui/preauth/j2ee/J2eeBasedPreAuthenticatedWebAuthenticationDetailsSourceTests.java index 2b1893a685..1d6efa3ad8 100755 --- a/core/src/test/java/org/springframework/security/ui/preauth/j2ee/J2eeBasedPreAuthenticatedWebAuthenticationDetailsSourceTests.java +++ b/core/src/test/java/org/springframework/security/ui/preauth/j2ee/J2eeBasedPreAuthenticatedWebAuthenticationDetailsSourceTests.java @@ -129,9 +129,9 @@ public class J2eeBasedPreAuthenticatedWebAuthenticationDetailsSourceTests extend private Attributes2GrantedAuthoritiesMapper getJ2eeUserRoles2GrantedAuthoritiesMapper() { SimpleAttributes2GrantedAuthoritiesMapper result = new SimpleAttributes2GrantedAuthoritiesMapper(); result.setAddPrefixIfAlreadyExisting(false); - result.setConvertRoleToLowerCase(false); - result.setConvertRoleToUpperCase(false); - result.setRolePrefix(""); + result.setConvertAttributeToLowerCase(false); + result.setConvertAttributeToUpperCase(false); + result.seAttributePrefix(""); return result; }