Class ClaimUtils


  • public class ClaimUtils
    extends Object
    This claim util class provides methods to make the handling of claims and claim values easier. The input claims (and their values) shall be treated as immutable. All util methods return a clone of the provided claim containing the desired claim update.
    • Constructor Detail

      • ClaimUtils

        public ClaimUtils()
    • Method Detail

      • add

        public ProcessedClaimCollection add​(ProcessedClaimCollection collection,
                                            ProcessedClaim... claims)
        Parameters:
        collection - Collection that should be used to add further claims to
        claims - Claims to be added to the provided collection
        Returns:
        Returns clone of the provided collection including additional claims
      • add

        public ProcessedClaimCollection add​(ProcessedClaimCollection collection,
                                            ProcessedClaimCollection... claimCollections)
        Parameters:
        collection - Collection that should be used to add claims from the other provided claim collections
        claimCollections - All claims contained within the provided collections will be added to the targetCollection
        Returns:
        Returns a clone of the provided collection containing all claims from all other claimCollections
      • create

        public ProcessedClaim create​(String processedClaimTypeURI,
                                     String... values)
        Parameters:
        processedClaimTypeURI - claim type URI
        values - values of created claim. Can be null if no values shall be added to claim.
        Returns:
        Returns new claim with provided claim type and values
      • get

        public ProcessedClaim get​(ProcessedClaimCollection processedClaims,
                                  String processedClaimType)
        Parameters:
        processedClaims - Collection of multiple claims with different claim types
        processedClaimType - URI of claim type to be selected from claim collection
        Returns:
        Returns first claim from claims collection matching the provided claimType
      • mapType

        public ProcessedClaimCollection mapType​(ProcessedClaimCollection processedClaims,
                                                Map<String,​String> map,
                                                boolean keepUnmapped)
        Parameters:
        processedClaims - Collection of claims to be mapped to a different claim type
        map - Map of old:new claim types
        keepUnmapped - if set to false only claims with a claim type contained in the map will be returned. If set to false claims with an unmapped claim type will also be returned.
        Returns:
        Returns claim collection with mapped claim types
      • mapValues

        public ProcessedClaim mapValues​(ProcessedClaim processedClaim,
                                        Map<Object,​Object> mapping,
                                        boolean keepUnmapped)
        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.
        Parameters:
        processedClaim - Claim providing values to be mapped
        mapping - Map of old:new mapping values
        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.
        Returns:
        Returns the provided claim with mapped values
      • filterValues

        public ProcessedClaim filterValues​(ProcessedClaim processedClaim,
                                           String filter)
        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.
        Parameters:
        processedClaim - Claim containing arbitrary values
        filter - Regex filter to be used to match with claim values
        Returns:
        Returns a claim containing only values from the processedClaim which matched the provided filter
      • merge

        public ProcessedClaim merge​(ProcessedClaimCollection processedClaims,
                                    String targetClaimType,
                                    String delimiter,
                                    String... processedClaimType)
        Merges the first value (only) from different claim types in a collection to a new claim type separated by the provided delimiter.
        Parameters:
        processedClaims - Collection of claims containing claims with claim types of listed claimType array
        targetClaimType - claim type URI of merged result claim
        delimiter - Delimiter added between multiple claim types. Value can be null.
        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.
        Returns:
        Returns merged claim of all found claim types
      • setType

        public ProcessedClaim setType​(ProcessedClaim processedClaim,
                                      String processedClaimTypeURI)
        Parameters:
        processedClaim - Claim to be updated
        processedClaimTypeURI - URI as String to be set as claim type in provided claim
        Returns:
        Returns updated claim
      • updateIssuer

        public ProcessedClaimCollection updateIssuer​(ProcessedClaimCollection processedClaims,
                                                     String newIssuer)
        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.
        Parameters:
        processedClaims - Collection of claims to be updated
        newIssuer - Issuer to be set for all claims within the collection
        Returns:
        Returns a new claim collection with clones of updated claims
      • upperCaseValues

        public ProcessedClaim upperCaseValues​(ProcessedClaim processedClaim)
        Parameters:
        processedClaim - values of this claim will be used for result claim
        Returns:
        Returns clone of the provided claim with values all in uppercase format
      • lowerCaseValues

        public ProcessedClaim lowerCaseValues​(ProcessedClaim processedClaim)
        Parameters:
        processedClaim - values of this claim will be used for result claim
        Returns:
        Returns clone of provided claim with values all in lowercase format
      • wrapValues

        public ProcessedClaim wrapValues​(ProcessedClaim processedClaim,
                                         String prefix,
                                         String suffix)
        Parameters:
        processedClaim - Claim providing values to be wrapped
        prefix - Prefix to be added to each claim value. Can be null.
        suffix - Suffix to be appended to each claim value. Can be null.
        Returns:
        Returns a clone of the the provided claim with wrapped values
      • singleToMultiValue

        public ProcessedClaim singleToMultiValue​(ProcessedClaim processedClaim,
                                                 String delimiter)
        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.
        Parameters:
        processedClaim - claim containing multi-values in a single value entry
        delimiter - Delimiter to split multi-values into single values
        Returns:
        Returns a clone of the provided claim containing only single values per value entry
      • multiToSingleValue

        public ProcessedClaim multiToSingleValue​(ProcessedClaim processedClaim,
                                                 String delimiter)
        This function is especially useful if values from multiple claim values need to be condensed into a single value element. For example a user has three roles: USER and MANAGER and ADMIN. If ',' is used as a delimiter, then this method would provide the following claim with only a single value looking like this: USER,MANAGER,ADMIN
        Parameters:
        processedClaim - claim containing multi-values
        delimiter - Delimiter to concatenate multi-values into a single value
        Returns:
        Returns a clone of the provided claim containing only one single value
      • distinctValues

        public ProcessedClaim distinctValues​(ProcessedClaim processedClaim)
        This function removes duplicated values.
        Parameters:
        processedClaim - claim containing multi-values of which some might be duplicated
        Returns:
        Returns a clone of the provided claim containing only distinct values
      • removeEmptyClaims

        public ProcessedClaimCollection removeEmptyClaims​(ProcessedClaimCollection processedClaims)
        Removes Claims without values.
        Parameters:
        processedClaims - Collection of claims with and/or without values
        Returns:
        Returns a collection of claims which contain values only