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;
}
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;
}
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;
}
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);
}
}
}
}
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));
}
Aggregations