Search in sources :

Example 1 with ClaimsParameters

use of org.apache.cxf.sts.claims.ClaimsParameters in project cas by apereo.

the class WrappingSecurityTokenServiceClaimsHandler method retrieveClaimValues.

@Override
public ProcessedClaimCollection retrieveClaimValues(final ClaimCollection claims, final ClaimsParameters parameters) {
    if (parameters.getRealm() == null || !parameters.getRealm().equalsIgnoreCase(this.realm)) {
        LOGGER.warn("Realm [{}] doesn't match with configured realm [{}]", parameters.getRealm(), this.realm);
        return new ProcessedClaimCollection();
    }
    if (parameters.getPrincipal() == null) {
        LOGGER.warn("No principal could be identified in the claim parameters request");
        return new ProcessedClaimCollection();
    }
    if (claims == null || claims.isEmpty()) {
        LOGGER.warn("No claims are available to process");
        return new ProcessedClaimCollection();
    }
    final ProcessedClaimCollection claimCollection = new ProcessedClaimCollection();
    claims.stream().map(requestClaim -> {
        final ProcessedClaim claim = new ProcessedClaim();
        claim.setClaimType(requestClaim.getClaimType());
        claim.setIssuer(this.issuer);
        claim.setOriginalIssuer(this.issuer);
        claim.setValues(requestClaim.getValues());
        return claim;
    }).forEach(claimCollection::add);
    return claimCollection;
}
Also used : ClaimsHandler(org.apache.cxf.sts.claims.ClaimsHandler) Arrays(java.util.Arrays) Logger(org.slf4j.Logger) ClaimsParameters(org.apache.cxf.sts.claims.ClaimsParameters) LoggerFactory(org.slf4j.LoggerFactory) Collectors(java.util.stream.Collectors) RealmSupport(org.apache.cxf.sts.token.realm.RealmSupport) WSFederationClaims(org.apereo.cas.ws.idp.WSFederationClaims) List(java.util.List) ClaimCollection(org.apache.cxf.rt.security.claims.ClaimCollection) UriBuilder(javax.ws.rs.core.UriBuilder) URI(java.net.URI) ProcessedClaimCollection(org.apache.cxf.sts.claims.ProcessedClaimCollection) ProcessedClaim(org.apache.cxf.sts.claims.ProcessedClaim) ProcessedClaimCollection(org.apache.cxf.sts.claims.ProcessedClaimCollection) ProcessedClaim(org.apache.cxf.sts.claims.ProcessedClaim)

Example 2 with ClaimsParameters

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

the class TestAttributeFileClaimsHandler method testRetrieveClaimsValuesNullPrincipal.

@Test
public void testRetrieveClaimsValuesNullPrincipal() {
    ClaimsParameters claimsParameters = new ClaimsParameters();
    ClaimCollection claimCollection = new ClaimCollection();
    ProcessedClaimCollection processedClaims = attributeFileClaimsHandler.retrieveClaimValues(claimCollection, claimsParameters);
    Assert.assertThat(processedClaims.size(), CoreMatchers.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 3 with ClaimsParameters

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

the class CertificateClaimsHandlerTest method testRetrieveClaimValuesWithCountry.

@Test
public void testRetrieveClaimValuesWithCountry() 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.COUNTRY_CLAIM_URI, "USA");
    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.COUNTRY_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 4 with ClaimsParameters

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

the class CertificateClaimsHandlerTest method testRetrieveClaimValuesWithCertValues.

@Test
public void testRetrieveClaimValuesWithCertValues() 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");
    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(SubjectUtils.EMAIL_ADDRESS_CLAIM_URI, SubjectUtils.COUNTRY_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 5 with ClaimsParameters

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

the class CertificateClaimsHandlerTest method testRetrieveClaimValuesWithAltNamesNotRequested.

@Test
public void testRetrieveClaimValuesWithAltNamesNotRequested() throws URISyntaxException {
    CertificateClaimsHandler certificateClaimsHandler = new CertificateClaimsHandler();
    certificateClaimsHandler.setCountryClaim("Country");
    certificateClaimsHandler.setEmailClaim("Email");
    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");
    map.put(SubjectUtils.COUNTRY_CLAIM_URI, "USA");
    parameters.setAdditionalProperties(map);
    ProcessedClaimCollection processedClaims = certificateClaimsHandler.retrieveClaimValues(claims, parameters);
    assertThat(processedClaims.size(), is(0));
}
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)

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