Search in sources :

Example 41 with ClaimCollection

use of org.apache.cxf.rt.security.claims.ClaimCollection in project cxf by apache.

the class RealmSupportTest method testFilteredRealmAIdentityMapping.

@org.junit.Test
public void testFilteredRealmAIdentityMapping() throws Exception {
    ClaimsManager claimsManager = new ClaimsManager();
    claimsManager.setIdentityMapper(new CustomIdentityMapper());
    RealmSupportClaimsHandler realmAHandler = new RealmSupportClaimsHandler();
    realmAHandler.setRealm("A");
    realmAHandler.setSupportedClaimTypes(Collections.singletonList("Claim-A"));
    RealmSupportClaimsHandler realmBHandler = new RealmSupportClaimsHandler();
    realmBHandler.setRealm("B");
    realmBHandler.setSupportedClaimTypes(Collections.singletonList("Claim-B"));
    RealmSupportClaimsHandler realmCHandler = new RealmSupportClaimsHandler();
    realmCHandler.setRealm("A");
    realmCHandler.setSupportedRealms(Collections.singletonList("A"));
    realmCHandler.setSupportedClaimTypes(Collections.singletonList("Claim-C"));
    claimsManager.setClaimHandlers(Arrays.asList(realmAHandler, realmBHandler, realmCHandler));
    ClaimCollection requestedClaims = createClaimCollection();
    ClaimsParameters parameters = new ClaimsParameters();
    parameters.setRealm("A");
    parameters.setPrincipal(new CustomTokenPrincipal("alice"));
    ProcessedClaimCollection claims = claimsManager.retrieveClaimValues(requestedClaims, parameters);
    Assert.assertEquals("Number of claims incorrect", 3, claims.size());
// Asserts in RealmSupportClaimsHandler must succeed
}
Also used : CustomTokenPrincipal(org.apache.wss4j.common.principal.CustomTokenPrincipal) CustomIdentityMapper(org.apache.cxf.sts.operation.CustomIdentityMapper) ProcessedClaimCollection(org.apache.cxf.sts.claims.ProcessedClaimCollection) ClaimsManager(org.apache.cxf.sts.claims.ClaimsManager) ClaimCollection(org.apache.cxf.rt.security.claims.ClaimCollection) ProcessedClaimCollection(org.apache.cxf.sts.claims.ProcessedClaimCollection) RealmSupportClaimsHandler(org.apache.cxf.sts.common.RealmSupportClaimsHandler) ClaimsParameters(org.apache.cxf.sts.claims.ClaimsParameters)

Example 42 with ClaimCollection

use of org.apache.cxf.rt.security.claims.ClaimCollection in project cxf by apache.

the class RealmSupportTest method testFilteredRealmBIdentityMapping.

@org.junit.Test
public void testFilteredRealmBIdentityMapping() throws Exception {
    ClaimsManager claimsManager = new ClaimsManager();
    claimsManager.setIdentityMapper(new CustomIdentityMapper());
    RealmSupportClaimsHandler realmAHandler = new RealmSupportClaimsHandler();
    realmAHandler.setRealm("A");
    realmAHandler.setSupportedClaimTypes(Collections.singletonList("Claim-A"));
    RealmSupportClaimsHandler realmBHandler = new RealmSupportClaimsHandler();
    realmBHandler.setRealm("B");
    realmBHandler.setSupportedClaimTypes(Collections.singletonList("Claim-B"));
    RealmSupportClaimsHandler realmCHandler = new RealmSupportClaimsHandler();
    realmCHandler.setRealm("A");
    realmCHandler.setSupportedRealms(Collections.singletonList("A"));
    realmCHandler.setSupportedClaimTypes(Collections.singletonList("Claim-C"));
    claimsManager.setClaimHandlers(Arrays.asList(realmAHandler, realmBHandler, realmCHandler));
    ClaimCollection requestedClaims = createClaimCollection();
    ClaimsParameters parameters = new ClaimsParameters();
    parameters.setRealm("B");
    parameters.setPrincipal(new CustomTokenPrincipal("ALICE"));
    ProcessedClaimCollection claims = claimsManager.retrieveClaimValues(requestedClaims, parameters);
    Assert.assertEquals("Number of claims incorrect", 2, claims.size());
// Asserts in RealmSupportClaimsHandler must succeed
}
Also used : CustomTokenPrincipal(org.apache.wss4j.common.principal.CustomTokenPrincipal) CustomIdentityMapper(org.apache.cxf.sts.operation.CustomIdentityMapper) ProcessedClaimCollection(org.apache.cxf.sts.claims.ProcessedClaimCollection) ClaimsManager(org.apache.cxf.sts.claims.ClaimsManager) ClaimCollection(org.apache.cxf.rt.security.claims.ClaimCollection) ProcessedClaimCollection(org.apache.cxf.sts.claims.ProcessedClaimCollection) RealmSupportClaimsHandler(org.apache.cxf.sts.common.RealmSupportClaimsHandler) ClaimsParameters(org.apache.cxf.sts.claims.ClaimsParameters)

Example 43 with ClaimCollection

use of org.apache.cxf.rt.security.claims.ClaimCollection in project cxf by apache.

the class RealmSupportTest method testIdentityMappingRealmB2A.

@org.junit.Test
public void testIdentityMappingRealmB2A() throws Exception {
    ClaimsManager claimsManager = new ClaimsManager();
    claimsManager.setIdentityMapper(new CustomIdentityMapper());
    RealmSupportClaimsHandler realmAHandler = new RealmSupportClaimsHandler();
    realmAHandler.setRealm("A");
    realmAHandler.setSupportedClaimTypes(Collections.singletonList("Claim-A"));
    RealmSupportClaimsHandler realmBHandler = new RealmSupportClaimsHandler();
    realmBHandler.setRealm("B");
    realmBHandler.setSupportedClaimTypes(Collections.singletonList("Claim-B"));
    RealmSupportClaimsHandler realmCHandler = new RealmSupportClaimsHandler();
    realmCHandler.setRealm("B");
    realmCHandler.setSupportedClaimTypes(Collections.singletonList("Claim-C"));
    claimsManager.setClaimHandlers(Arrays.asList(realmAHandler, realmBHandler, realmCHandler));
    ClaimCollection requestedClaims = createClaimCollection();
    ClaimsParameters parameters = new ClaimsParameters();
    parameters.setRealm("B");
    parameters.setPrincipal(new CustomTokenPrincipal("ALICE"));
    ProcessedClaimCollection claims = claimsManager.retrieveClaimValues(requestedClaims, parameters);
    Assert.assertEquals("Number of claims incorrect", 3, claims.size());
}
Also used : CustomTokenPrincipal(org.apache.wss4j.common.principal.CustomTokenPrincipal) CustomIdentityMapper(org.apache.cxf.sts.operation.CustomIdentityMapper) ProcessedClaimCollection(org.apache.cxf.sts.claims.ProcessedClaimCollection) ClaimsManager(org.apache.cxf.sts.claims.ClaimsManager) ClaimCollection(org.apache.cxf.rt.security.claims.ClaimCollection) ProcessedClaimCollection(org.apache.cxf.sts.claims.ProcessedClaimCollection) RealmSupportClaimsHandler(org.apache.cxf.sts.common.RealmSupportClaimsHandler) ClaimsParameters(org.apache.cxf.sts.claims.ClaimsParameters)

Example 44 with ClaimCollection

use of org.apache.cxf.rt.security.claims.ClaimCollection in project cxf by apache.

the class ValidateTokenTransformationUnitTest method createSAMLAssertion.

/*
     * Mock up an SAML assertion element
     */
private static Element createSAMLAssertion(String tokenType, Crypto crypto, String signatureUsername, CallbackHandler callbackHandler, Map<String, RealmProperties> realms) throws WSSecurityException {
    SAMLTokenProvider samlTokenProvider = new SAMLTokenProvider();
    samlTokenProvider.setRealmMap(realms);
    samlTokenProvider.setAttributeStatementProviders(Collections.singletonList(new ClaimsAttributeStatementProvider()));
    TokenProviderParameters providerParameters = createProviderParameters(tokenType, STSConstants.BEARER_KEY_KEYTYPE, crypto, signatureUsername, callbackHandler);
    if (realms != null) {
        providerParameters.setRealm("A");
    }
    // Set the ClaimsManager
    ClaimsManager claimsManager = new ClaimsManager();
    ClaimsHandler claimsHandler = new CustomClaimsHandler();
    claimsManager.setClaimHandlers(Collections.singletonList(claimsHandler));
    providerParameters.setClaimsManager(claimsManager);
    ClaimCollection requestedClaims = new ClaimCollection();
    Claim requestClaim = new Claim();
    requestClaim.setClaimType(ClaimTypes.LASTNAME);
    requestClaim.setOptional(false);
    requestedClaims.add(requestClaim);
    providerParameters.setRequestedSecondaryClaims(requestedClaims);
    TokenProviderResponse providerResponse = samlTokenProvider.createToken(providerParameters);
    assertNotNull(providerResponse);
    assertTrue(providerResponse.getToken() != null && providerResponse.getTokenId() != null);
    return (Element) providerResponse.getToken();
}
Also used : ClaimsAttributeStatementProvider(org.apache.cxf.sts.claims.ClaimsAttributeStatementProvider) ClaimsHandler(org.apache.cxf.sts.claims.ClaimsHandler) CustomClaimsHandler(org.apache.cxf.sts.common.CustomClaimsHandler) SAMLTokenProvider(org.apache.cxf.sts.token.provider.SAMLTokenProvider) JAXBElement(javax.xml.bind.JAXBElement) 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)

Example 45 with ClaimCollection

use of org.apache.cxf.rt.security.claims.ClaimCollection in project cxf by apache.

the class JWTClaimsTest method testJWTStaticClaims.

/**
 * Test the creation of a JWTToken with StaticClaimsHandler
 */
@org.junit.Test
public void testJWTStaticClaims() throws Exception {
    TokenProvider tokenProvider = new JWTTokenProvider();
    TokenProviderParameters providerParameters = createProviderParameters(JWTTokenProvider.JWT_TOKEN_TYPE, null);
    ClaimsManager claimsManager = new ClaimsManager();
    StaticClaimsHandler claimsHandler = new StaticClaimsHandler();
    Map<String, String> staticClaimsMap = new HashMap<>();
    staticClaimsMap.put(CLAIM_STATIC_COMPANY.toString(), CLAIM_STATIC_COMPANY_VALUE);
    claimsHandler.setGlobalClaims(staticClaimsMap);
    claimsManager.setClaimHandlers(Collections.singletonList((ClaimsHandler) claimsHandler));
    providerParameters.setClaimsManager(claimsManager);
    ClaimCollection claims = new ClaimCollection();
    Claim claim = new Claim();
    claim.setClaimType(CLAIM_STATIC_COMPANY);
    claims.add(claim);
    providerParameters.setRequestedPrimaryClaims(claims);
    TokenProviderResponse providerResponse = tokenProvider.createToken(providerParameters);
    assertNotNull(providerResponse);
    assertTrue(providerResponse.getToken() != null && providerResponse.getTokenId() != null);
    String token = (String) providerResponse.getToken();
    assertNotNull(token);
    JwsJwtCompactConsumer jwtConsumer = new JwsJwtCompactConsumer(token);
    JwtToken jwt = jwtConsumer.getJwtToken();
    assertEquals(jwt.getClaim(CLAIM_STATIC_COMPANY.toString()), CLAIM_STATIC_COMPANY_VALUE);
}
Also used : ClaimsHandler(org.apache.cxf.sts.claims.ClaimsHandler) StaticClaimsHandler(org.apache.cxf.sts.claims.StaticClaimsHandler) CustomClaimsHandler(org.apache.cxf.sts.common.CustomClaimsHandler) HashMap(java.util.HashMap) StaticClaimsHandler(org.apache.cxf.sts.claims.StaticClaimsHandler) JwtToken(org.apache.cxf.rs.security.jose.jwt.JwtToken) JWTTokenProvider(org.apache.cxf.sts.token.provider.jwt.JWTTokenProvider) ClaimsManager(org.apache.cxf.sts.claims.ClaimsManager) JwsJwtCompactConsumer(org.apache.cxf.rs.security.jose.jws.JwsJwtCompactConsumer) ClaimCollection(org.apache.cxf.rt.security.claims.ClaimCollection) Claim(org.apache.cxf.rt.security.claims.Claim) JWTTokenProvider(org.apache.cxf.sts.token.provider.jwt.JWTTokenProvider)

Aggregations

ClaimCollection (org.apache.cxf.rt.security.claims.ClaimCollection)100 Claim (org.apache.cxf.rt.security.claims.Claim)63 ClaimsManager (org.apache.cxf.sts.claims.ClaimsManager)46 ClaimsParameters (org.apache.cxf.sts.claims.ClaimsParameters)43 ProcessedClaimCollection (org.apache.cxf.sts.claims.ProcessedClaimCollection)42 ProcessedClaim (org.apache.cxf.sts.claims.ProcessedClaim)31 CustomTokenPrincipal (org.apache.wss4j.common.principal.CustomTokenPrincipal)26 ClaimsHandler (org.apache.cxf.sts.claims.ClaimsHandler)23 Principal (java.security.Principal)22 CustomClaimsHandler (org.apache.cxf.sts.common.CustomClaimsHandler)22 URI (java.net.URI)21 Element (org.w3c.dom.Element)21 StaticClaimsHandler (org.apache.cxf.sts.claims.StaticClaimsHandler)15 SamlAssertionWrapper (org.apache.wss4j.common.saml.SamlAssertionWrapper)13 ArrayList (java.util.ArrayList)12 LdapClaimsHandler (org.apache.cxf.sts.claims.LdapClaimsHandler)12 JAXBElement (javax.xml.bind.JAXBElement)10 Test (org.junit.Test)10 SAMLSecurityContext (org.apache.cxf.rt.security.saml.claims.SAMLSecurityContext)9 StaticEndpointClaimsHandler (org.apache.cxf.sts.claims.StaticEndpointClaimsHandler)9