use of ddf.security.claims.ClaimsCollection in project ddf by codice.
the class PropertyFileClaimsHandler method retrieveClaims.
@Override
public ClaimsCollection retrieveClaims(ClaimsParameters parameters) {
ClaimsCollection claimsColl = new ClaimsCollectionImpl();
Principal principal = parameters.getPrincipal();
String user = getUser(principal);
if (user == null) {
LOGGER.info("Could not determine user name, possible authentication error. Returning no claims.");
return claimsColl;
}
String userAttributes = userMapping.get(user);
if (userAttributes != null) {
String[] attributes = userAttributes.split(",");
Claim c = new ClaimImpl(roleClaimType);
for (int i = 1; i < attributes.length; i++) {
c.addValue(attributes[i]);
}
claimsColl.add(c);
}
Claim idClaim = new ClaimImpl(idClaimType);
idClaim.addValue(user);
claimsColl.add(idClaim);
return claimsColl;
}
use of ddf.security.claims.ClaimsCollection in project ddf by codice.
the class UsersAttributesFileClaimsHandler method retrieveClaims.
@Override
public ClaimsCollection retrieveClaims(ClaimsParameters claimsParameters) {
ClaimsCollection claimsColl = new ClaimsCollectionImpl();
Principal principal = claimsParameters.getPrincipal();
if (principal == null) {
return claimsColl;
}
String name;
if (principal instanceof X500Principal) {
name = subjectOperations.getCommonName((X500Principal) principal);
} else {
name = principal.getName();
}
Map<String, Set<String>> userMap = json.get(name);
if (userMap == null) {
userMap = attemptToFindAMatchingRegexFormatUserEntry(principal, json);
}
if (userMap == null) {
return claimsColl;
}
for (Map.Entry<String, Set<String>> claimEntry : userMap.entrySet()) {
Set<String> attributeValue = claimEntry.getValue();
Claim c = new ClaimImpl(claimEntry.getKey());
if (attributeValue != null) {
attributeValue.forEach(c::addValue);
claimsColl.add(c);
}
}
return claimsColl;
}
use of ddf.security.claims.ClaimsCollection in project ddf by codice.
the class UsersAttributesFileClaimsHandlerTest method testRetrieveClaimValuesTestHostname.
@Test
public void testRetrieveClaimValuesTestHostname() throws IOException {
// given
System.setProperty(SystemBaseUrl.INTERNAL_HOST, "testHostname");
final UsersAttributesFileClaimsHandler usersAttributesFileClaimsHandler = new UsersAttributesFileClaimsHandler();
usersAttributesFileClaimsHandler.setUsersAttributesFileLocation(getPathForValidTestAttributesFile());
final ClaimsCollection ClaimsCollection = getClaimsCollectionForValidTestAttributesFile();
final Principal principal = mock(Principal.class);
when(principal.getName()).thenReturn("testHostname");
final ClaimsParameters testHostnameClaimsParameters = new ClaimsParametersImpl(principal, new HashSet<>(), new HashMap<>());
// when
final ClaimsCollection processedClaims = usersAttributesFileClaimsHandler.retrieveClaims(testHostnameClaimsParameters);
// then
assertThat(processedClaims, containsInAnyOrder(allOf(hasProperty("name", is("Clearance")), hasProperty("values", containsInAnyOrder("U"))), allOf(hasProperty("name", is("CountryOfAffiliation")), hasProperty("values", containsInAnyOrder("USA"))), allOf(hasProperty("name", is("classification")), hasProperty("values", containsInAnyOrder("U"))), allOf(hasProperty("name", is("http://schemas.xmlsoap.org/ws/2005/05/identity/claims/emailaddress")), hasProperty("values", containsInAnyOrder("system@testHostname"))), allOf(hasProperty("name", is("ownerProducer")), hasProperty("values", containsInAnyOrder("USA"))), allOf(hasProperty("name", is("releasableTo")), hasProperty("values", containsInAnyOrder("USA"))), allOf(hasProperty("name", is("FineAccessControls")), hasProperty("values", containsInAnyOrder("SCI1", "SCI2"))), allOf(hasProperty("name", is("disseminationControls")), hasProperty("values", containsInAnyOrder("NF")))));
}
use of ddf.security.claims.ClaimsCollection in project ddf by codice.
the class UsersAttributesFileClaimsHandlerTest method testNoMatchRetrieveClaimValues.
@Test
public void testNoMatchRetrieveClaimValues() throws IOException {
// given
System.setProperty(SystemBaseUrl.INTERNAL_HOST, "testHostname");
final UsersAttributesFileClaimsHandler usersAttributesFileClaimsHandler = new UsersAttributesFileClaimsHandler();
usersAttributesFileClaimsHandler.setUsersAttributesFileLocation(getPathForValidTestAttributesFile());
final ClaimsCollection ClaimsCollection = getClaimsCollectionForValidTestAttributesFile();
final Principal principal = mock(Principal.class);
when(principal.getName()).thenReturn("someNameThat'sNotInTheUsersAttributesFile");
final ClaimsParameters unknownClaimsParameters = new ClaimsParametersImpl(principal, new HashSet<>(), new HashMap<>());
// when
final ClaimsCollection processedClaims = usersAttributesFileClaimsHandler.retrieveClaims(unknownClaimsParameters);
// then
assertThat(processedClaims, is(empty()));
}
use of ddf.security.claims.ClaimsCollection in project ddf by codice.
the class AttributeQueryClaimsHandlerTest method testRetrieveClaimValues.
@Test
public void testRetrieveClaimValues() throws Exception {
ClaimsCollection processedClaimCollection = retrieveClaimValues();
// Test that the claims were created and mapped correctly.
assertThat(processedClaimCollection.size(), is(equalTo(3)));
assertThat(processedClaimCollection.get(0).getName(), is(equalTo("Role")));
assertThat((String) processedClaimCollection.get(0).getValues().get(0), is(equalTo("Guest-hasMapping")));
assertThat(processedClaimCollection.get(1).getName(), is(equalTo("NameIdentifier")));
assertThat((String) processedClaimCollection.get(1).getValues().get(0), is(equalTo("Name-hasMapping")));
// Does not have an attribute mapping.
assertThat(processedClaimCollection.get(2).getName(), is(equalTo("Email")));
assertThat((String) processedClaimCollection.get(2).getValues().get(0), is(equalTo("email")));
}
Aggregations