Search in sources :

Example 31 with CustomClaimsHandler

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();
}
Also used : TokenProvider(org.apache.cxf.sts.token.provider.TokenProvider) SAMLTokenProvider(org.apache.cxf.sts.token.provider.SAMLTokenProvider) ClaimsHandler(org.apache.cxf.sts.claims.ClaimsHandler) CustomClaimsHandler(org.apache.cxf.sts.common.CustomClaimsHandler) SAMLTokenProvider(org.apache.cxf.sts.token.provider.SAMLTokenProvider) Element(org.w3c.dom.Element) ClaimsManager(org.apache.cxf.sts.claims.ClaimsManager) TokenProviderResponse(org.apache.cxf.sts.token.provider.TokenProviderResponse) CustomClaimsHandler(org.apache.cxf.sts.common.CustomClaimsHandler) ClaimCollection(org.apache.cxf.rt.security.claims.ClaimCollection) Claim(org.apache.cxf.rt.security.claims.Claim) TokenProviderParameters(org.apache.cxf.sts.token.provider.TokenProviderParameters)

Aggregations

ClaimsHandler (org.apache.cxf.sts.claims.ClaimsHandler)31 ClaimsManager (org.apache.cxf.sts.claims.ClaimsManager)31 CustomClaimsHandler (org.apache.cxf.sts.common.CustomClaimsHandler)31 Element (org.w3c.dom.Element)26 JAXBElement (javax.xml.bind.JAXBElement)21 ClaimCollection (org.apache.cxf.rt.security.claims.ClaimCollection)16 SAMLTokenProvider (org.apache.cxf.sts.token.provider.SAMLTokenProvider)16 ArrayList (java.util.ArrayList)15 RequestSecurityTokenType (org.apache.cxf.ws.security.sts.provider.model.RequestSecurityTokenType)15 RequestSecurityTokenResponseType (org.apache.cxf.ws.security.sts.provider.model.RequestSecurityTokenResponseType)14 RequestedSecurityTokenType (org.apache.cxf.ws.security.sts.provider.model.RequestedSecurityTokenType)14 Claim (org.apache.cxf.rt.security.claims.Claim)13 ClaimsAttributeStatementProvider (org.apache.cxf.sts.claims.ClaimsAttributeStatementProvider)11 AttributeStatementProvider (org.apache.cxf.sts.token.provider.AttributeStatementProvider)11 TokenProvider (org.apache.cxf.sts.token.provider.TokenProvider)11 CustomTokenPrincipal (org.apache.wss4j.common.principal.CustomTokenPrincipal)11 JwsJwtCompactConsumer (org.apache.cxf.rs.security.jose.jws.JwsJwtCompactConsumer)9 JwtToken (org.apache.cxf.rs.security.jose.jwt.JwtToken)9 StaticClaimsHandler (org.apache.cxf.sts.claims.StaticClaimsHandler)9 JWTTokenProvider (org.apache.cxf.sts.token.provider.jwt.JWTTokenProvider)9