Search in sources :

Example 51 with ProcessedClaimCollection

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

the class ClaimUtils method updateIssuer.

/**
 * All claims within the provided collection will be updated in the following manner: If no original
 * issuer is set, the issuer in the provided claims will be set as original issuer. If an original issuer
 * was already set before, the original issuer will not be updated. All claims will be updated to have the
 * provided issuer name be set as the claim issuer.
 *
 * @param processedClaims Collection of claims to be updated
 * @param issuerName Issuer to be set for all claims within the collection
 * @return Returns a new claim collection with clones of updated claims
 */
public ProcessedClaimCollection updateIssuer(ProcessedClaimCollection processedClaims, String newIssuer) {
    ProcessedClaimCollection resultClaimCollection = null;
    if (processedClaims != null) {
        resultClaimCollection = new ProcessedClaimCollection();
        for (ProcessedClaim c : processedClaims) {
            ProcessedClaim newClaim = c.clone();
            if (newClaim.getOriginalIssuer() == null) {
                newClaim.setOriginalIssuer(newClaim.getIssuer());
            }
            newClaim.setIssuer(newIssuer);
            resultClaimCollection.add(newClaim);
        }
    }
    return resultClaimCollection;
}
Also used : ProcessedClaimCollection(org.apache.cxf.sts.claims.ProcessedClaimCollection) ProcessedClaim(org.apache.cxf.sts.claims.ProcessedClaim)

Example 52 with ProcessedClaimCollection

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

the class JexlClaimsMapper method mapClaims.

public ProcessedClaimCollection mapClaims(String sourceRealm, ProcessedClaimCollection sourceClaims, String targetRealm, ClaimsParameters parameters) {
    JexlContext context = new MapContext();
    context.set("sourceClaims", sourceClaims);
    context.set("targetClaims", new ProcessedClaimCollection());
    context.set("sourceRealm", sourceRealm);
    context.set("targetRealm", targetRealm);
    context.set("claimsParameters", parameters);
    Script s = getScript();
    if (s == null) {
        LOG.warning("No claim mapping script defined");
        // TODO Check if null or an exception would be more
        return new ProcessedClaimCollection();
    // appropriate
    }
    return (ProcessedClaimCollection) s.execute(context);
}
Also used : Script(org.apache.commons.jexl2.Script) ProcessedClaimCollection(org.apache.cxf.sts.claims.ProcessedClaimCollection) JexlContext(org.apache.commons.jexl2.JexlContext) MapContext(org.apache.commons.jexl2.MapContext)

Example 53 with ProcessedClaimCollection

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

the class DefaultJWTClaimsProvider method handleWSTrustClaims.

protected void handleWSTrustClaims(JWTClaimsProviderParameters jwtClaimsProviderParameters, JwtClaims claims) {
    TokenProviderParameters providerParameters = jwtClaimsProviderParameters.getProviderParameters();
    // Handle Claims
    ProcessedClaimCollection retrievedClaims = ClaimsUtils.processClaims(providerParameters);
    if (retrievedClaims != null) {
        Iterator<ProcessedClaim> claimIterator = retrievedClaims.iterator();
        while (claimIterator.hasNext()) {
            ProcessedClaim claim = claimIterator.next();
            if (claim.getClaimType() != null && claim.getValues() != null && !claim.getValues().isEmpty()) {
                Object claimValues = claim.getValues();
                if (claim.getValues().size() == 1) {
                    claimValues = claim.getValues().get(0);
                }
                claims.setProperty(translateClaim(claim.getClaimType().toString()), claimValues);
            }
        }
    }
}
Also used : ProcessedClaimCollection(org.apache.cxf.sts.claims.ProcessedClaimCollection) ProcessedClaim(org.apache.cxf.sts.claims.ProcessedClaim) TokenProviderParameters(org.apache.cxf.sts.token.provider.TokenProviderParameters)

Example 54 with ProcessedClaimCollection

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

the class JexlClaimsMapperTest method testMultiToSingleValue.

@Test
public void testMultiToSingleValue() throws IOException {
    ProcessedClaimCollection result = jcm.mapClaims("A", createClaimCollection(), "B", createProperties());
    assertNotNull(result);
    ProcessedClaim claim = findClaim(result, "http://my.schema.org/identity/claims/multi2single");
    assertNotNull(claim);
    assertNotNull(claim.getValues());
    assertEquals(1, claim.getValues().size());
    assertEquals("Value1,Value2,Value3", claim.getValues().get(0));
}
Also used : ProcessedClaimCollection(org.apache.cxf.sts.claims.ProcessedClaimCollection) ProcessedClaim(org.apache.cxf.sts.claims.ProcessedClaim) Test(org.junit.Test)

Example 55 with ProcessedClaimCollection

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

the class JexlClaimsMapperTest method testLowerCaseClaim.

@Test
public void testLowerCaseClaim() throws IOException {
    ProcessedClaimCollection result = jcm.mapClaims("A", createClaimCollection(), "B", createProperties());
    assertNotNull(result);
    ProcessedClaim claim = findClaim(result, "http://my.schema.org/identity/claims/lowercase");
    assertNotNull(claim);
    assertNotNull(claim.getValues());
    assertEquals(2, claim.getValues().size());
    assertEquals("value2", claim.getValues().get(1));
}
Also used : ProcessedClaimCollection(org.apache.cxf.sts.claims.ProcessedClaimCollection) ProcessedClaim(org.apache.cxf.sts.claims.ProcessedClaim) Test(org.junit.Test)

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