Search in sources :

Example 6 with ClaimsParameters

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

the class CertificateClaimsHandlerTest method testRetrieveClaimValuesNoCertValues.

@Test
public void testRetrieveClaimValuesNoCertValues() throws URISyntaxException {
    CertificateClaimsHandler certificateClaimsHandler = new CertificateClaimsHandler();
    ClaimCollection claims = getClaims();
    ClaimsParameters parameters = new ClaimsParameters();
    parameters.setPrincipal(mock(Principal.class));
    ProcessedClaimCollection processedClaims = certificateClaimsHandler.retrieveClaimValues(claims, parameters);
    assertThat(processedClaims.size(), is(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) Principal(java.security.Principal) ClaimsParameters(org.apache.cxf.sts.claims.ClaimsParameters) Test(org.junit.Test)

Example 7 with ClaimsParameters

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

the class CertificateClaimsHandlerTest method testRetrieveClaimValuesWithAltNamesRequested.

@Test
public void testRetrieveClaimValuesWithAltNamesRequested() throws URISyntaxException {
    CertificateClaimsHandler certificateClaimsHandler = new CertificateClaimsHandler();
    certificateClaimsHandler.setCountryClaim("Country");
    certificateClaimsHandler.setEmailClaim("Email");
    ClaimCollection claims = new ClaimCollection();
    Claim claim = new Claim();
    claim.setClaimType(new URI("Country"));
    claims.add(claim);
    Claim claim1 = new Claim();
    claim1.setClaimType(new URI("Email"));
    claims.add(claim1);
    ClaimsParameters parameters = new ClaimsParameters();
    parameters.setPrincipal(mock(Principal.class));
    Map<String, Object> map = new HashMap<>();
    map.put(SubjectUtils.EMAIL_ADDRESS_CLAIM_URI, "local@localhost");
    map.put(SubjectUtils.COUNTRY_CLAIM_URI, "USA");
    parameters.setAdditionalProperties(map);
    ProcessedClaimCollection processedClaims = certificateClaimsHandler.retrieveClaimValues(claims, parameters);
    assertThat(processedClaims.size(), is(2));
    assertThat(processedClaims.stream().map(c -> c.getClaimType().toString()).collect(Collectors.toList()), containsInAnyOrder("Email", "Country"));
}
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) URI(java.net.URI) Claim(org.apache.cxf.rt.security.claims.Claim) Principal(java.security.Principal) ClaimsParameters(org.apache.cxf.sts.claims.ClaimsParameters) Test(org.junit.Test)

Example 8 with ClaimsParameters

use of org.apache.cxf.sts.claims.ClaimsParameters 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 9 with ClaimsParameters

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

the class TestAttributeQueryClaimsHandler method testRetrieveClaimsValuesNullPrincipal.

@Test
public void testRetrieveClaimsValuesNullPrincipal() {
    ClaimsParameters claimsParameters = mock(ClaimsParameters.class);
    when(claimsParameters.getPrincipal()).thenReturn(null);
    ClaimCollection claimCollection = new ClaimCollection();
    ProcessedClaimCollection processedClaims = spyAttributeQueryClaimsHandler.retrieveClaimValues(claimCollection, claimsParameters);
    assertThat(processedClaims.size(), 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)

Example 10 with ClaimsParameters

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

the class TestAttributeQueryClaimsHandler method retrieveClaimValues.

private ProcessedClaimCollection retrieveClaimValues() {
    ClaimCollection claimCollection = new ClaimCollection();
    Claim claim = new Claim();
    try {
        claim.setClaimType(new URI("http://schemas.xmlsoap.org/ws/2005/05/identity/claims/nameidentifier"));
    } catch (URISyntaxException e) {
        fail("Could not create URI.");
    }
    claimCollection.add(claim);
    ClaimsParameters claimsParameters = mock(ClaimsParameters.class);
    Principal principal = mock(Principal.class);
    when(principal.getName()).thenReturn(USERNAME);
    when(claimsParameters.getPrincipal()).thenReturn(principal);
    return spyAttributeQueryClaimsHandler.retrieveClaimValues(claimCollection, claimsParameters);
}
Also used : URISyntaxException(java.net.URISyntaxException) ClaimCollection(org.apache.cxf.rt.security.claims.ClaimCollection) ProcessedClaimCollection(org.apache.cxf.sts.claims.ProcessedClaimCollection) URI(java.net.URI) Claim(org.apache.cxf.rt.security.claims.Claim) Principal(java.security.Principal) ClaimsParameters(org.apache.cxf.sts.claims.ClaimsParameters)

Aggregations

ClaimCollection (org.apache.cxf.rt.security.claims.ClaimCollection)17 ClaimsParameters (org.apache.cxf.sts.claims.ClaimsParameters)17 ProcessedClaimCollection (org.apache.cxf.sts.claims.ProcessedClaimCollection)17 Test (org.junit.Test)13 Principal (java.security.Principal)10 URI (java.net.URI)6 HashMap (java.util.HashMap)6 Claim (org.apache.cxf.rt.security.claims.Claim)6 ProcessedClaim (org.apache.cxf.sts.claims.ProcessedClaim)4 URISyntaxException (java.net.URISyntaxException)2 List (java.util.List)2 UserPrincipal (org.apache.karaf.jaas.boot.principal.UserPrincipal)2 Connection (org.forgerock.opendj.ldap.Connection)2 LDAPConnectionFactory (org.forgerock.opendj.ldap.LDAPConnectionFactory)2 LinkedAttribute (org.forgerock.opendj.ldap.LinkedAttribute)2 BindResult (org.forgerock.opendj.ldap.responses.BindResult)2 SearchResultEntry (org.forgerock.opendj.ldap.responses.SearchResultEntry)2 ConnectionEntryReader (org.forgerock.opendj.ldif.ConnectionEntryReader)2 Before (org.junit.Before)2 Matchers.anyString (org.mockito.Matchers.anyString)2