Search in sources :

Example 56 with ClaimCollection

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

the class TestAttributeFileClaimsHandler method setup.

@Before
public void setup() throws IOException {
    System.setProperty("ddf.home", "testdir");
    InputStream resourceAsStream = TestAttributeFileClaimsHandler.class.getResourceAsStream("/users.attributes");
    userFile = temporaryFolder.newFile("users.attributes");
    FileOutputStream userFileOs = new FileOutputStream(userFile);
    IOUtils.copy(resourceAsStream, userFileOs);
    attributeFileClaimsHandler.setAttributeFileLocation(userFile.getAbsolutePath());
    attributeFileClaimsHandler.init();
    claimCollection = new ClaimCollection();
    Claim claim = new Claim();
    claim.setClaimType(URI.create("test"));
    claimCollection.add(claim);
    Claim claim1 = new Claim();
    claim1.setClaimType(URI.create("test1"));
    claimCollection.add(claim1);
    Claim claim2 = new Claim();
    claim2.setClaimType(URI.create("reg"));
    claimCollection.add(claim2);
    adminClaimsParameters = new ClaimsParameters();
    Principal principal = mock(Principal.class);
    when(principal.getName()).thenReturn("admin");
    adminClaimsParameters.setPrincipal(principal);
    localhostClaimsParameters = new ClaimsParameters();
    principal = mock(Principal.class);
    when(principal.getName()).thenReturn("localhost");
    localhostClaimsParameters.setPrincipal(principal);
    regexClaimsParameters = new ClaimsParameters();
    principal = mock(Principal.class);
    when(principal.getName()).thenReturn("myhostname");
    regexClaimsParameters.setPrincipal(principal);
    unknownClaimsParameters = new ClaimsParameters();
    principal = mock(Principal.class);
    when(principal.getName()).thenReturn("unknown");
    unknownClaimsParameters.setPrincipal(principal);
}
Also used : InputStream(java.io.InputStream) FileOutputStream(java.io.FileOutputStream) ClaimCollection(org.apache.cxf.rt.security.claims.ClaimCollection) ProcessedClaimCollection(org.apache.cxf.sts.claims.ProcessedClaimCollection) 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) Before(org.junit.Before)

Example 57 with ClaimCollection

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

the class TestPropertyFileClaimsHandler method testRetrieveClaimValues.

@Test
public void testRetrieveClaimValues() {
    PropertyFileClaimsHandler propertyFileClaimsHandler = new PropertyFileClaimsHandler();
    propertyFileClaimsHandler.setPropertyFileLocation("/users.properties");
    propertyFileClaimsHandler.setRoleClaimType("http://myroletype");
    ClaimCollection claimCollection = new ClaimCollection();
    Claim claim = new Claim();
    try {
        claim.setClaimType(new URI("http://myroletype"));
    } catch (URISyntaxException e) {
        fail("Could not create URI");
    }
    claimCollection.add(claim);
    ClaimsParameters claimsParameters = mock(ClaimsParameters.class);
    Principal principal = mock(Principal.class);
    when(principal.getName()).thenReturn("admin");
    when(claimsParameters.getPrincipal()).thenReturn(principal);
    ProcessedClaimCollection processedClaimCollection = propertyFileClaimsHandler.retrieveClaimValues(claimCollection, claimsParameters);
    assertEquals(1, processedClaimCollection.size());
    assertEquals(4, processedClaimCollection.get(0).getValues().size());
}
Also used : ProcessedClaimCollection(org.apache.cxf.sts.claims.ProcessedClaimCollection) URISyntaxException(java.net.URISyntaxException) ClaimCollection(org.apache.cxf.rt.security.claims.ClaimCollection) ProcessedClaimCollection(org.apache.cxf.sts.claims.ProcessedClaimCollection) URI(java.net.URI) Claim(org.apache.cxf.rt.security.claims.Claim) X500Principal(javax.security.auth.x500.X500Principal) KerberosPrincipal(javax.security.auth.kerberos.KerberosPrincipal) Principal(java.security.Principal) ClaimsParameters(org.apache.cxf.sts.claims.ClaimsParameters) Test(org.junit.Test)

Example 58 with ClaimCollection

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

the class TestPropertyFileClaimsHandler method testRetrieveClaimsValuesNullPrincipal.

@Test
public void testRetrieveClaimsValuesNullPrincipal() {
    PropertyFileClaimsHandler claimsHandler = new PropertyFileClaimsHandler();
    ClaimsParameters claimsParameters = new ClaimsParameters();
    ClaimCollection claimCollection = new ClaimCollection();
    ProcessedClaimCollection processedClaims = claimsHandler.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 59 with ClaimCollection

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

the class ClaimsManager method filterHandlerClaims.

private ClaimCollection filterHandlerClaims(ClaimCollection claims, List<URI> handlerClaimTypes) {
    ClaimCollection supportedClaims = new ClaimCollection();
    supportedClaims.setDialect(claims.getDialect());
    for (Claim claim : claims) {
        if (handlerClaimTypes.contains(claim.getClaimType())) {
            supportedClaims.add(claim);
        }
    }
    return supportedClaims;
}
Also used : ClaimCollection(org.apache.cxf.rt.security.claims.ClaimCollection) Claim(org.apache.cxf.rt.security.claims.Claim)

Example 60 with ClaimCollection

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

the class LDAPClaimsTest method testRetrieveRolesForBob.

@org.junit.Test
public void testRetrieveRolesForBob() throws Exception {
    LdapGroupClaimsHandler claimsHandler = (LdapGroupClaimsHandler) appContext.getBean("testGroupClaimsHandlerOtherUsers");
    ClaimsManager claimsManager = new ClaimsManager();
    claimsManager.setClaimHandlers(Collections.singletonList(claimsHandler));
    String user = props.getProperty("otherClaimUser");
    Assert.assertNotNull(user, "Property 'claimUser' not configured");
    ClaimCollection requestedClaims = new ClaimCollection();
    Claim claim = new Claim();
    URI roleURI = URI.create("http://schemas.xmlsoap.org/ws/2005/05/identity/claims/role");
    claim.setClaimType(roleURI);
    requestedClaims.add(claim);
    ClaimsParameters params = new ClaimsParameters();
    params.setPrincipal(new CustomTokenPrincipal(user));
    ProcessedClaimCollection retrievedClaims = claimsManager.retrieveClaimValues(requestedClaims, params);
    Assert.assertTrue(retrievedClaims.size() == 1);
    Assert.assertTrue(retrievedClaims.get(0).getClaimType().equals(roleURI));
    Assert.assertTrue(retrievedClaims.get(0).getValues().size() == 2);
}
Also used : LdapGroupClaimsHandler(org.apache.cxf.sts.claims.LdapGroupClaimsHandler) CustomTokenPrincipal(org.apache.wss4j.common.principal.CustomTokenPrincipal) ProcessedClaimCollection(org.apache.cxf.sts.claims.ProcessedClaimCollection) ClaimsManager(org.apache.cxf.sts.claims.ClaimsManager) 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)

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