Search in sources :

Example 1 with ClaimImpl

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

the class PKIRealmTest method setup.

@Before
public void setup() {
    List<ClaimsHandler> claimsHandlers = new ArrayList<>();
    claimsHandlers.add(mock(ClaimsHandler.class));
    claimsHandlers.add(mock(ClaimsHandler.class));
    ClaimsCollection claims1 = new ClaimsCollectionImpl();
    ClaimImpl email1 = new ClaimImpl("email");
    email1.addValue("test@example.com");
    claims1.add(email1);
    ClaimsCollection claims2 = new ClaimsCollectionImpl();
    ClaimImpl email2 = new ClaimImpl("email");
    email2.addValue("tester@example.com");
    claims2.add(email2);
    when(claimsHandlers.get(0).retrieveClaims(any())).thenReturn(claims1);
    when(claimsHandlers.get(1).retrieveClaims(any())).thenReturn(claims2);
    pkiRealm.setClaimsHandlers(claimsHandlers);
}
Also used : ClaimsHandler(ddf.security.claims.ClaimsHandler) ClaimsCollectionImpl(ddf.security.claims.impl.ClaimsCollectionImpl) ArrayList(java.util.ArrayList) ClaimImpl(ddf.security.claims.impl.ClaimImpl) ClaimsCollection(ddf.security.claims.ClaimsCollection) Before(org.junit.Before)

Example 2 with ClaimImpl

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

the class UsernamePasswordRealmTest method setup.

@Before
public void setup() {
    List<ClaimsHandler> claimsHandlers = new ArrayList<>();
    claimsHandlers.add(mock(ClaimsHandler.class));
    claimsHandlers.add(mock(ClaimsHandler.class));
    ClaimsCollection claims1 = new ClaimsCollectionImpl();
    ClaimImpl email1 = new ClaimImpl("email");
    email1.addValue("test@example.com");
    claims1.add(email1);
    ClaimsCollection claims2 = new ClaimsCollectionImpl();
    ClaimImpl email2 = new ClaimImpl("email");
    email2.addValue("tester@example.com");
    claims2.add(email2);
    when(claimsHandlers.get(0).retrieveClaims(any())).thenReturn(claims1);
    when(claimsHandlers.get(1).retrieveClaims(any())).thenReturn(claims2);
    upRealm.setClaimsHandlers(claimsHandlers);
    JaasRealm jaasRealm = mock(JaasRealm.class);
    when(jaasRealm.getName()).thenReturn("realm");
    upRealm.realmList.add(jaasRealm);
}
Also used : JaasRealm(org.apache.karaf.jaas.config.JaasRealm) ClaimsHandler(ddf.security.claims.ClaimsHandler) ClaimsCollectionImpl(ddf.security.claims.impl.ClaimsCollectionImpl) ArrayList(java.util.ArrayList) ClaimImpl(ddf.security.claims.impl.ClaimImpl) ClaimsCollection(ddf.security.claims.ClaimsCollection) Before(org.junit.Before)

Example 3 with ClaimImpl

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

the class AttributeQueryClaimsHandler method createSingleValuedClaim.

/**
 * Creates a single valued claim.
 *
 * @param claimType The claim type.
 * @param claimValue The claim value.
 * @return The claim.
 * @throws URISyntaxException
 */
protected Claim createSingleValuedClaim(String claimType, String claimValue) {
    Claim claim = new ClaimImpl(claimType);
    claim.addValue(claimValue);
    LOGGER.debug("Created claim with type [{}] and value [{}].", claimType, claimValue);
    return claim;
}
Also used : ClaimImpl(ddf.security.claims.impl.ClaimImpl) Claim(ddf.security.claims.Claim)

Example 4 with ClaimImpl

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

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

Aggregations

ClaimImpl (ddf.security.claims.impl.ClaimImpl)8 Claim (ddf.security.claims.Claim)6 ClaimsCollection (ddf.security.claims.ClaimsCollection)6 ClaimsCollectionImpl (ddf.security.claims.impl.ClaimsCollectionImpl)6 Principal (java.security.Principal)4 ArrayList (java.util.ArrayList)3 X500Principal (javax.security.auth.x500.X500Principal)3 ClaimsHandler (ddf.security.claims.ClaimsHandler)2 Map (java.util.Map)2 Attribute (org.forgerock.opendj.ldap.Attribute)2 ByteString (org.forgerock.opendj.ldap.ByteString)2 Connection (org.forgerock.opendj.ldap.Connection)2 LdapException (org.forgerock.opendj.ldap.LdapException)2 SearchResultReferenceIOException (org.forgerock.opendj.ldap.SearchResultReferenceIOException)2 BindRequest (org.forgerock.opendj.ldap.requests.BindRequest)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 AndFilter (org.springframework.ldap.filter.AndFilter)2