Search in sources :

Example 1 with ClaimsParametersImpl

use of ddf.security.claims.impl.ClaimsParametersImpl in project ddf by codice.

the class CertificateClaimsHandlerTest method testRetrieveClaimValuesNoCertValues.

@Test
public void testRetrieveClaimValuesNoCertValues() throws URISyntaxException {
    CertificateClaimsHandler certificateClaimsHandler = new CertificateClaimsHandler();
    ClaimsParameters parameters = new ClaimsParametersImpl(mock(Principal.class), new HashSet<>(), new HashMap<>());
    ClaimsCollection processedClaims = certificateClaimsHandler.retrieveClaims(parameters);
    assertThat(processedClaims.size(), is(0));
}
Also used : ClaimsParametersImpl(ddf.security.claims.impl.ClaimsParametersImpl) ClaimsCollection(ddf.security.claims.ClaimsCollection) Principal(java.security.Principal) ClaimsParameters(ddf.security.claims.ClaimsParameters) Test(org.junit.Test)

Example 2 with ClaimsParametersImpl

use of ddf.security.claims.impl.ClaimsParametersImpl in project ddf by codice.

the class CertificateClaimsHandlerTest method testRetrieveClaimValuesWithCountry.

@Test
public void testRetrieveClaimValuesWithCountry() throws URISyntaxException {
    CertificateClaimsHandler certificateClaimsHandler = new CertificateClaimsHandler();
    Map<String, Object> map = new HashMap<>();
    map.put(SubjectOperations.COUNTRY_CLAIM_URI, "USA");
    ClaimsParameters parameters = new ClaimsParametersImpl(mock(Principal.class), new HashSet<>(), map);
    ClaimsCollection processedClaims = certificateClaimsHandler.retrieveClaims(parameters);
    assertThat(processedClaims.size(), is(1));
    assertThat(processedClaims.stream().map(ddf.security.claims.Claim::getName).collect(Collectors.toList()), containsInAnyOrder(SubjectOperations.COUNTRY_CLAIM_URI));
}
Also used : ClaimsParametersImpl(ddf.security.claims.impl.ClaimsParametersImpl) HashMap(java.util.HashMap) ClaimsCollection(ddf.security.claims.ClaimsCollection) Principal(java.security.Principal) ClaimsParameters(ddf.security.claims.ClaimsParameters) Test(org.junit.Test)

Example 3 with ClaimsParametersImpl

use of ddf.security.claims.impl.ClaimsParametersImpl in project ddf by codice.

the class CertificateClaimsHandlerTest method testRetrieveClaimValuesWithCertValues.

@Test
public void testRetrieveClaimValuesWithCertValues() throws URISyntaxException {
    CertificateClaimsHandler certificateClaimsHandler = new CertificateClaimsHandler();
    Map<String, Object> map = new HashMap<>();
    map.put(SubjectOperations.EMAIL_ADDRESS_CLAIM_URI, "local@localhost");
    map.put(SubjectOperations.COUNTRY_CLAIM_URI, "USA");
    ClaimsParameters parameters = new ClaimsParametersImpl(mock(Principal.class), new HashSet<>(), map);
    ClaimsCollection processedClaims = certificateClaimsHandler.retrieveClaims(parameters);
    assertThat(processedClaims.size(), is(2));
    assertThat(processedClaims.stream().map(ddf.security.claims.Claim::getName).collect(Collectors.toList()), containsInAnyOrder(SubjectOperations.EMAIL_ADDRESS_CLAIM_URI, SubjectOperations.COUNTRY_CLAIM_URI));
}
Also used : ClaimsParametersImpl(ddf.security.claims.impl.ClaimsParametersImpl) HashMap(java.util.HashMap) ClaimsCollection(ddf.security.claims.ClaimsCollection) Principal(java.security.Principal) ClaimsParameters(ddf.security.claims.ClaimsParameters) Test(org.junit.Test)

Example 4 with ClaimsParametersImpl

use of ddf.security.claims.impl.ClaimsParametersImpl 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");
    Map<String, Object> map = new HashMap<>();
    map.put(SubjectOperations.EMAIL_ADDRESS_CLAIM_URI, "local@localhost");
    map.put(SubjectOperations.COUNTRY_CLAIM_URI, "USA");
    ClaimsParameters parameters = new ClaimsParametersImpl(mock(Principal.class), new HashSet<>(), map);
    ClaimsCollection processedClaims = certificateClaimsHandler.retrieveClaims(parameters);
    assertThat(processedClaims.size(), is(2));
    assertThat(processedClaims.stream().map(ddf.security.claims.Claim::getName).collect(Collectors.toList()), containsInAnyOrder("Email", "Country"));
}
Also used : ClaimsParametersImpl(ddf.security.claims.impl.ClaimsParametersImpl) HashMap(java.util.HashMap) ClaimsCollection(ddf.security.claims.ClaimsCollection) Principal(java.security.Principal) ClaimsParameters(ddf.security.claims.ClaimsParameters) Test(org.junit.Test)

Example 5 with ClaimsParametersImpl

use of ddf.security.claims.impl.ClaimsParametersImpl in project ddf by codice.

the class CertificateClaimsHandlerTest method testRetrieveClaimValuesWithEmail.

@Test
public void testRetrieveClaimValuesWithEmail() throws URISyntaxException {
    CertificateClaimsHandler certificateClaimsHandler = new CertificateClaimsHandler();
    Map<String, Object> map = new HashMap<>();
    map.put(SubjectOperations.EMAIL_ADDRESS_CLAIM_URI, "local@localhost");
    ClaimsParameters parameters = new ClaimsParametersImpl(mock(Principal.class), new HashSet<>(), map);
    ClaimsCollection processedClaims = certificateClaimsHandler.retrieveClaims(parameters);
    assertThat(processedClaims.size(), is(1));
    assertThat(processedClaims.stream().map(ddf.security.claims.Claim::getName).collect(Collectors.toList()), containsInAnyOrder(SubjectOperations.EMAIL_ADDRESS_CLAIM_URI));
}
Also used : ClaimsParametersImpl(ddf.security.claims.impl.ClaimsParametersImpl) HashMap(java.util.HashMap) ClaimsCollection(ddf.security.claims.ClaimsCollection) Principal(java.security.Principal) ClaimsParameters(ddf.security.claims.ClaimsParameters) Test(org.junit.Test)

Aggregations

ClaimsCollection (ddf.security.claims.ClaimsCollection)14 ClaimsParametersImpl (ddf.security.claims.impl.ClaimsParametersImpl)14 ClaimsParameters (ddf.security.claims.ClaimsParameters)12 Test (org.junit.Test)12 Principal (java.security.Principal)10 HashMap (java.util.HashMap)9 Claim (ddf.security.claims.Claim)4 HashSet (java.util.HashSet)4 UserPrincipal (org.apache.karaf.jaas.boot.principal.UserPrincipal)4 SubjectUtils (ddf.security.service.impl.SubjectUtils)3 AttributeStatement (ddf.security.assertion.AttributeStatement)2 SecurityAssertion (ddf.security.assertion.SecurityAssertion)2 AttributeStatementDefault (ddf.security.assertion.impl.AttributeStatementDefault)2 DefaultSecurityAssertionBuilder (ddf.security.assertion.impl.DefaultSecurityAssertionBuilder)2 ClaimsHandler (ddf.security.claims.ClaimsHandler)2 Instant (java.time.Instant)2 SimplePrincipalCollection (org.apache.shiro.subject.SimplePrincipalCollection)2 Connection (org.forgerock.opendj.ldap.Connection)2 ConnectionFactory (org.forgerock.opendj.ldap.ConnectionFactory)2 DN (org.forgerock.opendj.ldap.DN)2