Search in sources :

Example 1 with ProcessedClaimCollection

use of org.apache.cxf.sts.claims.ProcessedClaimCollection in project cas by apereo.

the class WrappingSecurityTokenServiceClaimsHandler method retrieveClaimValues.

@Override
public ProcessedClaimCollection retrieveClaimValues(final ClaimCollection claims, final ClaimsParameters parameters) {
    if (parameters.getRealm() == null || !parameters.getRealm().equalsIgnoreCase(this.realm)) {
        LOGGER.warn("Realm [{}] doesn't match with configured realm [{}]", parameters.getRealm(), this.realm);
        return new ProcessedClaimCollection();
    }
    if (parameters.getPrincipal() == null) {
        LOGGER.warn("No principal could be identified in the claim parameters request");
        return new ProcessedClaimCollection();
    }
    if (claims == null || claims.isEmpty()) {
        LOGGER.warn("No claims are available to process");
        return new ProcessedClaimCollection();
    }
    final ProcessedClaimCollection claimCollection = new ProcessedClaimCollection();
    claims.stream().map(requestClaim -> {
        final ProcessedClaim claim = new ProcessedClaim();
        claim.setClaimType(requestClaim.getClaimType());
        claim.setIssuer(this.issuer);
        claim.setOriginalIssuer(this.issuer);
        claim.setValues(requestClaim.getValues());
        return claim;
    }).forEach(claimCollection::add);
    return claimCollection;
}
Also used : ClaimsHandler(org.apache.cxf.sts.claims.ClaimsHandler) Arrays(java.util.Arrays) Logger(org.slf4j.Logger) ClaimsParameters(org.apache.cxf.sts.claims.ClaimsParameters) LoggerFactory(org.slf4j.LoggerFactory) Collectors(java.util.stream.Collectors) RealmSupport(org.apache.cxf.sts.token.realm.RealmSupport) WSFederationClaims(org.apereo.cas.ws.idp.WSFederationClaims) List(java.util.List) ClaimCollection(org.apache.cxf.rt.security.claims.ClaimCollection) UriBuilder(javax.ws.rs.core.UriBuilder) URI(java.net.URI) ProcessedClaimCollection(org.apache.cxf.sts.claims.ProcessedClaimCollection) ProcessedClaim(org.apache.cxf.sts.claims.ProcessedClaim) ProcessedClaimCollection(org.apache.cxf.sts.claims.ProcessedClaimCollection) ProcessedClaim(org.apache.cxf.sts.claims.ProcessedClaim)

Example 2 with ProcessedClaimCollection

use of org.apache.cxf.sts.claims.ProcessedClaimCollection in project ddf by codice.

the class AttributeFileClaimsHandler method retrieveClaimValues.

@Override
public ProcessedClaimCollection retrieveClaimValues(ClaimCollection claimCollection, ClaimsParameters claimsParameters) {
    ProcessedClaimCollection claimsColl = new ProcessedClaimCollection();
    Principal principal = claimsParameters.getPrincipal();
    if (principal == null) {
        return claimsColl;
    }
    String name;
    if (principal instanceof X500Principal) {
        name = SubjectUtils.getCommonName((X500Principal) principal);
    } else {
        name = principal.getName();
    }
    Object user = json.get(name);
    Map userMap = null;
    if (user != null) {
        if (user instanceof Map) {
            userMap = (Map) user;
        }
    } else {
        Set<Map.Entry<String, Object>> entries = json.entrySet();
        for (Map.Entry<String, Object> entry : entries) {
            String key = entry.getKey();
            Pattern pattern = Pattern.compile(key);
            Matcher matcher = pattern.matcher(principal.getName());
            if (matcher.matches()) {
                userMap = (Map) entry.getValue();
                break;
            }
        }
    }
    if (userMap == null) {
        return claimsColl;
    }
    for (Claim claim : claimCollection) {
        Object attributeValue = userMap.get(claim.getClaimType().toString());
        ProcessedClaim c = new ProcessedClaim();
        c.setClaimType(claim.getClaimType());
        c.setPrincipal(principal);
        if (attributeValue instanceof List) {
            ((List) attributeValue).forEach(c::addValue);
            claimsColl.add(c);
        } else if (attributeValue instanceof String) {
            c.addValue(attributeValue);
            claimsColl.add(c);
        }
    }
    return claimsColl;
}
Also used : Pattern(java.util.regex.Pattern) ProcessedClaimCollection(org.apache.cxf.sts.claims.ProcessedClaimCollection) Matcher(java.util.regex.Matcher) ProcessedClaim(org.apache.cxf.sts.claims.ProcessedClaim) X500Principal(javax.security.auth.x500.X500Principal) ArrayList(java.util.ArrayList) List(java.util.List) Map(java.util.Map) X500Principal(javax.security.auth.x500.X500Principal) Principal(java.security.Principal) ProcessedClaim(org.apache.cxf.sts.claims.ProcessedClaim) Claim(org.apache.cxf.rt.security.claims.Claim)

Example 3 with ProcessedClaimCollection

use of org.apache.cxf.sts.claims.ProcessedClaimCollection in project ddf by codice.

the class TestAttributeFileClaimsHandler method testRetrieveClaimValuesRegex.

@Test
public void testRetrieveClaimValuesRegex() {
    ProcessedClaimCollection processedClaims = attributeFileClaimsHandler.retrieveClaimValues(claimCollection, regexClaimsParameters);
    assertThat(processedClaims.size(), is(1));
    assertThat(processedClaims.get(0).getClaimType().toString(), is("reg"));
    assertThat(processedClaims.get(0).getValues().get(0), is("ex"));
}
Also used : ProcessedClaimCollection(org.apache.cxf.sts.claims.ProcessedClaimCollection) Test(org.junit.Test)

Example 4 with ProcessedClaimCollection

use of org.apache.cxf.sts.claims.ProcessedClaimCollection in project ddf by codice.

the class TestAttributeFileClaimsHandler method testRetrieveClaimValuesLocalhost.

@Test
public void testRetrieveClaimValuesLocalhost() {
    ProcessedClaimCollection processedClaims = attributeFileClaimsHandler.retrieveClaimValues(claimCollection, localhostClaimsParameters);
    assertThat(processedClaims.size(), is(0));
}
Also used : ProcessedClaimCollection(org.apache.cxf.sts.claims.ProcessedClaimCollection) Test(org.junit.Test)

Example 5 with ProcessedClaimCollection

use of org.apache.cxf.sts.claims.ProcessedClaimCollection in project ddf by codice.

the class TestAttributeFileClaimsHandler method testRetrieveClaimsValuesNullPrincipal.

@Test
public void testRetrieveClaimsValuesNullPrincipal() {
    ClaimsParameters claimsParameters = new ClaimsParameters();
    ClaimCollection claimCollection = new ClaimCollection();
    ProcessedClaimCollection processedClaims = attributeFileClaimsHandler.retrieveClaimValues(claimCollection, claimsParameters);
    Assert.assertThat(processedClaims.size(), CoreMatchers.is(equalTo(0)));
}
Also used : ProcessedClaimCollection(org.apache.cxf.sts.claims.ProcessedClaimCollection) ClaimCollection(org.apache.cxf.rt.security.claims.ClaimCollection) ProcessedClaimCollection(org.apache.cxf.sts.claims.ProcessedClaimCollection) ClaimsParameters(org.apache.cxf.sts.claims.ClaimsParameters) Test(org.junit.Test)

Aggregations

ProcessedClaimCollection (org.apache.cxf.sts.claims.ProcessedClaimCollection)31 Test (org.junit.Test)21 ClaimCollection (org.apache.cxf.rt.security.claims.ClaimCollection)17 Principal (java.security.Principal)15 ClaimsParameters (org.apache.cxf.sts.claims.ClaimsParameters)15 Claim (org.apache.cxf.rt.security.claims.Claim)10 ProcessedClaim (org.apache.cxf.sts.claims.ProcessedClaim)10 URI (java.net.URI)8 HashMap (java.util.HashMap)5 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)5 URISyntaxException (java.net.URISyntaxException)4 X500Principal (javax.security.auth.x500.X500Principal)4 List (java.util.List)3 Connection (org.forgerock.opendj.ldap.Connection)3 BindResult (org.forgerock.opendj.ldap.responses.BindResult)3 SearchResultEntry (org.forgerock.opendj.ldap.responses.SearchResultEntry)3 ConnectionEntryReader (org.forgerock.opendj.ldif.ConnectionEntryReader)3 GuestPrincipal (ddf.security.principal.GuestPrincipal)2 ArrayList (java.util.ArrayList)2 KerberosPrincipal (javax.security.auth.kerberos.KerberosPrincipal)2