use of org.opensaml.core.xml.XMLObjectBuilder in project cxf by apache.
the class CustomClaimsHandler method retrieveClaimValues.
public ProcessedClaimCollection retrieveClaimValues(ClaimCollection claims, ClaimsParameters parameters) {
if (claims != null && !claims.isEmpty()) {
ProcessedClaimCollection claimCollection = new ProcessedClaimCollection();
for (Claim requestClaim : claims) {
ProcessedClaim claim = new ProcessedClaim();
claim.setClaimType(requestClaim.getClaimType());
if (ClaimTypes.FIRSTNAME.toString().equals(requestClaim.getClaimType())) {
if (requestClaim instanceof CustomRequestClaim) {
CustomRequestClaim customClaim = (CustomRequestClaim) requestClaim;
String customName = customClaim.getValues().get(0) + "@" + customClaim.getScope();
claim.addValue(customName);
} else {
claim.addValue("alice");
}
} else if (ClaimTypes.LASTNAME.toString().equals(requestClaim.getClaimType())) {
claim.addValue("doe");
} else if (ClaimTypes.EMAILADDRESS.toString().equals(requestClaim.getClaimType())) {
claim.addValue("alice@cxf.apache.org");
} else if (ClaimTypes.STREETADDRESS.toString().equals(requestClaim.getClaimType())) {
claim.addValue("1234 1st Street");
} else if (ClaimTypes.MOBILEPHONE.toString().equals(requestClaim.getClaimType())) {
// Test custom (Integer) attribute value
XMLObjectBuilderFactory builderFactory = XMLObjectProviderRegistrySupport.getBuilderFactory();
@SuppressWarnings("unchecked") XMLObjectBuilder<XSInteger> xsIntegerBuilder = (XMLObjectBuilder<XSInteger>) builderFactory.getBuilder(XSInteger.TYPE_NAME);
XSInteger attributeValue = xsIntegerBuilder.buildObject(AttributeValue.DEFAULT_ELEMENT_NAME, XSInteger.TYPE_NAME);
attributeValue.setValue(185912592);
claim.addValue(attributeValue);
} else if (ROLE_CLAIM.equals(requestClaim.getClaimType())) {
if (requestClaim.getValues().size() > 0) {
for (Object requestedRole : requestClaim.getValues()) {
if (isUserInRole(parameters.getPrincipal(), requestedRole.toString())) {
claim.addValue(requestedRole);
}
}
if (claim.getValues().isEmpty()) {
continue;
}
} else {
// If no specific role was requested return DUMMY role for user
claim.addValue(role);
}
}
claimCollection.add(claim);
}
return claimCollection;
}
return null;
}
Aggregations