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