Search in sources :

Example 26 with ProcessedClaim

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

the class AttributeQueryClaimsHandler method createSingleValuedClaim.

/**
     * Creates a single valued claim.
     *
     * @param claimType  The claim type.
     * @param claimValue The claim value.
     * @return The claim.
     * @throws URISyntaxException
     */
protected ProcessedClaim createSingleValuedClaim(String claimType, String claimValue) throws URISyntaxException {
    ProcessedClaim claim = new ProcessedClaim();
    claim.setClaimType(new URI(claimType));
    claim.setValues(ImmutableList.<Object>of(claimValue));
    LOGGER.debug("Created claim with type [{}] and value [{}].", claimType, claimValue);
    return claim;
}
Also used : ProcessedClaim(org.apache.cxf.sts.claims.ProcessedClaim) URI(java.net.URI)

Example 27 with ProcessedClaim

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

the class CertificateClaimsHandler method buildClaim.

private void buildClaim(ProcessedClaimCollection claimsColl, Principal principal, URI claimType, Object value) {
    if (value == null) {
        return;
    }
    ProcessedClaim c = new ProcessedClaim();
    c.setClaimType(claimType);
    c.setPrincipal(principal);
    c.addValue(value);
    claimsColl.add(c);
}
Also used : ProcessedClaim(org.apache.cxf.sts.claims.ProcessedClaim)

Example 28 with ProcessedClaim

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

the class ClaimUtils method filterValues.

/**
 * Filtering all values from the given claim according to the provided regex filter. Input claims will not
 * be modified. Result claim will be a clone of the provided claims just possible fewer (filtered) claim
 * values.
 *
 * @param processedClaim Claim containing arbitrary values
 * @param filter Regex filter to be used to match with claim values
 * @return Returns a claim containing only values from the processedClaim which matched the provided
 *         filter
 */
public ProcessedClaim filterValues(ProcessedClaim processedClaim, String filter) {
    ProcessedClaim resultClaim = null;
    if (processedClaim != null) {
        resultClaim = processedClaim.clone();
        List<Object> values = resultClaim.getValues();
        List<Object> filteredValues = new ArrayList<>();
        if (values == null || filter == null) {
            resultClaim.setValues(filteredValues);
            return resultClaim;
        }
        for (Object value : values) {
            if (value != null && value.toString().matches(filter)) {
                filteredValues.add(value);
            }
        }
        resultClaim.setValues(filteredValues);
    }
    return resultClaim;
}
Also used : ProcessedClaim(org.apache.cxf.sts.claims.ProcessedClaim) ArrayList(java.util.ArrayList)

Example 29 with ProcessedClaim

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

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

the class ClaimUtils method merge.

/**
 * Merges the first value (only) from different claim types in a collection to a new claim type separated
 * by the provided delimiter.
 *
 * @param processedClaims Collection of claims containing claims with claim types of listed
 *            <code>claimType</code> array
 * @param targetClaimType claim type URI of merged result claim
 * @param delimiter Delimiter added between multiple claim types. Value can be <code>null</code>.
 * @param processedClaimType URIs of claim types to be merged. Merging will be in the same order as the
 *            provided claim type URIs. If a claim type is not found in the collection this claim type
 *            will be omitted.
 * @return Returns merged claim of all found claim types
 */
public ProcessedClaim merge(ProcessedClaimCollection processedClaims, String targetClaimType, String delimiter, String... processedClaimType) {
    ProcessedClaim mergedProcessedClaim = null;
    StringBuilder sbProcessedClaimValue = new StringBuilder();
    for (String sc : processedClaimType) {
        ProcessedClaim c = get(processedClaims, sc);
        if (c != null) {
            List<Object> values = c.getValues();
            if (values != null && !values.isEmpty()) {
                if (mergedProcessedClaim == null) {
                    // First match TODO refactor for better method override
                    mergedProcessedClaim = c.clone();
                    sbProcessedClaimValue.append(values.get(0));
                    mergedProcessedClaim.getValues().clear();
                } else {
                    sbProcessedClaimValue.append(delimiter).append(values.get(0));
                }
            }
        }
    }
    if (mergedProcessedClaim != null) {
        mergedProcessedClaim.setClaimType(URI.create(targetClaimType));
        mergedProcessedClaim.addValue(sbProcessedClaimValue.toString());
    }
    return mergedProcessedClaim;
}
Also used : ProcessedClaim(org.apache.cxf.sts.claims.ProcessedClaim)

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