use of ddf.security.claims.impl.ClaimsCollectionImpl in project ddf by codice.
the class AttributeQueryClaimsHandler method getAttributes.
/**
* Gets the attributes for the supplied user from the external attribute store. Returns null if
* the AttributeQueryClient is null.
*
* @param nameId used for the request.
* @return The collection of attributes retrieved from the external attribute store.
* @throws URISyntaxException
*/
protected ClaimsCollection getAttributes(String nameId) throws URISyntaxException {
ClaimsCollection claimCollection = new ClaimsCollectionImpl();
LOGGER.debug("Sending AttributeQuery Request.");
AttributeQueryClient attributeQueryClient;
Assertion assertion;
try {
attributeQueryClient = createAttributeQueryClient(simpleSign, externalAttributeStoreUrl, issuer, destination);
if (attributeQueryClient == null) {
return null;
}
assertion = attributeQueryClient.query(nameId);
if (assertion != null) {
createClaims(claimCollection, assertion);
}
} catch (AttributeQueryException ex) {
LOGGER.info("Error occurred in AttributeQueryClient, did not retrieve response. Set log level for \"org.codice.ddf.security.claims.attributequery.common\" to DEBUG for more information.");
LOGGER.debug("Error occurred in AttributeQueryClient, did not retrieve response.", ex);
}
return claimCollection;
}
use of ddf.security.claims.impl.ClaimsCollectionImpl in project ddf by codice.
the class CertificateClaimsHandler method retrieveClaims.
@Override
public ClaimsCollection retrieveClaims(ClaimsParameters parameters) {
ClaimsCollection claimsColl = new ClaimsCollectionImpl();
Map<String, Object> additionalProperties = parameters.getAdditionalProperties();
if (additionalProperties != null) {
if (additionalProperties.containsKey(SubjectOperations.EMAIL_ADDRESS_CLAIM_URI)) {
buildClaim(claimsColl, emailClaim, additionalProperties.get(SubjectOperations.EMAIL_ADDRESS_CLAIM_URI));
}
if (additionalProperties.containsKey(SubjectOperations.COUNTRY_CLAIM_URI)) {
buildClaim(claimsColl, countryClaim, additionalProperties.get(SubjectOperations.COUNTRY_CLAIM_URI));
}
}
return claimsColl;
}
use of ddf.security.claims.impl.ClaimsCollectionImpl in project ddf by codice.
the class PKIRealmTest method setup.
@Before
public void setup() {
List<ClaimsHandler> claimsHandlers = new ArrayList<>();
claimsHandlers.add(mock(ClaimsHandler.class));
claimsHandlers.add(mock(ClaimsHandler.class));
ClaimsCollection claims1 = new ClaimsCollectionImpl();
ClaimImpl email1 = new ClaimImpl("email");
email1.addValue("test@example.com");
claims1.add(email1);
ClaimsCollection claims2 = new ClaimsCollectionImpl();
ClaimImpl email2 = new ClaimImpl("email");
email2.addValue("tester@example.com");
claims2.add(email2);
when(claimsHandlers.get(0).retrieveClaims(any())).thenReturn(claims1);
when(claimsHandlers.get(1).retrieveClaims(any())).thenReturn(claims2);
pkiRealm.setClaimsHandlers(claimsHandlers);
}
use of ddf.security.claims.impl.ClaimsCollectionImpl in project ddf by codice.
the class AttributeQueryClaimsHandler method retrieveClaims.
/**
* Retrieves claims from the external attribute store.
*
* @param parameters The subject to get claims for.
* @return The collection of claims or an empty collection if there are no security claims.
* @throws URISyntaxException
*/
@Override
public ClaimsCollection retrieveClaims(ClaimsParameters parameters) {
ClaimsCollection claimCollection = new ClaimsCollectionImpl();
Principal principal = parameters.getPrincipal();
if (principal == null) {
return claimCollection;
}
String nameId = getNameId(principal);
try {
if (!StringUtils.isEmpty(nameId)) {
ClaimsCollection securityClaimCollection = getAttributes(nameId);
// If security claim collection came back empty, return an empty claim collection.
if (!CollectionUtils.isEmpty(securityClaimCollection)) {
claimCollection.addAll(securityClaimCollection);
}
}
} catch (URISyntaxException e) {
LOGGER.info(ERROR_RETRIEVING_ATTRIBUTES + "Set log level to DEBUG for more information.", externalAttributeStoreUrl, nameId);
LOGGER.debug(ERROR_RETRIEVING_ATTRIBUTES, externalAttributeStoreUrl, nameId, e);
}
return claimCollection;
}
use of ddf.security.claims.impl.ClaimsCollectionImpl 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;
}
Aggregations