use of ddf.security.claims.ClaimsCollection in project ddf by codice.
the class CertificateClaimsHandlerTest method testRetrieveClaimValuesWithAltNamesRequested.
@Test
public void testRetrieveClaimValuesWithAltNamesRequested() throws URISyntaxException {
CertificateClaimsHandler certificateClaimsHandler = new CertificateClaimsHandler();
certificateClaimsHandler.setCountryClaim("Country");
certificateClaimsHandler.setEmailClaim("Email");
Map<String, Object> map = new HashMap<>();
map.put(SubjectOperations.EMAIL_ADDRESS_CLAIM_URI, "local@localhost");
map.put(SubjectOperations.COUNTRY_CLAIM_URI, "USA");
ClaimsParameters parameters = new ClaimsParametersImpl(mock(Principal.class), new HashSet<>(), map);
ClaimsCollection processedClaims = certificateClaimsHandler.retrieveClaims(parameters);
assertThat(processedClaims.size(), is(2));
assertThat(processedClaims.stream().map(ddf.security.claims.Claim::getName).collect(Collectors.toList()), containsInAnyOrder("Email", "Country"));
}
use of ddf.security.claims.ClaimsCollection in project ddf by codice.
the class CertificateClaimsHandlerTest method testRetrieveClaimValuesWithEmail.
@Test
public void testRetrieveClaimValuesWithEmail() throws URISyntaxException {
CertificateClaimsHandler certificateClaimsHandler = new CertificateClaimsHandler();
Map<String, Object> map = new HashMap<>();
map.put(SubjectOperations.EMAIL_ADDRESS_CLAIM_URI, "local@localhost");
ClaimsParameters parameters = new ClaimsParametersImpl(mock(Principal.class), new HashSet<>(), map);
ClaimsCollection processedClaims = certificateClaimsHandler.retrieveClaims(parameters);
assertThat(processedClaims.size(), is(1));
assertThat(processedClaims.stream().map(ddf.security.claims.Claim::getName).collect(Collectors.toList()), containsInAnyOrder(SubjectOperations.EMAIL_ADDRESS_CLAIM_URI));
}
use of ddf.security.claims.ClaimsCollection in project ddf by codice.
the class RoleClaimsHandlerTest method testRetrieveClaimsValuesIgnoredReferences.
@Test
public void testRetrieveClaimsValuesIgnoredReferences() throws LdapException, SearchResultReferenceIOException {
BindResult bindResult = mock(BindResult.class);
ClaimsParameters claimsParameters;
Connection connection = mock(Connection.class);
ConnectionEntryReader membershipReader = mock(ConnectionEntryReader.class);
ConnectionEntryReader groupNameReader = mock(ConnectionEntryReader.class);
LinkedAttribute membershipAttribute = new LinkedAttribute("uid");
LinkedAttribute groupNameAttribute = new LinkedAttribute("cn");
ClaimsCollection processedClaims;
RoleClaimsHandler claimsHandler;
SearchResultEntry membershipSearchResult = mock(SearchResultEntry.class);
DN resultDN = DN.valueOf("uid=tstark,");
SearchResultEntry groupNameSearchResult = mock(SearchResultEntry.class);
String groupName = "avengers";
when(bindResult.isSuccess()).thenReturn(true);
membershipAttribute.add("tstark");
when(membershipSearchResult.getAttribute(anyString())).thenReturn(membershipAttribute);
// simulate two items in the list (a reference and an entry)
when(membershipReader.hasNext()).thenReturn(true, true, false);
// test a reference followed by entries thereafter
when(membershipReader.isEntry()).thenReturn(false, true);
when(membershipReader.readEntry()).thenReturn(membershipSearchResult);
when(membershipSearchResult.getName()).thenReturn(resultDN);
groupNameAttribute.add(groupName);
when(groupNameSearchResult.getAttribute(anyString())).thenReturn(groupNameAttribute);
when(groupNameReader.hasNext()).thenReturn(true, true, false);
when(groupNameReader.isEntry()).thenReturn(false, true);
when(groupNameReader.readEntry()).thenReturn(groupNameSearchResult);
when(connection.bind(any())).thenReturn(bindResult);
when(connection.search(any(), any(), eq("(&(objectClass=groupOfNames)(|(member=uid=tstark,)(member=uid=tstark,)))"), any())).thenReturn(groupNameReader);
when(connection.search(anyString(), any(), anyString(), matches("uid"))).thenReturn(membershipReader);
claimsHandler = new RoleClaimsHandler(new AttributeMapLoader(new SubjectUtils()));
ConnectionFactory mockConnectionFactory = mock(ConnectionFactory.class);
when(mockConnectionFactory.getConnection()).thenReturn(connection);
claimsHandler.setLdapConnectionFactory(mockConnectionFactory);
claimsHandler.setBindMethod("Simple");
claimsHandler.setBindUserCredentials("foo");
claimsHandler.setBindUserDN("bar");
claimsParameters = new ClaimsParametersImpl(new UserPrincipal(USER_CN), new HashSet<>(), new HashMap<>());
processedClaims = claimsHandler.retrieveClaims(claimsParameters);
assertThat(processedClaims, hasSize(1));
Claim claim = processedClaims.get(0);
assertThat(claim.getValues(), hasSize(1));
assertThat(claim.getValues().get(0), equalTo(groupName));
}
use of ddf.security.claims.ClaimsCollection in project ddf by codice.
the class CertificateClaimsHandler method retrieveClaims.
@Override
public ClaimsCollection retrieveClaims(ClaimsParameters parameters) {
ClaimsCollection claimsColl = new ClaimsCollectionImpl();
Map<String, Object> additionalProperties = parameters.getAdditionalProperties();
if (additionalProperties != null) {
if (additionalProperties.containsKey(SubjectOperations.EMAIL_ADDRESS_CLAIM_URI)) {
buildClaim(claimsColl, emailClaim, additionalProperties.get(SubjectOperations.EMAIL_ADDRESS_CLAIM_URI));
}
if (additionalProperties.containsKey(SubjectOperations.COUNTRY_CLAIM_URI)) {
buildClaim(claimsColl, countryClaim, additionalProperties.get(SubjectOperations.COUNTRY_CLAIM_URI));
}
}
return claimsColl;
}
use of ddf.security.claims.ClaimsCollection in project ddf by codice.
the class LdapClaimsHandlerTest method testRetrieveClaimsValuesNullPrincipal.
@Test
public void testRetrieveClaimsValuesNullPrincipal() throws LdapException {
when(mockBindResult.isSuccess()).thenReturn(false);
ClaimsCollection processedClaims = claimsHandler.retrieveClaims(claimsParameters);
assertThat(processedClaims.size(), CoreMatchers.is(equalTo(0)));
}
Aggregations