Search in sources :

Example 16 with ClaimCollection

use of org.apache.cxf.rt.security.claims.ClaimCollection in project alliance by codice.

the class VideographerClaimsHandlerTest method testNameClaim.

@SuppressWarnings("unchecked")
@Test
public void testNameClaim() throws URISyntaxException {
    claimsHandler = new VideographerClaimsHandler();
    claimsHandler.setAttributes(Collections.singletonList(CLAIM1));
    requestClaims = new ClaimCollection();
    Claim requestClaim = new Claim();
    URI nameURI = new URI(CLAIM_URI_1);
    requestClaim.setClaimType(nameURI);
    requestClaims.add(requestClaim);
    claimsParameters = new ClaimsParameters();
    claimsParameters.setPrincipal(new VideographerPrincipal(IP_ADDR));
    claimsCollection = claimsHandler.retrieveClaimValues(requestClaims, claimsParameters);
    assertThat(claimsCollection, containsInAnyOrder(getNameClaim(nameURI), getIpClaim()));
}
Also used : ClaimCollection(org.apache.cxf.rt.security.claims.ClaimCollection) ProcessedClaimCollection(org.apache.cxf.sts.claims.ProcessedClaimCollection) URI(java.net.URI) VideographerPrincipal(org.codice.alliance.video.security.principal.videographer.VideographerPrincipal) ProcessedClaim(org.apache.cxf.sts.claims.ProcessedClaim) Claim(org.apache.cxf.rt.security.claims.Claim) ClaimsParameters(org.apache.cxf.sts.claims.ClaimsParameters) Test(org.junit.Test)

Example 17 with ClaimCollection

use of org.apache.cxf.rt.security.claims.ClaimCollection 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.handlerRealm)) {
        LOGGER.warn("Realm [{}] doesn't match with configured realm [{}]", parameters.getRealm(), this.handlerRealm);
        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();
    }
    val claimCollection = new ProcessedClaimCollection();
    claims.stream().map(c -> createProcessedClaim(c, parameters)).forEach(claimCollection::add);
    return claimCollection;
}
Also used : lombok.val(lombok.val) ClaimsHandler(org.apache.cxf.sts.claims.ClaimsHandler) Getter(lombok.Getter) ClaimsParameters(org.apache.cxf.sts.claims.ClaimsParameters) RequiredArgsConstructor(lombok.RequiredArgsConstructor) lombok.val(lombok.val) Collectors(java.util.stream.Collectors) WSFederationClaims(org.apereo.cas.ws.idp.WSFederationClaims) RealmSupport(org.apache.cxf.sts.token.realm.RealmSupport) Slf4j(lombok.extern.slf4j.Slf4j) List(java.util.List) ClaimCollection(org.apache.cxf.rt.security.claims.ClaimCollection) CollectionUtils(org.apereo.cas.util.CollectionUtils) ProcessedClaimCollection(org.apache.cxf.sts.claims.ProcessedClaimCollection) ProcessedClaim(org.apache.cxf.sts.claims.ProcessedClaim) Claim(org.apache.cxf.rt.security.claims.Claim) ProcessedClaimCollection(org.apache.cxf.sts.claims.ProcessedClaimCollection)

Example 18 with ClaimCollection

use of org.apache.cxf.rt.security.claims.ClaimCollection in project cas by apereo.

the class CustomNamespaceWSFederationClaimsClaimsHandlerTests method verifySAML2Type.

@Test
public void verifySAML2Type() {
    val handler = new CustomNamespaceWSFederationClaimsClaimsHandler("CAS", "https://apereo.org/cas", List.of("https://apereo.org/cas/givenName", "https://apereo.org/cas/email"));
    val claims = new ClaimCollection();
    val claim = new Claim();
    claim.setClaimType("https://apereo.org/cas/givenName");
    claims.add(claim);
    val parameters = new ClaimsParameters();
    val requirements = new TokenRequirements();
    requirements.setTokenType(WSFederationConstants.WSS_SAML2_TOKEN_TYPE);
    parameters.setTokenRequirements(requirements);
    parameters.setRealm("CAS");
    parameters.setPrincipal(mock(Principal.class));
    val values = handler.retrieveClaimValues(claims, parameters);
    assertFalse(values.isEmpty());
    val processed = (ProcessedClaim) values.get(0);
    assertEquals("givenName", processed.getClaimType());
    assertEquals(handler.getIssuer(), processed.getIssuer());
}
Also used : lombok.val(lombok.val) TokenRequirements(org.apache.cxf.sts.request.TokenRequirements) ProcessedClaim(org.apache.cxf.sts.claims.ProcessedClaim) ClaimCollection(org.apache.cxf.rt.security.claims.ClaimCollection) ProcessedClaim(org.apache.cxf.sts.claims.ProcessedClaim) Claim(org.apache.cxf.rt.security.claims.Claim) Principal(java.security.Principal) ClaimsParameters(org.apache.cxf.sts.claims.ClaimsParameters) Test(org.junit.jupiter.api.Test)

Example 19 with ClaimCollection

use of org.apache.cxf.rt.security.claims.ClaimCollection in project cas by apereo.

the class CustomNamespaceWSFederationClaimsClaimsHandlerTests method verifySAML1Type.

@Test
public void verifySAML1Type() {
    val handler = new CustomNamespaceWSFederationClaimsClaimsHandler("CAS", "https://apereo.org/cas", List.of("https://apereo.org/cas/givenName", "https://apereo.org/cas/email"));
    val claims = new ClaimCollection();
    val claim = new Claim();
    claim.setClaimType("https://apereo.org/cas/givenName");
    claims.add(claim);
    val parameters = new ClaimsParameters();
    val requirements = new TokenRequirements();
    requirements.setTokenType(WSFederationConstants.WSS_SAML1_TOKEN_TYPE);
    parameters.setTokenRequirements(requirements);
    parameters.setRealm("CAS");
    parameters.setPrincipal(mock(Principal.class));
    val values = handler.retrieveClaimValues(claims, parameters);
    assertFalse(values.isEmpty());
    val processed = (ProcessedClaim) values.get(0);
    assertEquals("https://apereo.org/cas/givenName", processed.getClaimType());
    assertEquals(handler.getIssuer(), processed.getIssuer());
}
Also used : lombok.val(lombok.val) TokenRequirements(org.apache.cxf.sts.request.TokenRequirements) ProcessedClaim(org.apache.cxf.sts.claims.ProcessedClaim) ClaimCollection(org.apache.cxf.rt.security.claims.ClaimCollection) ProcessedClaim(org.apache.cxf.sts.claims.ProcessedClaim) Claim(org.apache.cxf.rt.security.claims.Claim) Principal(java.security.Principal) ClaimsParameters(org.apache.cxf.sts.claims.ClaimsParameters) Test(org.junit.jupiter.api.Test)

Example 20 with ClaimCollection

use of org.apache.cxf.rt.security.claims.ClaimCollection in project cas by apereo.

the class WrappingSecurityTokenServiceClaimsHandlerTests method verifyClaimMatchesRealm.

@Test
public void verifyClaimMatchesRealm() {
    val claims = new ClaimCollection();
    val claim = new Claim();
    claim.setClaimType(WSFederationClaims.COMMON_NAME.getUri());
    claims.add(claim);
    val parameters = new ClaimsParameters();
    parameters.setRealm("CAS-Other");
    val handler = new WrappingSecurityTokenServiceClaimsHandler("CAS", "https://apereo.org/cas");
    assertTrue(handler.retrieveClaimValues(claims, parameters).isEmpty());
}
Also used : lombok.val(lombok.val) ClaimCollection(org.apache.cxf.rt.security.claims.ClaimCollection) Claim(org.apache.cxf.rt.security.claims.Claim) ClaimsParameters(org.apache.cxf.sts.claims.ClaimsParameters) Test(org.junit.jupiter.api.Test)

Aggregations

ClaimCollection (org.apache.cxf.rt.security.claims.ClaimCollection)100 Claim (org.apache.cxf.rt.security.claims.Claim)63 ClaimsManager (org.apache.cxf.sts.claims.ClaimsManager)46 ClaimsParameters (org.apache.cxf.sts.claims.ClaimsParameters)43 ProcessedClaimCollection (org.apache.cxf.sts.claims.ProcessedClaimCollection)42 ProcessedClaim (org.apache.cxf.sts.claims.ProcessedClaim)31 CustomTokenPrincipal (org.apache.wss4j.common.principal.CustomTokenPrincipal)26 ClaimsHandler (org.apache.cxf.sts.claims.ClaimsHandler)23 Principal (java.security.Principal)22 CustomClaimsHandler (org.apache.cxf.sts.common.CustomClaimsHandler)22 URI (java.net.URI)21 Element (org.w3c.dom.Element)21 StaticClaimsHandler (org.apache.cxf.sts.claims.StaticClaimsHandler)15 SamlAssertionWrapper (org.apache.wss4j.common.saml.SamlAssertionWrapper)13 ArrayList (java.util.ArrayList)12 LdapClaimsHandler (org.apache.cxf.sts.claims.LdapClaimsHandler)12 JAXBElement (javax.xml.bind.JAXBElement)10 Test (org.junit.Test)10 SAMLSecurityContext (org.apache.cxf.rt.security.saml.claims.SAMLSecurityContext)9 StaticEndpointClaimsHandler (org.apache.cxf.sts.claims.StaticEndpointClaimsHandler)9