SEC-680: Missed some additional method, method parameter & field names, JavaDoc

http://jira.springframework.org/browse/SEC-680
This commit is contained in:
Luke Taylor 2008-02-28 12:28:17 +00:00
parent 25c4db08b9
commit 93432b7626
6 changed files with 74 additions and 74 deletions

View File

@ -11,14 +11,14 @@ import org.springframework.security.GrantedAuthority;
*/ */
public interface Attributes2GrantedAuthoritiesMapper { 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 * list of Spring Security GrantedAuthorities. There are no restrictions for the
* mapping process; a single role can be mapped to multiple Acegi * mapping process; a single attribute can be mapped to multiple Spring Security
* GrantedAuthorities, all roles can be mapped to a single Acegi * GrantedAuthorities, all attributes can be mapped to a single Spring Security
* GrantedAuthority, some roles may not be mapped, etc. * 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 * @return the list of mapped GrantedAuthorities
*/ */
public GrantedAuthority[] getGrantedAuthorities(String[] roles); public GrantedAuthority[] getGrantedAuthorities(String[] attributes);
} }

View File

@ -11,22 +11,22 @@ import org.springframework.util.Assert;
/** /**
* <p> * <p>
* This class implements the Attributes2GrantedAuthoritiesMapper interface by doing a * This class implements the Attributes2GrantedAuthoritiesMapper interface by doing a
* one-on-one mapping from roles to Acegi GrantedAuthorities. Optionally a * one-to-one mapping from roles to Spring Security GrantedAuthorities. Optionally a
* prefix can be added, and the role name can be converted to upper or lower * prefix can be added, and the attribute name can be converted to upper or lower
* case. * case.
* <p> * <p>
* 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. * "ROLE_", and no case conversion is done.
* *
* @author Ruud Senden * @author Ruud Senden
* @since 2.0 * @since 2.0
*/ */
public class SimpleAttributes2GrantedAuthoritiesMapper implements Attributes2GrantedAuthoritiesMapper, InitializingBean { 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; private boolean addPrefixIfAlreadyExisting = false;
@ -34,64 +34,64 @@ public class SimpleAttributes2GrantedAuthoritiesMapper implements Attributes2Gra
* Check whether all properties have been set to correct values. * Check whether all properties have been set to correct values.
*/ */
public void afterPropertiesSet() throws Exception { public void afterPropertiesSet() throws Exception {
Assert.isTrue(!(isConvertRoleToUpperCase() && isConvertRoleToLowerCase()), Assert.isTrue(!(isConvertAttributeToUpperCase() && isConvertAttributeToLowerCase()),
"Either convertRoleToUpperCase or convertRoleToLowerCase can be set to true, but not both"); "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) { public GrantedAuthority[] getGrantedAuthorities(String[] attributes) {
GrantedAuthority[] result = new GrantedAuthority[roles.length]; GrantedAuthority[] result = new GrantedAuthority[attributes.length];
for (int i = 0; i < roles.length; i++) { for (int i = 0; i < attributes.length; i++) {
result[i] = getGrantedAuthority(roles[i]); result[i] = getGrantedAuthority(attributes[i]);
} }
return result; 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. * doing case conversion and/or adding a prefix.
* *
* @param role * @param attribute
* The role for which to get a GrantedAuthority * The attribute for which to get a GrantedAuthority
* @return GrantedAuthority representing the given role. * @return GrantedAuthority representing the given role.
*/ */
private GrantedAuthority getGrantedAuthority(String role) { private GrantedAuthority getGrantedAuthority(String attribute) {
if (isConvertRoleToLowerCase()) { if (isConvertAttributeToLowerCase()) {
role = role.toLowerCase(Locale.getDefault()); attribute = attribute.toLowerCase(Locale.getDefault());
} else if (isConvertRoleToUpperCase()) { } else if (isConvertAttributeToUpperCase()) {
role = role.toUpperCase(Locale.getDefault()); attribute = attribute.toUpperCase(Locale.getDefault());
} }
if (isAddPrefixIfAlreadyExisting() || !role.startsWith(getRolePrefix())) { if (isAddPrefixIfAlreadyExisting() || !attribute.startsWith(getAttributePrefix())) {
return new GrantedAuthorityImpl(getRolePrefix() + role); return new GrantedAuthorityImpl(getAttributePrefix() + attribute);
} else { } else {
return new GrantedAuthorityImpl(role); return new GrantedAuthorityImpl(attribute);
} }
} }
private boolean isConvertRoleToLowerCase() { private boolean isConvertAttributeToLowerCase() {
return convertRoleToLowerCase; return convertAttributeToLowerCase;
} }
public void setConvertRoleToLowerCase(boolean b) { public void setConvertAttributeToLowerCase(boolean b) {
convertRoleToLowerCase = b; convertAttributeToLowerCase = b;
} }
private boolean isConvertRoleToUpperCase() { private boolean isConvertAttributeToUpperCase() {
return convertRoleToUpperCase; return convertAttributeToUpperCase;
} }
public void setConvertRoleToUpperCase(boolean b) { public void setConvertAttributeToUpperCase(boolean b) {
convertRoleToUpperCase = b; convertAttributeToUpperCase = b;
} }
private String getRolePrefix() { private String getAttributePrefix() {
return rolePrefix == null ? "" : rolePrefix; return attributePrefix == null ? "" : attributePrefix;
} }
public void setRolePrefix(String string) { public void seAttributePrefix(String string) {
rolePrefix = string; attributePrefix = string;
} }
private boolean isAddPrefixIfAlreadyExisting() { private boolean isAddPrefixIfAlreadyExisting() {

View File

@ -4,14 +4,14 @@ import org.springframework.util.Assert;
/** /**
* This class implements the MappableAttributesRetriever interface by just returning * 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. * method.
* *
* @author Ruud Senden * @author Ruud Senden
* @since 2.0 * @since 2.0
*/ */
public class SimpleMappableAttributesRetriever implements MappableAttributesRetriever { public class SimpleMappableAttributesRetriever implements MappableAttributesRetriever {
private String[] mappableRoles = null; private String[] mappableAttributes = null;
/* /*
* (non-Javadoc) * (non-Javadoc)
@ -19,15 +19,15 @@ public class SimpleMappableAttributesRetriever implements MappableAttributesRetr
* @see org.springframework.security.authoritymapping.MappableAttributesRetriever#getMappableAttributes() * @see org.springframework.security.authoritymapping.MappableAttributesRetriever#getMappableAttributes()
*/ */
public String[] getMappableAttributes() { public String[] getMappableAttributes() {
Assert.notNull(mappableRoles, "No mappable roles have been set"); Assert.notNull(mappableAttributes, "No mappable roles have been set");
String[] copy = new String[mappableRoles.length]; String[] copy = new String[mappableAttributes.length];
System.arraycopy(mappableRoles, 0, copy, 0, copy.length); System.arraycopy(mappableAttributes, 0, copy, 0, copy.length);
return copy; return copy;
} }
public void setMappableAttributes(String[] aMappableRoles) { public void setMappableAttributes(String[] aMappableRoles) {
this.mappableRoles = new String[aMappableRoles.length]; this.mappableAttributes = new String[aMappableRoles.length];
System.arraycopy(aMappableRoles, 0, mappableRoles, 0, mappableRoles.length); System.arraycopy(aMappableRoles, 0, mappableAttributes, 0, mappableAttributes.length);
} }
} }

View File

@ -27,7 +27,7 @@ import org.xml.sax.SAXException;
/** /**
* This implementation for the MappableAttributesRetriever interface retrieves the * This implementation for the MappableAttributesRetriever interface retrieves the
* list of mappable roles from an XML file. * list of mappable attributes from an XML file.
* <p> * <p>
* This class is defined as abstract because it is too generic to be used * 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. * 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 { public abstract class XmlMappableAttributesRetriever implements MappableAttributesRetriever, InitializingBean {
private static final Log logger = LogFactory.getLog(XmlMappableAttributesRetriever.class); private static final Log logger = LogFactory.getLog(XmlMappableAttributesRetriever.class);
private String[] mappableRoles = null; private String[] mappableAttributes = null;
private InputStream xmlInputStream = null; private InputStream xmlInputStream = null;
@ -55,27 +55,27 @@ public abstract class XmlMappableAttributesRetriever implements MappableAttribut
public void afterPropertiesSet() throws Exception { public void afterPropertiesSet() throws Exception {
Assert.notNull(xmlInputStream, "An XML InputStream must be set"); Assert.notNull(xmlInputStream, "An XML InputStream must be set");
Assert.notNull(xpathExpression, "An XPath expression must be set"); Assert.notNull(xpathExpression, "An XPath expression must be set");
mappableRoles = getMappableRoles(xmlInputStream); mappableAttributes = getMappableAttributes(xmlInputStream);
} }
public String[] getMappableAttributes() { public String[] getMappableAttributes() {
String[] copy = new String[mappableRoles.length]; String[] copy = new String[mappableAttributes.length];
System.arraycopy(mappableRoles, 0, copy, 0, copy.length); System.arraycopy(mappableAttributes, 0, copy, 0, copy.length);
return copy; return copy;
} }
/** /**
* Get the mappable roles from the specified XML document. * Get the mappable roles from the specified XML document.
*/ */
private String[] getMappableRoles(InputStream aStream) { private String[] getMappableAttributes(InputStream aStream) {
if (logger.isDebugEnabled()) { if (logger.isDebugEnabled()) {
logger.debug("Reading mappable roles from XML document"); logger.debug("Reading mappable attributes from XML document");
} }
try { try {
Document doc = getDocument(aStream); Document doc = getDocument(aStream);
String[] roles = getMappableRoles(doc); String[] roles = getMappableAttributes(doc);
if (logger.isDebugEnabled()) { 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; return roles;
} finally { } finally {
@ -118,7 +118,7 @@ public abstract class XmlMappableAttributesRetriever implements MappableAttribut
* @return String[] the list of roles. * @return String[] the list of roles.
* @throws JaxenException * @throws JaxenException
*/ */
private String[] getMappableRoles(Document doc) { private String[] getMappableAttributes(Document doc) {
try { try {
DOMXPath xpath = new DOMXPath(xpathExpression); DOMXPath xpath = new DOMXPath(xpathExpression);
List roleElements = xpath.selectNodes(doc); List roleElements = xpath.selectNodes(doc);

View File

@ -17,8 +17,8 @@ public class SimpleRoles2GrantedAuthoritiesMapperTests extends TestCase {
public final void testAfterPropertiesSetConvertToUpperAndLowerCase() { public final void testAfterPropertiesSetConvertToUpperAndLowerCase() {
SimpleAttributes2GrantedAuthoritiesMapper mapper = new SimpleAttributes2GrantedAuthoritiesMapper(); SimpleAttributes2GrantedAuthoritiesMapper mapper = new SimpleAttributes2GrantedAuthoritiesMapper();
mapper.setConvertRoleToLowerCase(true); mapper.setConvertAttributeToLowerCase(true);
mapper.setConvertRoleToUpperCase(true); mapper.setConvertAttributeToUpperCase(true);
try { try {
mapper.afterPropertiesSet(); mapper.afterPropertiesSet();
fail("Expected exception not thrown"); fail("Expected exception not thrown");
@ -48,7 +48,7 @@ public class SimpleRoles2GrantedAuthoritiesMapperTests extends TestCase {
String[] roles = { "Role1", "Role2" }; String[] roles = { "Role1", "Role2" };
String[] expectedGas = { "ROLE1", "ROLE2" }; String[] expectedGas = { "ROLE1", "ROLE2" };
SimpleAttributes2GrantedAuthoritiesMapper mapper = getDefaultMapper(); SimpleAttributes2GrantedAuthoritiesMapper mapper = getDefaultMapper();
mapper.setConvertRoleToUpperCase(true); mapper.setConvertAttributeToUpperCase(true);
testGetGrantedAuthorities(mapper, roles, expectedGas); testGetGrantedAuthorities(mapper, roles, expectedGas);
} }
@ -56,7 +56,7 @@ public class SimpleRoles2GrantedAuthoritiesMapperTests extends TestCase {
String[] roles = { "Role1", "Role2" }; String[] roles = { "Role1", "Role2" };
String[] expectedGas = { "role1", "role2" }; String[] expectedGas = { "role1", "role2" };
SimpleAttributes2GrantedAuthoritiesMapper mapper = getDefaultMapper(); SimpleAttributes2GrantedAuthoritiesMapper mapper = getDefaultMapper();
mapper.setConvertRoleToLowerCase(true); mapper.setConvertAttributeToLowerCase(true);
testGetGrantedAuthorities(mapper, roles, expectedGas); testGetGrantedAuthorities(mapper, roles, expectedGas);
} }
@ -65,7 +65,7 @@ public class SimpleRoles2GrantedAuthoritiesMapperTests extends TestCase {
String[] expectedGas = { "ROLE_Role1", "ROLE_Role2", "ROLE_ROLE_Role3" }; String[] expectedGas = { "ROLE_Role1", "ROLE_Role2", "ROLE_ROLE_Role3" };
SimpleAttributes2GrantedAuthoritiesMapper mapper = getDefaultMapper(); SimpleAttributes2GrantedAuthoritiesMapper mapper = getDefaultMapper();
mapper.setAddPrefixIfAlreadyExisting(true); mapper.setAddPrefixIfAlreadyExisting(true);
mapper.setRolePrefix("ROLE_"); mapper.seAttributePrefix("ROLE_");
testGetGrantedAuthorities(mapper, roles, expectedGas); testGetGrantedAuthorities(mapper, roles, expectedGas);
} }
@ -74,7 +74,7 @@ public class SimpleRoles2GrantedAuthoritiesMapperTests extends TestCase {
String[] expectedGas = { "ROLE_Role1", "ROLE_Role2", "ROLE_Role3" }; String[] expectedGas = { "ROLE_Role1", "ROLE_Role2", "ROLE_Role3" };
SimpleAttributes2GrantedAuthoritiesMapper mapper = getDefaultMapper(); SimpleAttributes2GrantedAuthoritiesMapper mapper = getDefaultMapper();
mapper.setAddPrefixIfAlreadyExisting(false); mapper.setAddPrefixIfAlreadyExisting(false);
mapper.setRolePrefix("ROLE_"); mapper.seAttributePrefix("ROLE_");
testGetGrantedAuthorities(mapper, roles, expectedGas); testGetGrantedAuthorities(mapper, roles, expectedGas);
} }
@ -83,7 +83,7 @@ public class SimpleRoles2GrantedAuthoritiesMapperTests extends TestCase {
String[] expectedGas = { "ROLE_Role1", "ROLE_Role2", "ROLE_role_Role3" }; String[] expectedGas = { "ROLE_Role1", "ROLE_Role2", "ROLE_role_Role3" };
SimpleAttributes2GrantedAuthoritiesMapper mapper = getDefaultMapper(); SimpleAttributes2GrantedAuthoritiesMapper mapper = getDefaultMapper();
mapper.setAddPrefixIfAlreadyExisting(false); mapper.setAddPrefixIfAlreadyExisting(false);
mapper.setRolePrefix("ROLE_"); mapper.seAttributePrefix("ROLE_");
testGetGrantedAuthorities(mapper, roles, expectedGas); testGetGrantedAuthorities(mapper, roles, expectedGas);
} }
@ -92,8 +92,8 @@ public class SimpleRoles2GrantedAuthoritiesMapperTests extends TestCase {
String[] expectedGas = { "ROLE_ROLE1", "ROLE_ROLE2", "ROLE_ROLE3" }; String[] expectedGas = { "ROLE_ROLE1", "ROLE_ROLE2", "ROLE_ROLE3" };
SimpleAttributes2GrantedAuthoritiesMapper mapper = getDefaultMapper(); SimpleAttributes2GrantedAuthoritiesMapper mapper = getDefaultMapper();
mapper.setAddPrefixIfAlreadyExisting(false); mapper.setAddPrefixIfAlreadyExisting(false);
mapper.setConvertRoleToUpperCase(true); mapper.setConvertAttributeToUpperCase(true);
mapper.setRolePrefix("ROLE_"); mapper.seAttributePrefix("ROLE_");
testGetGrantedAuthorities(mapper, roles, expectedGas); testGetGrantedAuthorities(mapper, roles, expectedGas);
} }
@ -111,9 +111,9 @@ public class SimpleRoles2GrantedAuthoritiesMapperTests extends TestCase {
private SimpleAttributes2GrantedAuthoritiesMapper getDefaultMapper() { private SimpleAttributes2GrantedAuthoritiesMapper getDefaultMapper() {
SimpleAttributes2GrantedAuthoritiesMapper mapper = new SimpleAttributes2GrantedAuthoritiesMapper(); SimpleAttributes2GrantedAuthoritiesMapper mapper = new SimpleAttributes2GrantedAuthoritiesMapper();
mapper.setRolePrefix(""); mapper.seAttributePrefix("");
mapper.setConvertRoleToLowerCase(false); mapper.setConvertAttributeToLowerCase(false);
mapper.setConvertRoleToUpperCase(false); mapper.setConvertAttributeToUpperCase(false);
mapper.setAddPrefixIfAlreadyExisting(false); mapper.setAddPrefixIfAlreadyExisting(false);
return mapper; return mapper;
} }

View File

@ -129,9 +129,9 @@ public class J2eeBasedPreAuthenticatedWebAuthenticationDetailsSourceTests extend
private Attributes2GrantedAuthoritiesMapper getJ2eeUserRoles2GrantedAuthoritiesMapper() { private Attributes2GrantedAuthoritiesMapper getJ2eeUserRoles2GrantedAuthoritiesMapper() {
SimpleAttributes2GrantedAuthoritiesMapper result = new SimpleAttributes2GrantedAuthoritiesMapper(); SimpleAttributes2GrantedAuthoritiesMapper result = new SimpleAttributes2GrantedAuthoritiesMapper();
result.setAddPrefixIfAlreadyExisting(false); result.setAddPrefixIfAlreadyExisting(false);
result.setConvertRoleToLowerCase(false); result.setConvertAttributeToLowerCase(false);
result.setConvertRoleToUpperCase(false); result.setConvertAttributeToUpperCase(false);
result.setRolePrefix(""); result.seAttributePrefix("");
return result; return result;
} }