use of ddf.security.assertion.impl.AttributeDefault in project ddf by codice.
the class GuestRealm method createPrincipalFromToken.
private SimplePrincipalCollection createPrincipalFromToken(BaseAuthenticationToken token) {
SimplePrincipalCollection principals = new SimplePrincipalCollection();
DefaultSecurityAssertionBuilder defaultSecurityAssertionBuilder = new DefaultSecurityAssertionBuilder();
Set<Map.Entry<URI, List<String>>> entries = claimsMap.entrySet();
AttributeStatementDefault attributeStatement = new AttributeStatementDefault();
for (Map.Entry<URI, List<String>> entry : entries) {
AttributeDefault attribute = new AttributeDefault();
attribute.setName(entry.getKey().toString());
for (String value : entry.getValue()) {
attribute.addValue(value);
}
attributeStatement.addAttribute(attribute);
}
defaultSecurityAssertionBuilder.addAttributeStatement(attributeStatement);
defaultSecurityAssertionBuilder.userPrincipal(new GuestPrincipal(token.getIpAddress()));
defaultSecurityAssertionBuilder.issuer("local");
defaultSecurityAssertionBuilder.notBefore(new Date());
// We don't really care how long it is "valid" for
defaultSecurityAssertionBuilder.notOnOrAfter(new Date(new Date().getTime() + 14400000L));
defaultSecurityAssertionBuilder.token(token);
defaultSecurityAssertionBuilder.tokenType(GUEST_TOKEN_TYPE);
SecurityAssertion securityAssertion = defaultSecurityAssertionBuilder.build();
Principal principal = securityAssertion.getPrincipal();
if (principal != null) {
principals.add(principal.getName(), getName());
}
principals.add(securityAssertion, getName());
return principals;
}
use of ddf.security.assertion.impl.AttributeDefault in project ddf by codice.
the class PKIRealm method mergeClaimsToAttributes.
private void mergeClaimsToAttributes(AttributeStatement attributeStatement, ClaimsCollection claims) {
for (Claim claim : claims) {
Attribute newAttr = new AttributeDefault();
newAttr.setName(claim.getName());
newAttr.setValues(claim.getValues());
boolean found = false;
for (Attribute attribute : attributeStatement.getAttributes()) {
if (attribute.getName().equals(newAttr.getName())) {
found = true;
for (String value : newAttr.getValues()) {
attribute.addValue(value);
}
}
}
if (!found) {
attributeStatement.addAttribute(newAttr);
}
}
}
use of ddf.security.assertion.impl.AttributeDefault in project ddf by codice.
the class UsernamePasswordRealm method mergeClaimsToAttributes.
private void mergeClaimsToAttributes(AttributeStatement attributeStatement, ClaimsCollection claims) {
for (Claim claim : claims) {
Attribute newAttr = new AttributeDefault();
newAttr.setName(claim.getName());
newAttr.setValues(claim.getValues());
boolean found = false;
for (Attribute attribute : attributeStatement.getAttributes()) {
if (attribute.getName().equals(newAttr.getName())) {
found = true;
for (String value : newAttr.getValues()) {
attribute.addValue(value);
}
}
}
if (!found) {
attributeStatement.addAttribute(newAttr);
}
}
}
Aggregations