use of org.apache.cxf.sts.claims.ProcessedClaimCollection in project ddf by codice.
the class CertificateClaimsHandlerTest method testRetrieveClaimValuesWithEmail.
@Test
public void testRetrieveClaimValuesWithEmail() throws URISyntaxException {
CertificateClaimsHandler certificateClaimsHandler = new CertificateClaimsHandler();
ClaimCollection claims = getClaims();
ClaimsParameters parameters = new ClaimsParameters();
parameters.setPrincipal(mock(Principal.class));
Map<String, Object> map = new HashMap<>();
map.put(SubjectUtils.EMAIL_ADDRESS_CLAIM_URI, "local@localhost");
parameters.setAdditionalProperties(map);
ProcessedClaimCollection processedClaims = certificateClaimsHandler.retrieveClaimValues(claims, parameters);
assertThat(processedClaims.size(), is(1));
assertThat(processedClaims.stream().map(c -> c.getClaimType().toString()).collect(Collectors.toList()), containsInAnyOrder(SubjectUtils.EMAIL_ADDRESS_CLAIM_URI));
}
use of org.apache.cxf.sts.claims.ProcessedClaimCollection in project ddf by codice.
the class LdapClaimsHandlerTest method testRetrieveClaimsValues.
@Test
public void testRetrieveClaimsValues() throws URISyntaxException {
when(mockBindResult.isSuccess()).thenReturn(true);
ProcessedClaimCollection processedClaims = claimsHandler.retrieveClaimValues(claims, claimsParameters);
assertThat(processedClaims, hasSize(1));
Claim claim = processedClaims.get(0);
assertThat(claim.getValues(), contains(DUMMY_VALUE));
}
use of org.apache.cxf.sts.claims.ProcessedClaimCollection in project ddf by codice.
the class LdapClaimsHandlerTest method testRetrieveClaimsValuesNullPrincipal.
@Test
public void testRetrieveClaimsValuesNullPrincipal() {
when(mockBindResult.isSuccess()).thenReturn(false);
ProcessedClaimCollection processedClaims = claimsHandler.retrieveClaimValues(new ClaimCollection(), claimsParameters);
assertThat(processedClaims.size(), CoreMatchers.is(equalTo(0)));
}
use of org.apache.cxf.sts.claims.ProcessedClaimCollection in project ddf by codice.
the class AttributeFileClaimsHandler method retrieveClaimValues.
@Override
public ProcessedClaimCollection retrieveClaimValues(ClaimCollection claimCollection, ClaimsParameters claimsParameters) {
ProcessedClaimCollection claimsColl = new ProcessedClaimCollection();
Principal principal = claimsParameters.getPrincipal();
if (principal == null) {
return claimsColl;
}
String name;
if (principal instanceof X500Principal) {
name = SubjectUtils.getCommonName((X500Principal) principal);
} else {
name = principal.getName();
}
Object user = json.get(name);
Map userMap = null;
if (user != null) {
if (user instanceof Map) {
userMap = (Map) user;
}
} else {
Set<Map.Entry<String, Object>> entries = json.entrySet();
for (Map.Entry<String, Object> entry : entries) {
String key = entry.getKey();
Pattern pattern = Pattern.compile(key);
Matcher matcher = pattern.matcher(principal.getName());
if (matcher.matches()) {
userMap = (Map) entry.getValue();
break;
}
}
}
if (userMap == null) {
return claimsColl;
}
for (Claim claim : claimCollection) {
Object attributeValue = userMap.get(claim.getClaimType().toString());
ProcessedClaim c = new ProcessedClaim();
c.setClaimType(claim.getClaimType());
c.setPrincipal(principal);
if (attributeValue instanceof List) {
((List) attributeValue).forEach(c::addValue);
claimsColl.add(c);
} else if (attributeValue instanceof String) {
c.addValue(attributeValue);
claimsColl.add(c);
}
}
return claimsColl;
}
use of org.apache.cxf.sts.claims.ProcessedClaimCollection in project ddf by codice.
the class TestAttributeFileClaimsHandler method testRetrieveClaimValuesRegex.
@Test
public void testRetrieveClaimValuesRegex() {
ProcessedClaimCollection processedClaims = attributeFileClaimsHandler.retrieveClaimValues(claimCollection, regexClaimsParameters);
assertThat(processedClaims.size(), is(1));
assertThat(processedClaims.get(0).getClaimType().toString(), is("reg"));
assertThat(processedClaims.get(0).getValues().get(0), is("ex"));
}
Aggregations