Search in sources :

Example 6 with ProcessedClaimCollection

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

the class CertificateClaimsHandlerTest method testRetrieveClaimValuesWithEmail.

@Test
public void testRetrieveClaimValuesWithEmail() throws URISyntaxException {
    CertificateClaimsHandler certificateClaimsHandler = new CertificateClaimsHandler();
    ClaimCollection claims = getClaims();
    ClaimsParameters parameters = new ClaimsParameters();
    parameters.setPrincipal(mock(Principal.class));
    Map<String, Object> map = new HashMap<>();
    map.put(SubjectUtils.EMAIL_ADDRESS_CLAIM_URI, "local@localhost");
    parameters.setAdditionalProperties(map);
    ProcessedClaimCollection processedClaims = certificateClaimsHandler.retrieveClaimValues(claims, parameters);
    assertThat(processedClaims.size(), is(1));
    assertThat(processedClaims.stream().map(c -> c.getClaimType().toString()).collect(Collectors.toList()), containsInAnyOrder(SubjectUtils.EMAIL_ADDRESS_CLAIM_URI));
}
Also used : ProcessedClaimCollection(org.apache.cxf.sts.claims.ProcessedClaimCollection) HashMap(java.util.HashMap) ClaimCollection(org.apache.cxf.rt.security.claims.ClaimCollection) ProcessedClaimCollection(org.apache.cxf.sts.claims.ProcessedClaimCollection) Principal(java.security.Principal) ClaimsParameters(org.apache.cxf.sts.claims.ClaimsParameters) Test(org.junit.Test)

Example 7 with ProcessedClaimCollection

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

the class LdapClaimsHandlerTest method testRetrieveClaimsValues.

@Test
public void testRetrieveClaimsValues() throws URISyntaxException {
    when(mockBindResult.isSuccess()).thenReturn(true);
    ProcessedClaimCollection processedClaims = claimsHandler.retrieveClaimValues(claims, claimsParameters);
    assertThat(processedClaims, hasSize(1));
    Claim claim = processedClaims.get(0);
    assertThat(claim.getValues(), contains(DUMMY_VALUE));
}
Also used : ProcessedClaimCollection(org.apache.cxf.sts.claims.ProcessedClaimCollection) Claim(org.apache.cxf.rt.security.claims.Claim) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 8 with ProcessedClaimCollection

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

the class LdapClaimsHandlerTest method testRetrieveClaimsValuesNullPrincipal.

@Test
public void testRetrieveClaimsValuesNullPrincipal() {
    when(mockBindResult.isSuccess()).thenReturn(false);
    ProcessedClaimCollection processedClaims = claimsHandler.retrieveClaimValues(new ClaimCollection(), claimsParameters);
    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) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 9 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 10 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)

Aggregations

ProcessedClaimCollection (org.apache.cxf.sts.claims.ProcessedClaimCollection)68 ProcessedClaim (org.apache.cxf.sts.claims.ProcessedClaim)40 Test (org.junit.Test)32 ClaimCollection (org.apache.cxf.rt.security.claims.ClaimCollection)30 ClaimsParameters (org.apache.cxf.sts.claims.ClaimsParameters)29 Claim (org.apache.cxf.rt.security.claims.Claim)21 URI (java.net.URI)18 Principal (java.security.Principal)15 ClaimsManager (org.apache.cxf.sts.claims.ClaimsManager)14 CustomTokenPrincipal (org.apache.wss4j.common.principal.CustomTokenPrincipal)14 ArrayList (java.util.ArrayList)13 HashMap (java.util.HashMap)5 ClaimsHandler (org.apache.cxf.sts.claims.ClaimsHandler)5 LdapClaimsHandler (org.apache.cxf.sts.claims.LdapClaimsHandler)5 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)5 URISyntaxException (java.net.URISyntaxException)4 List (java.util.List)4 X500Principal (javax.security.auth.x500.X500Principal)4 LdapGroupClaimsHandler (org.apache.cxf.sts.claims.LdapGroupClaimsHandler)4 RealmSupportClaimsHandler (org.apache.cxf.sts.common.RealmSupportClaimsHandler)4