SEC-2690: String[]->List<String>

Use Collections rather than Arrays since Collections can be immutable.
This commit is contained in:
Rob Winch
2014-07-28 11:15:48 -05:00
parent 15c837d5de
commit 1761b29e58
6 changed files with 53 additions and 49 deletions

View File

@@ -17,6 +17,7 @@ package org.springframework.security.ldap;
import static org.junit.Assert.*;
import java.util.List;
import java.util.Map;
import java.util.Set;
@@ -102,14 +103,14 @@ public class SpringSecurityLdapTemplateITests extends AbstractLdapIntegrationTes
@Test
public void testMultiAttributeRetrievalWithNullAttributeNames() {
Set<Map<String, String[]>> values =
Set<Map<String, List<String>>> values =
template.searchForMultipleAttributeValues(
"ou=people",
"(uid={0})",
new String[]{"bob"},
null);
assertEquals(1, values.size());
Map<String, String[]> record = (Map<String, String[]>) values.toArray()[0];
Map<String, List<String>> record = values.iterator().next();
assertAttributeValue(record, "uid", "bob");
assertAttributeValue(record, "objectclass", "top", "person", "organizationalPerson", "inetOrgPerson");
assertAttributeValue(record, "cn", "Bob Hamilton");
@@ -119,14 +120,14 @@ public class SpringSecurityLdapTemplateITests extends AbstractLdapIntegrationTes
@Test
public void testMultiAttributeRetrievalWithZeroLengthAttributeNames() {
Set<Map<String, String[]>> values =
Set<Map<String, List<String>>> values =
template.searchForMultipleAttributeValues(
"ou=people",
"(uid={0})",
new String[]{"bob"},
new String[0]);
assertEquals(1, values.size());
Map<String, String[]> record = (Map<String, String[]>) values.toArray()[0];
Map<String, List<String>> record = values.iterator().next();
assertAttributeValue(record, "uid", "bob");
assertAttributeValue(record, "objectclass", "top", "person", "organizationalPerson", "inetOrgPerson");
assertAttributeValue(record, "cn", "Bob Hamilton");
@@ -136,7 +137,7 @@ public class SpringSecurityLdapTemplateITests extends AbstractLdapIntegrationTes
@Test
public void testMultiAttributeRetrievalWithSpecifiedAttributeNames() {
Set<Map<String, String[]>> values =
Set<Map<String, List<String>>> values =
template.searchForMultipleAttributeValues(
"ou=people",
"(uid={0})",
@@ -147,7 +148,7 @@ public class SpringSecurityLdapTemplateITests extends AbstractLdapIntegrationTes
"sn"
});
assertEquals(1, values.size());
Map<String, String[]> record = (Map<String, String[]>) values.toArray()[0];
Map<String, List<String>> record = values.iterator().next();
assertAttributeValue(record, "uid", "bob");
assertAttributeValue(record, "cn", "Bob Hamilton");
assertAttributeValue(record, "sn", "Hamilton");
@@ -155,11 +156,11 @@ public class SpringSecurityLdapTemplateITests extends AbstractLdapIntegrationTes
assertFalse(record.containsKey("objectclass"));
}
protected void assertAttributeValue(Map<String, String[]> record, String attributeName, String... values) {
protected void assertAttributeValue(Map<String, List<String>> record, String attributeName, String... values) {
assertTrue(record.containsKey(attributeName));
assertEquals(values.length, record.get(attributeName).length);
assertEquals(values.length, record.get(attributeName).size());
for (int i = 0; i < values.length; i++) {
assertEquals(values[i], record.get(attributeName)[i]);
assertEquals(values[i], record.get(attributeName).get(i));
}
}

View File

@@ -104,13 +104,13 @@ public class NestedLdapAuthoritiesPopulatorTests extends AbstractLdapIntegration
//closure group
assertTrue(ldapAuthorities[0].getAttributes().containsKey("member"));
assertNotNull(ldapAuthorities[0].getAttributes().get("member"));
assertEquals(1, ldapAuthorities[0].getAttributes().get("member").length);
assertEquals(1, ldapAuthorities[0].getAttributes().get("member").size());
assertEquals("uid=closuredude,ou=people,dc=springframework,dc=org", ldapAuthorities[0].getFirstAttributeValue("member"));
//java group
assertTrue(ldapAuthorities[1].getAttributes().containsKey("member"));
assertNotNull(ldapAuthorities[1].getAttributes().get("member"));
assertEquals(3, ldapAuthorities[1].getAttributes().get("member").length);
assertEquals(3, ldapAuthorities[1].getAttributes().get("member").size());
assertEquals(groovyDevelopers.getDn(), ldapAuthorities[1].getFirstAttributeValue("member"));
assertEquals(
new String[]{
@@ -124,7 +124,7 @@ public class NestedLdapAuthoritiesPopulatorTests extends AbstractLdapIntegration
//test non existent attribute
assertNull(ldapAuthorities[2].getFirstAttributeValue("test"));
assertNotNull(ldapAuthorities[2].getAttributeValues("test"));
assertEquals(0, ldapAuthorities[2].getAttributeValues("test").length);
assertEquals(0, ldapAuthorities[2].getAttributeValues("test").size());
//test role name
assertEquals(jDevelopers.getAuthority(), ldapAuthorities[3].getAuthority());
}