Search in sources :

Example 1 with ClaimsCollection

use of ddf.security.claims.ClaimsCollection in project ddf by codice.

the class PropertyFileClaimsHandlerTest method testRetrieveClaimValues.

@Test
public void testRetrieveClaimValues() {
    PropertyFileClaimsHandler propertyFileClaimsHandler = new PropertyFileClaimsHandler();
    propertyFileClaimsHandler.setPropertyFileLocation("/users.properties");
    propertyFileClaimsHandler.setRoleClaimType("http://myroletype");
    propertyFileClaimsHandler.setIdClaimType("http://myidtype");
    ClaimsParameters claimsParameters = mock(ClaimsParameters.class);
    Principal principal = mock(Principal.class);
    when(principal.getName()).thenReturn("admin");
    when(claimsParameters.getPrincipal()).thenReturn(principal);
    ClaimsCollection processedClaimCollection = propertyFileClaimsHandler.retrieveClaims(claimsParameters);
    assertEquals(2, processedClaimCollection.size());
    assertEquals(4, processedClaimCollection.get(0).getValues().size());
    assertEquals("admin", processedClaimCollection.get(1).getValues().get(0));
}
Also used : ClaimsCollection(ddf.security.claims.ClaimsCollection) Principal(java.security.Principal) X500Principal(javax.security.auth.x500.X500Principal) KerberosPrincipal(javax.security.auth.kerberos.KerberosPrincipal) ClaimsParameters(ddf.security.claims.ClaimsParameters) Test(org.junit.Test)

Example 2 with ClaimsCollection

use of ddf.security.claims.ClaimsCollection in project ddf by codice.

the class AttributeQueryClaimsHandler method getAttributes.

/**
 * Gets the attributes for the supplied user from the external attribute store. Returns null if
 * the AttributeQueryClient is null.
 *
 * @param nameId used for the request.
 * @return The collection of attributes retrieved from the external attribute store.
 * @throws URISyntaxException
 */
protected ClaimsCollection getAttributes(String nameId) throws URISyntaxException {
    ClaimsCollection claimCollection = new ClaimsCollectionImpl();
    LOGGER.debug("Sending AttributeQuery Request.");
    AttributeQueryClient attributeQueryClient;
    Assertion assertion;
    try {
        attributeQueryClient = createAttributeQueryClient(simpleSign, externalAttributeStoreUrl, issuer, destination);
        if (attributeQueryClient == null) {
            return null;
        }
        assertion = attributeQueryClient.query(nameId);
        if (assertion != null) {
            createClaims(claimCollection, assertion);
        }
    } catch (AttributeQueryException ex) {
        LOGGER.info("Error occurred in AttributeQueryClient, did not retrieve response. Set log level for \"org.codice.ddf.security.claims.attributequery.common\" to DEBUG for more information.");
        LOGGER.debug("Error occurred in AttributeQueryClient, did not retrieve response.", ex);
    }
    return claimCollection;
}
Also used : ClaimsCollectionImpl(ddf.security.claims.impl.ClaimsCollectionImpl) Assertion(org.opensaml.saml.saml2.core.Assertion) ClaimsCollection(ddf.security.claims.ClaimsCollection)

Example 3 with ClaimsCollection

use of ddf.security.claims.ClaimsCollection 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 4 with ClaimsCollection

use of ddf.security.claims.ClaimsCollection 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 5 with ClaimsCollection

use of ddf.security.claims.ClaimsCollection 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)

Aggregations

ClaimsCollection (ddf.security.claims.ClaimsCollection)29 Test (org.junit.Test)18 Principal (java.security.Principal)16 ClaimsParameters (ddf.security.claims.ClaimsParameters)14 ClaimsParametersImpl (ddf.security.claims.impl.ClaimsParametersImpl)14 HashMap (java.util.HashMap)10 Claim (ddf.security.claims.Claim)9 ClaimsCollectionImpl (ddf.security.claims.impl.ClaimsCollectionImpl)9 ClaimImpl (ddf.security.claims.impl.ClaimImpl)6 ClaimsHandler (ddf.security.claims.ClaimsHandler)4 ArrayList (java.util.ArrayList)4 HashSet (java.util.HashSet)4 X500Principal (javax.security.auth.x500.X500Principal)4 UserPrincipal (org.apache.karaf.jaas.boot.principal.UserPrincipal)4 Connection (org.forgerock.opendj.ldap.Connection)4 BindResult (org.forgerock.opendj.ldap.responses.BindResult)4 SearchResultEntry (org.forgerock.opendj.ldap.responses.SearchResultEntry)4 ConnectionEntryReader (org.forgerock.opendj.ldif.ConnectionEntryReader)4 SubjectUtils (ddf.security.service.impl.SubjectUtils)3 AttributeStatement (ddf.security.assertion.AttributeStatement)2