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