Search in sources :

Example 21 with ProcessedClaimCollection

use of org.apache.cxf.sts.claims.ProcessedClaimCollection in project cxf by apache.

the class JexlClaimsMapperTest method testUpdateIssuer.

@Test
public void testUpdateIssuer() throws IOException {
    ProcessedClaimCollection result = jcm.mapClaims("A", createClaimCollection(), "B", createProperties());
    assertNotNull(result);
    assertEquals("STS-B", result.get(0).getOriginalIssuer());
    assertEquals("NewIssuer", result.get(0).getIssuer());
    assertEquals("STS-A", result.get(1).getOriginalIssuer());
}
Also used : ProcessedClaimCollection(org.apache.cxf.sts.claims.ProcessedClaimCollection) Test(org.junit.Test)

Example 22 with ProcessedClaimCollection

use of org.apache.cxf.sts.claims.ProcessedClaimCollection in project cxf by apache.

the class JexlClaimsMapperTest method testStaticClaim.

@Test
public void testStaticClaim() throws IOException {
    ProcessedClaimCollection result = jcm.mapClaims("A", createClaimCollection(), "B", createProperties());
    assertNotNull(result);
    ProcessedClaim staticClaim = findClaim(result, "http://schemas.microsoft.com/identity/claims/identityprovider");
    assertNotNull(staticClaim);
}
Also used : ProcessedClaimCollection(org.apache.cxf.sts.claims.ProcessedClaimCollection) ProcessedClaim(org.apache.cxf.sts.claims.ProcessedClaim) Test(org.junit.Test)

Example 23 with ProcessedClaimCollection

use of org.apache.cxf.sts.claims.ProcessedClaimCollection in project cxf by apache.

the class CustomAttributeProvider method getStatement.

/**
 * Get an AttributeStatementBean using the given parameters.
 */
public AttributeStatementBean getStatement(TokenProviderParameters providerParameters) {
    List<AttributeBean> attributeList = new ArrayList<>();
    TokenRequirements tokenRequirements = providerParameters.getTokenRequirements();
    String tokenType = tokenRequirements.getTokenType();
    // Handle Claims
    ProcessedClaimCollection retrievedClaims = ClaimsUtils.processClaims(providerParameters);
    AttributeStatementBean attrBean = new AttributeStatementBean();
    Iterator<ProcessedClaim> claimIterator = retrievedClaims.iterator();
    if (!claimIterator.hasNext()) {
        // If no Claims have been processed then create a default attribute
        AttributeBean attributeBean = createDefaultAttribute(tokenType);
        attributeList.add(attributeBean);
    }
    while (claimIterator.hasNext()) {
        ProcessedClaim claim = claimIterator.next();
        AttributeBean attributeBean = createAttributeFromClaim(claim, tokenType);
        attributeList.add(attributeBean);
    }
    ReceivedToken onBehalfOf = tokenRequirements.getOnBehalfOf();
    ReceivedToken actAs = tokenRequirements.getActAs();
    try {
        if (onBehalfOf != null) {
            AttributeBean parameterBean = handleAdditionalParameters(false, onBehalfOf.getToken(), tokenType);
            if (!parameterBean.getAttributeValues().isEmpty()) {
                attributeList.add(parameterBean);
            }
        }
        if (actAs != null) {
            AttributeBean parameterBean = handleAdditionalParameters(true, actAs.getToken(), tokenType);
            if (!parameterBean.getAttributeValues().isEmpty()) {
                attributeList.add(parameterBean);
            }
        }
    } catch (WSSecurityException ex) {
        throw new STSException(ex.getMessage(), ex);
    }
    attrBean.setSamlAttributes(attributeList);
    return attrBean;
}
Also used : AttributeStatementBean(org.apache.wss4j.common.saml.bean.AttributeStatementBean) ProcessedClaimCollection(org.apache.cxf.sts.claims.ProcessedClaimCollection) TokenRequirements(org.apache.cxf.sts.request.TokenRequirements) ProcessedClaim(org.apache.cxf.sts.claims.ProcessedClaim) ArrayList(java.util.ArrayList) STSException(org.apache.cxf.ws.security.sts.provider.STSException) WSSecurityException(org.apache.wss4j.common.ext.WSSecurityException) AttributeBean(org.apache.wss4j.common.saml.bean.AttributeBean) ReceivedToken(org.apache.cxf.sts.request.ReceivedToken)

Example 24 with ProcessedClaimCollection

use of org.apache.cxf.sts.claims.ProcessedClaimCollection in project cxf by apache.

the class CustomUserClaimsHandler 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.equals(requestClaim.getClaimType())) {
                if (parameters.getPrincipal().getName().equalsIgnoreCase("alice")) {
                    claim.addValue("aliceClaim");
                } else if (parameters.getPrincipal().getName().equalsIgnoreCase("bob")) {
                    claim.addValue("bobClaim");
                }
            }
            claimCollection.add(claim);
        }
        return claimCollection;
    }
    return null;
}
Also used : ProcessedClaimCollection(org.apache.cxf.sts.claims.ProcessedClaimCollection) ProcessedClaim(org.apache.cxf.sts.claims.ProcessedClaim) ProcessedClaim(org.apache.cxf.sts.claims.ProcessedClaim) Claim(org.apache.cxf.rt.security.claims.Claim)

Example 25 with ProcessedClaimCollection

use of org.apache.cxf.sts.claims.ProcessedClaimCollection 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(URI.create("Claim-A")));
    RealmSupportClaimsHandler realmBHandler = new RealmSupportClaimsHandler();
    realmBHandler.setRealm("B");
    realmBHandler.setSupportedClaimTypes(Collections.singletonList(URI.create("Claim-B")));
    RealmSupportClaimsHandler realmCHandler = new RealmSupportClaimsHandler();
    realmCHandler.setRealm("A");
    realmCHandler.setSupportedRealms(Collections.singletonList("A"));
    realmCHandler.setSupportedClaimTypes(Collections.singletonList(URI.create("Claim-C")));
    List<ClaimsHandler> claimHandlers = new ArrayList<>();
    claimHandlers.add(realmAHandler);
    claimHandlers.add(realmBHandler);
    claimHandlers.add(realmCHandler);
    claimsManager.setClaimHandlers(Collections.unmodifiableList(claimHandlers));
    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) ClaimsHandler(org.apache.cxf.sts.claims.ClaimsHandler) RealmSupportClaimsHandler(org.apache.cxf.sts.common.RealmSupportClaimsHandler) ProcessedClaimCollection(org.apache.cxf.sts.claims.ProcessedClaimCollection) ArrayList(java.util.ArrayList) 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)

Aggregations

ProcessedClaimCollection (org.apache.cxf.sts.claims.ProcessedClaimCollection)68 ProcessedClaim (org.apache.cxf.sts.claims.ProcessedClaim)40 Test (org.junit.Test)32 ClaimCollection (org.apache.cxf.rt.security.claims.ClaimCollection)30 ClaimsParameters (org.apache.cxf.sts.claims.ClaimsParameters)29 Claim (org.apache.cxf.rt.security.claims.Claim)21 URI (java.net.URI)18 Principal (java.security.Principal)15 ClaimsManager (org.apache.cxf.sts.claims.ClaimsManager)14 CustomTokenPrincipal (org.apache.wss4j.common.principal.CustomTokenPrincipal)14 ArrayList (java.util.ArrayList)13 HashMap (java.util.HashMap)5 ClaimsHandler (org.apache.cxf.sts.claims.ClaimsHandler)5 LdapClaimsHandler (org.apache.cxf.sts.claims.LdapClaimsHandler)5 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)5 URISyntaxException (java.net.URISyntaxException)4 List (java.util.List)4 X500Principal (javax.security.auth.x500.X500Principal)4 LdapGroupClaimsHandler (org.apache.cxf.sts.claims.LdapGroupClaimsHandler)4 RealmSupportClaimsHandler (org.apache.cxf.sts.common.RealmSupportClaimsHandler)4