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);
}
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());
}
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)));
}
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;
}
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);
}
Aggregations