Search in sources :

Example 56 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 57 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)

Aggregations

ProcessedClaim (org.apache.cxf.sts.claims.ProcessedClaim)57 ProcessedClaimCollection (org.apache.cxf.sts.claims.ProcessedClaimCollection)44 Claim (org.apache.cxf.rt.security.claims.Claim)22 ArrayList (java.util.ArrayList)20 ClaimsParameters (org.apache.cxf.sts.claims.ClaimsParameters)14 ClaimCollection (org.apache.cxf.rt.security.claims.ClaimCollection)13 ClaimsManager (org.apache.cxf.sts.claims.ClaimsManager)11 CustomTokenPrincipal (org.apache.wss4j.common.principal.CustomTokenPrincipal)11 Test (org.junit.Test)11 LdapClaimsHandler (org.apache.cxf.sts.claims.LdapClaimsHandler)10 URI (java.net.URI)9 Principal (java.security.Principal)8 List (java.util.List)3 X500Principal (javax.security.auth.x500.X500Principal)3 lombok.val (lombok.val)3 TokenRequirements (org.apache.cxf.sts.request.TokenRequirements)3 GuestPrincipal (ddf.security.principal.GuestPrincipal)2 ByteArrayInputStream (java.io.ByteArrayInputStream)2 InputStream (java.io.InputStream)2 URISyntaxException (java.net.URISyntaxException)2