Search in sources :

Example 21 with ClaimsCollection

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

the class PropertyFileClaimsHandler method retrieveClaims.

@Override
public ClaimsCollection retrieveClaims(ClaimsParameters parameters) {
    ClaimsCollection claimsColl = new ClaimsCollectionImpl();
    Principal principal = parameters.getPrincipal();
    String user = getUser(principal);
    if (user == null) {
        LOGGER.info("Could not determine user name, possible authentication error. Returning no claims.");
        return claimsColl;
    }
    String userAttributes = userMapping.get(user);
    if (userAttributes != null) {
        String[] attributes = userAttributes.split(",");
        Claim c = new ClaimImpl(roleClaimType);
        for (int i = 1; i < attributes.length; i++) {
            c.addValue(attributes[i]);
        }
        claimsColl.add(c);
    }
    Claim idClaim = new ClaimImpl(idClaimType);
    idClaim.addValue(user);
    claimsColl.add(idClaim);
    return claimsColl;
}
Also used : ClaimsCollectionImpl(ddf.security.claims.impl.ClaimsCollectionImpl) ClaimImpl(ddf.security.claims.impl.ClaimImpl) ClaimsCollection(ddf.security.claims.ClaimsCollection) X500Principal(javax.security.auth.x500.X500Principal) KerberosPrincipal(javax.security.auth.kerberos.KerberosPrincipal) Principal(java.security.Principal) Claim(ddf.security.claims.Claim)

Example 22 with ClaimsCollection

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

the class UsersAttributesFileClaimsHandler method retrieveClaims.

@Override
public ClaimsCollection retrieveClaims(ClaimsParameters claimsParameters) {
    ClaimsCollection claimsColl = new ClaimsCollectionImpl();
    Principal principal = claimsParameters.getPrincipal();
    if (principal == null) {
        return claimsColl;
    }
    String name;
    if (principal instanceof X500Principal) {
        name = subjectOperations.getCommonName((X500Principal) principal);
    } else {
        name = principal.getName();
    }
    Map<String, Set<String>> userMap = json.get(name);
    if (userMap == null) {
        userMap = attemptToFindAMatchingRegexFormatUserEntry(principal, json);
    }
    if (userMap == null) {
        return claimsColl;
    }
    for (Map.Entry<String, Set<String>> claimEntry : userMap.entrySet()) {
        Set<String> attributeValue = claimEntry.getValue();
        Claim c = new ClaimImpl(claimEntry.getKey());
        if (attributeValue != null) {
            attributeValue.forEach(c::addValue);
            claimsColl.add(c);
        }
    }
    return claimsColl;
}
Also used : ImmutableSet(com.google.common.collect.ImmutableSet) Set(java.util.Set) ClaimImpl(ddf.security.claims.impl.ClaimImpl) ClaimsCollectionImpl(ddf.security.claims.impl.ClaimsCollectionImpl) ClaimsCollection(ddf.security.claims.ClaimsCollection) X500Principal(javax.security.auth.x500.X500Principal) HashMap(java.util.HashMap) Map(java.util.Map) X500Principal(javax.security.auth.x500.X500Principal) Principal(java.security.Principal) Claim(ddf.security.claims.Claim)

Example 23 with ClaimsCollection

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

the class UsersAttributesFileClaimsHandlerTest method testRetrieveClaimValuesTestHostname.

@Test
public void testRetrieveClaimValuesTestHostname() throws IOException {
    // given
    System.setProperty(SystemBaseUrl.INTERNAL_HOST, "testHostname");
    final UsersAttributesFileClaimsHandler usersAttributesFileClaimsHandler = new UsersAttributesFileClaimsHandler();
    usersAttributesFileClaimsHandler.setUsersAttributesFileLocation(getPathForValidTestAttributesFile());
    final ClaimsCollection ClaimsCollection = getClaimsCollectionForValidTestAttributesFile();
    final Principal principal = mock(Principal.class);
    when(principal.getName()).thenReturn("testHostname");
    final ClaimsParameters testHostnameClaimsParameters = new ClaimsParametersImpl(principal, new HashSet<>(), new HashMap<>());
    // when
    final ClaimsCollection processedClaims = usersAttributesFileClaimsHandler.retrieveClaims(testHostnameClaimsParameters);
    // then
    assertThat(processedClaims, containsInAnyOrder(allOf(hasProperty("name", is("Clearance")), hasProperty("values", containsInAnyOrder("U"))), allOf(hasProperty("name", is("CountryOfAffiliation")), hasProperty("values", containsInAnyOrder("USA"))), allOf(hasProperty("name", is("classification")), hasProperty("values", containsInAnyOrder("U"))), allOf(hasProperty("name", is("http://schemas.xmlsoap.org/ws/2005/05/identity/claims/emailaddress")), hasProperty("values", containsInAnyOrder("system@testHostname"))), allOf(hasProperty("name", is("ownerProducer")), hasProperty("values", containsInAnyOrder("USA"))), allOf(hasProperty("name", is("releasableTo")), hasProperty("values", containsInAnyOrder("USA"))), allOf(hasProperty("name", is("FineAccessControls")), hasProperty("values", containsInAnyOrder("SCI1", "SCI2"))), allOf(hasProperty("name", is("disseminationControls")), hasProperty("values", containsInAnyOrder("NF")))));
}
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 24 with ClaimsCollection

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

the class UsersAttributesFileClaimsHandlerTest method testNoMatchRetrieveClaimValues.

@Test
public void testNoMatchRetrieveClaimValues() throws IOException {
    // given
    System.setProperty(SystemBaseUrl.INTERNAL_HOST, "testHostname");
    final UsersAttributesFileClaimsHandler usersAttributesFileClaimsHandler = new UsersAttributesFileClaimsHandler();
    usersAttributesFileClaimsHandler.setUsersAttributesFileLocation(getPathForValidTestAttributesFile());
    final ClaimsCollection ClaimsCollection = getClaimsCollectionForValidTestAttributesFile();
    final Principal principal = mock(Principal.class);
    when(principal.getName()).thenReturn("someNameThat'sNotInTheUsersAttributesFile");
    final ClaimsParameters unknownClaimsParameters = new ClaimsParametersImpl(principal, new HashSet<>(), new HashMap<>());
    // when
    final ClaimsCollection processedClaims = usersAttributesFileClaimsHandler.retrieveClaims(unknownClaimsParameters);
    // then
    assertThat(processedClaims, is(empty()));
}
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 25 with ClaimsCollection

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

the class AttributeQueryClaimsHandlerTest method testRetrieveClaimValues.

@Test
public void testRetrieveClaimValues() throws Exception {
    ClaimsCollection processedClaimCollection = retrieveClaimValues();
    // Test that the claims were created and mapped correctly.
    assertThat(processedClaimCollection.size(), is(equalTo(3)));
    assertThat(processedClaimCollection.get(0).getName(), is(equalTo("Role")));
    assertThat((String) processedClaimCollection.get(0).getValues().get(0), is(equalTo("Guest-hasMapping")));
    assertThat(processedClaimCollection.get(1).getName(), is(equalTo("NameIdentifier")));
    assertThat((String) processedClaimCollection.get(1).getValues().get(0), is(equalTo("Name-hasMapping")));
    // Does not have an attribute mapping.
    assertThat(processedClaimCollection.get(2).getName(), is(equalTo("Email")));
    assertThat((String) processedClaimCollection.get(2).getValues().get(0), is(equalTo("email")));
}
Also used : ClaimsCollection(ddf.security.claims.ClaimsCollection) 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