Search in sources :

Example 51 with ClaimCollection

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

the class RequestParser method parseClaims.

/**
 * Create a ClaimCollection from a DOM Element
 */
private ClaimCollection parseClaims(Element claimsElement, List<ClaimsParser> claimsParsers) {
    String dialectAttr = null;
    ClaimCollection requestedClaims = new ClaimCollection();
    try {
        dialectAttr = claimsElement.getAttributeNS(null, "Dialect");
        if (dialectAttr != null && !"".equals(dialectAttr)) {
            requestedClaims.setDialect(new URI(dialectAttr));
        }
    } catch (URISyntaxException e1) {
        LOG.log(Level.WARNING, "Cannot create URI from the given Dialect attribute value " + dialectAttr, e1);
    }
    Element childClaimType = DOMUtils.getFirstElement(claimsElement);
    while (childClaimType != null) {
        Claim requestClaim = parseChildClaimType(childClaimType, dialectAttr, claimsParsers);
        if (requestClaim != null) {
            requestedClaims.add(requestClaim);
        }
        childClaimType = DOMUtils.getNextElement(childClaimType);
    }
    return requestedClaims;
}
Also used : JAXBElement(javax.xml.bind.JAXBElement) Element(org.w3c.dom.Element) URISyntaxException(java.net.URISyntaxException) ClaimCollection(org.apache.cxf.rt.security.claims.ClaimCollection) URI(java.net.URI) Claim(org.apache.cxf.rt.security.claims.Claim)

Example 52 with ClaimCollection

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

the class RequestParser method parseClaims.

/**
 * Create a ClaimCollection from a JAXB ClaimsType object
 */
private static ClaimCollection parseClaims(ClaimsType claimsType, List<ClaimsParser> claimsParsers) {
    String dialectAttr = null;
    ClaimCollection requestedClaims = new ClaimCollection();
    try {
        dialectAttr = claimsType.getDialect();
        if (dialectAttr != null && !"".equals(dialectAttr)) {
            requestedClaims.setDialect(new URI(dialectAttr));
        }
    } catch (URISyntaxException e1) {
        LOG.log(Level.WARNING, "Cannot create URI from the given Dialect attribute value " + dialectAttr, e1);
    }
    for (Object claim : claimsType.getAny()) {
        if (claim instanceof Element) {
            Claim requestClaim = parseChildClaimType((Element) claim, dialectAttr, claimsParsers);
            if (requestClaim != null) {
                requestedClaims.add(requestClaim);
            }
        }
    }
    return requestedClaims;
}
Also used : JAXBElement(javax.xml.bind.JAXBElement) Element(org.w3c.dom.Element) URISyntaxException(java.net.URISyntaxException) ClaimCollection(org.apache.cxf.rt.security.claims.ClaimCollection) URI(java.net.URI) Claim(org.apache.cxf.rt.security.claims.Claim)

Example 53 with ClaimCollection

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

the class DefaultSAMLRoleParser method parseRolesFromAssertion.

/**
 * Return the set of User/Principal roles from the Assertion.
 * @param principal the Principal associated with the Assertion
 * @param subject the JAAS Subject associated with a successful validation of the Assertion
 * @param assertion The Assertion object
 * @return the set of User/Principal roles from the Assertion.
 */
public Set<Principal> parseRolesFromAssertion(Principal principal, Subject subject, SamlAssertionWrapper assertion) {
    if (subject != null && useJaasSubject) {
        return super.parseRolesFromSubject(principal, subject);
    }
    ClaimCollection claims = SAMLUtils.getClaims(assertion);
    Set<Principal> roles = SAMLUtils.parseRolesFromClaims(claims, roleAttributeName, null);
    SAMLSecurityContext context = new SAMLSecurityContext(principal, roles, claims);
    return context.getUserRoles();
}
Also used : SAMLSecurityContext(org.apache.cxf.rt.security.saml.claims.SAMLSecurityContext) ClaimCollection(org.apache.cxf.rt.security.claims.ClaimCollection) Principal(java.security.Principal)

Example 54 with ClaimCollection

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

the class RoleClaimsHandlerTest method testRetrieveClaimsValuesNullPrincipal.

@Test
public void testRetrieveClaimsValuesNullPrincipal() {
    RoleClaimsHandler claimsHandler = new RoleClaimsHandler();
    ClaimsParameters claimsParameters = new ClaimsParameters();
    ClaimCollection claimCollection = new ClaimCollection();
    ProcessedClaimCollection processedClaims = claimsHandler.retrieveClaimValues(claimCollection, claimsParameters);
    assertThat(processedClaims, is(empty()));
}
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) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 55 with ClaimCollection

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

the class GuestClaimsHandlerTest method testRetrieveClaims.

@Test
public void testRetrieveClaims() throws URISyntaxException {
    GuestClaimsHandler claimsHandler = new GuestClaimsHandler();
    claimsHandler.setAttributes(Arrays.asList("http://schemas.xmlsoap.org/ws/2005/05/identity/claims/nameidentifier=Guest", "http://schemas.xmlsoap.org/ws/2005/05/identity/claims/emailaddress=Guest@guest.com|someguy@somesite.com|somedude@cool.com", "http://schemas.xmlsoap.org/ws/2005/05/identity/claims/surname=Guest"));
    ClaimCollection requestClaims = new ClaimCollection();
    Claim requestClaim = new Claim();
    URI nameURI = new URI("http://schemas.xmlsoap.org/ws/2005/05/identity/claims/nameidentifier");
    requestClaim.setClaimType(nameURI);
    requestClaims.add(requestClaim);
    requestClaim = new Claim();
    URI emailURI = new URI("http://schemas.xmlsoap.org/ws/2005/05/identity/claims/emailaddress");
    requestClaim.setClaimType(emailURI);
    requestClaims.add(requestClaim);
    requestClaim = new Claim();
    URI fooURI = new URI("http://schemas.xmlsoap.org/ws/2005/05/identity/claims/foobar");
    requestClaim.setClaimType(fooURI);
    requestClaim.setOptional(true);
    requestClaims.add(requestClaim);
    ClaimsParameters claimsParameters = new ClaimsParameters();
    claimsParameters.setPrincipal(new GuestPrincipal("127.0.0.1"));
    List<URI> supportedClaims = claimsHandler.getSupportedClaimTypes();
    assertEquals(3, supportedClaims.size());
    ProcessedClaimCollection claimsCollection = claimsHandler.retrieveClaimValues(requestClaims, claimsParameters);
    assertEquals(3, claimsCollection.size());
    for (ProcessedClaim claim : claimsCollection) {
        if (claim.getClaimType().equals(nameURI)) {
            assertEquals(1, claim.getValues().size());
            assertEquals("Guest", claim.getValues().get(0));
        } else if (claim.getClaimType().equals(emailURI)) {
            assertEquals(3, claim.getValues().size());
            List<Object> values = claim.getValues();
            assertEquals("Guest@guest.com", values.get(0));
            assertEquals("someguy@somesite.com", values.get(1));
            assertEquals("somedude@cool.com", values.get(2));
        } else if (claim.getClaimType().equals("IpAddress")) {
            assertEquals("127.0.0.1", claim.getValues().get(0));
        }
        assertFalse(claim.getClaimType().equals(fooURI));
    }
    claimsParameters = new ClaimsParameters();
    claimsCollection = claimsHandler.retrieveClaimValues(requestClaims, claimsParameters);
    assertEquals(2, claimsCollection.size());
    claimsParameters = new ClaimsParameters();
    claimsParameters.setPrincipal(new CustomTokenPrincipal("SomeValue"));
    claimsCollection = claimsHandler.retrieveClaimValues(requestClaims, claimsParameters);
    assertEquals(2, claimsCollection.size());
}
Also used : CustomTokenPrincipal(org.apache.wss4j.common.principal.CustomTokenPrincipal) ProcessedClaimCollection(org.apache.cxf.sts.claims.ProcessedClaimCollection) ProcessedClaim(org.apache.cxf.sts.claims.ProcessedClaim) GuestPrincipal(ddf.security.principal.GuestPrincipal) List(java.util.List) ClaimCollection(org.apache.cxf.rt.security.claims.ClaimCollection) ProcessedClaimCollection(org.apache.cxf.sts.claims.ProcessedClaimCollection) URI(java.net.URI) 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)

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