use of org.apache.cxf.sts.common.CustomClaimsHandler in project cxf by apache.
the class SAMLTokenValidatorTest method createSAMLAssertionWithRoles.
private Element createSAMLAssertionWithRoles(String tokenType, Crypto crypto, String signatureUsername, CallbackHandler callbackHandler, String role) throws WSSecurityException {
TokenProvider samlTokenProvider = new SAMLTokenProvider();
TokenProviderParameters providerParameters = createProviderParameters("alice", tokenType, STSConstants.BEARER_KEY_KEYTYPE, crypto, signatureUsername, callbackHandler);
ClaimsManager claimsManager = new ClaimsManager();
ClaimsHandler claimsHandler = new CustomClaimsHandler();
claimsManager.setClaimHandlers(Collections.singletonList(claimsHandler));
providerParameters.setClaimsManager(claimsManager);
ClaimCollection claims = new ClaimCollection();
Claim claim = new Claim();
claim.setClaimType(URI.create("http://schemas.xmlsoap.org/ws/2005/05/identity/claims/role"));
claim.addValue(role);
claims.add(claim);
providerParameters.setRequestedPrimaryClaims(claims);
TokenProviderResponse providerResponse = samlTokenProvider.createToken(providerParameters);
assertTrue(providerResponse != null);
assertTrue(providerResponse.getToken() != null && providerResponse.getTokenId() != null);
return (Element) providerResponse.getToken();
}
Aggregations