RequestClaimCollection claims, ClaimsParameters parameters) {
if (claims != null && claims.size() > 0) {
ClaimCollection claimCollection = new ClaimCollection();
for (RequestClaim requestClaim : claims) {
Claim claim = new Claim();
claim.setClaimType(requestClaim.getClaimType());
if (ClaimTypes.FIRSTNAME.equals(requestClaim.getClaimType())) {
if (requestClaim instanceof CustomRequestClaim) {
CustomRequestClaim customClaim = (CustomRequestClaim) requestClaim;
String customName = customClaim.getClaimValue() + "@" + customClaim.getScope();
claim.addValue(customName);
} else {
claim.addValue("alice");
}
} else if (ClaimTypes.LASTNAME.equals(requestClaim.getClaimType())) {
claim.addValue("doe");
} else if (ClaimTypes.EMAILADDRESS.equals(requestClaim.getClaimType())) {
claim.addValue("alice@cxf.apache.org");
} else if (ClaimTypes.STREETADDRESS.equals(requestClaim.getClaimType())) {
claim.addValue("1234 1st Street");
} else if (ClaimTypes.MOBILEPHONE.equals(requestClaim.getClaimType())) {
// Test custom (Integer) attribute value
XMLObjectBuilderFactory builderFactory = Configuration.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())) {
String requestedRole = requestClaim.getClaimValue();
if (isUserInRole(parameters.getPrincipal(), requestedRole)) {
claim.addValue(requestedRole);
} else {
continue;
}
}
claimCollection.add(claim);