use of org.apache.cxf.sts.claims.ProcessedClaimCollection in project cas by apereo.
the class WrappingSecurityTokenServiceClaimsHandler method retrieveClaimValues.
@Override
public ProcessedClaimCollection retrieveClaimValues(final ClaimCollection claims, final ClaimsParameters parameters) {
if (parameters.getRealm() == null || !parameters.getRealm().equalsIgnoreCase(this.realm)) {
LOGGER.warn("Realm [{}] doesn't match with configured realm [{}]", parameters.getRealm(), this.realm);
return new ProcessedClaimCollection();
}
if (parameters.getPrincipal() == null) {
LOGGER.warn("No principal could be identified in the claim parameters request");
return new ProcessedClaimCollection();
}
if (claims == null || claims.isEmpty()) {
LOGGER.warn("No claims are available to process");
return new ProcessedClaimCollection();
}
final ProcessedClaimCollection claimCollection = new ProcessedClaimCollection();
claims.stream().map(requestClaim -> {
final ProcessedClaim claim = new ProcessedClaim();
claim.setClaimType(requestClaim.getClaimType());
claim.setIssuer(this.issuer);
claim.setOriginalIssuer(this.issuer);
claim.setValues(requestClaim.getValues());
return claim;
}).forEach(claimCollection::add);
return claimCollection;
}
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"));
}
use of org.apache.cxf.sts.claims.ProcessedClaimCollection in project ddf by codice.
the class TestAttributeFileClaimsHandler method testRetrieveClaimValuesLocalhost.
@Test
public void testRetrieveClaimValuesLocalhost() {
ProcessedClaimCollection processedClaims = attributeFileClaimsHandler.retrieveClaimValues(claimCollection, localhostClaimsParameters);
assertThat(processedClaims.size(), is(0));
}
use of org.apache.cxf.sts.claims.ProcessedClaimCollection in project ddf by codice.
the class TestAttributeFileClaimsHandler method testRetrieveClaimsValuesNullPrincipal.
@Test
public void testRetrieveClaimsValuesNullPrincipal() {
ClaimsParameters claimsParameters = new ClaimsParameters();
ClaimCollection claimCollection = new ClaimCollection();
ProcessedClaimCollection processedClaims = attributeFileClaimsHandler.retrieveClaimValues(claimCollection, claimsParameters);
Assert.assertThat(processedClaims.size(), CoreMatchers.is(equalTo(0)));
}
Aggregations