Search in sources :

Example 31 with ProcessedClaim

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

the class ClaimUtils method upperCaseValues.

/**
 * @param processedClaim values of this claim will be used for result claim
 * @return Returns clone of the provided claim with values all in uppercase format
 */
public ProcessedClaim upperCaseValues(ProcessedClaim processedClaim) {
    ProcessedClaim resultClaim = null;
    if (processedClaim != null) {
        resultClaim = processedClaim.clone();
        if (resultClaim.getValues() != null) {
            List<Object> oldValues = resultClaim.getValues();
            List<Object> newValues = new ArrayList<>();
            for (Object value : oldValues) {
                newValues.add(value.toString().toUpperCase());
            }
            resultClaim.getValues().clear();
            resultClaim.getValues().addAll(newValues);
        }
    }
    return resultClaim;
}
Also used : ProcessedClaim(org.apache.cxf.sts.claims.ProcessedClaim) ArrayList(java.util.ArrayList)

Example 32 with ProcessedClaim

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

the class ClaimUtils method mapValues.

/**
 * Mapping all values from the given claim according to the provided map. Input claims will not be
 * modified. Result claim will be a clone of the provided claims just with different (mapped) claim
 * values.
 *
 * @param processedClaim Claim providing values to be mapped
 * @param map Map of old:new mapping values
 * @param keepUnmapped if set to false only values contained in the map will be returned. If set to true,
 *            values not contained in the map will also remain in the returned claim.
 * @return Returns the provided claim with mapped values
 */
public ProcessedClaim mapValues(ProcessedClaim processedClaim, Map<Object, Object> mapping, boolean keepUnmapped) {
    ProcessedClaim resultClaim = null;
    if (processedClaim != null) {
        resultClaim = processedClaim.clone();
        List<Object> values = resultClaim.getValues();
        List<Object> mappedValues = new ArrayList<>();
        if (values == null || mapping == null || mapping.isEmpty()) {
            resultClaim.setValues(mappedValues);
            return resultClaim;
        }
        for (Object value : values) {
            Object newValue = mapping.get(value);
            if (newValue != null) {
                mappedValues.add(newValue);
            } else if (keepUnmapped) {
                mappedValues.add(value);
            }
        }
        resultClaim.setValues(mappedValues);
    }
    return resultClaim;
}
Also used : ProcessedClaim(org.apache.cxf.sts.claims.ProcessedClaim) ArrayList(java.util.ArrayList)

Example 33 with ProcessedClaim

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

the class ClaimUtils method singleToMultiValue.

/**
 * This function is especially useful if multi values from a claim are stored within a single value entry.
 * For example multi user roles could all be stored in a single value element separated by comma:
 * USER,MANAGER,ADMIN The result of this function will provide a claim with three distinct values: USER
 * and MANAGER and ADMIN.
 *
 * @param processedClaim claim containing multi-values in a single value entry
 * @param delimiter Delimiter to split multi-values into single values
 * @return Returns a clone of the provided claim containing only single values per value entry
 */
public ProcessedClaim singleToMultiValue(ProcessedClaim processedClaim, String delimiter) {
    ProcessedClaim resultClaim = null;
    if (processedClaim != null) {
        resultClaim = processedClaim.clone();
        if (resultClaim.getValues() != null) {
            List<Object> oldValues = resultClaim.getValues();
            List<Object> newValues = new ArrayList<>();
            for (Object value : oldValues) {
                String multivalue = value.toString();
                StringTokenizer st = new StringTokenizer(multivalue, delimiter);
                while (st.hasMoreTokens()) {
                    newValues.add(st.nextToken());
                }
            }
            resultClaim.getValues().clear();
            resultClaim.getValues().addAll(newValues);
        }
    }
    return resultClaim;
}
Also used : StringTokenizer(java.util.StringTokenizer) ProcessedClaim(org.apache.cxf.sts.claims.ProcessedClaim) ArrayList(java.util.ArrayList)

Example 34 with ProcessedClaim

use of org.apache.cxf.sts.claims.ProcessedClaim 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 35 with ProcessedClaim

use of org.apache.cxf.sts.claims.ProcessedClaim 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)

Aggregations

ProcessedClaim (org.apache.cxf.sts.claims.ProcessedClaim)46 ProcessedClaimCollection (org.apache.cxf.sts.claims.ProcessedClaimCollection)35 ArrayList (java.util.ArrayList)15 Claim (org.apache.cxf.rt.security.claims.Claim)12 Test (org.junit.Test)12 URI (java.net.URI)11 ClaimsParameters (org.apache.cxf.sts.claims.ClaimsParameters)9 ClaimCollection (org.apache.cxf.rt.security.claims.ClaimCollection)8 ClaimsManager (org.apache.cxf.sts.claims.ClaimsManager)6 CustomTokenPrincipal (org.apache.wss4j.common.principal.CustomTokenPrincipal)6 Principal (java.security.Principal)5 LdapClaimsHandler (org.apache.cxf.sts.claims.LdapClaimsHandler)5 List (java.util.List)4 X500Principal (javax.security.auth.x500.X500Principal)3 Connection (org.forgerock.opendj.ldap.Connection)3 BindResult (org.forgerock.opendj.ldap.responses.BindResult)3 SearchResultEntry (org.forgerock.opendj.ldap.responses.SearchResultEntry)3 ConnectionEntryReader (org.forgerock.opendj.ldif.ConnectionEntryReader)3 GuestPrincipal (ddf.security.principal.GuestPrincipal)2 AttributeBean (org.apache.wss4j.common.saml.bean.AttributeBean)2