use of ddf.security.principal.impl.GuestPrincipal in project ddf by codice.
the class SessionManagementServiceImplTest method getGuestAssertion.
private SecurityAssertion getGuestAssertion() {
SecurityAssertion guestAssertion = mock(SecurityAssertionDefault.class);
GuestPrincipal guestPrincipal = mock(GuestPrincipal.class);
when(guestAssertion.getWeight()).thenReturn(SecurityAssertion.NO_AUTH_WEIGHT);
when(guestPrincipal.getName()).thenReturn("guest");
when(guestAssertion.getPrincipal()).thenReturn(guestPrincipal);
when(guestAssertion.getNotOnOrAfter()).thenReturn(Date.from(Instant.now().plus(Duration.ofHours(4))));
return guestAssertion;
}
use of ddf.security.principal.impl.GuestPrincipal in project ddf by codice.
the class SubjectUtilsTest method testGuestDisplayName.
@Test
public void testGuestDisplayName() {
ddf.security.Subject subject = getSubjectWithPrincipal(new GuestPrincipal("127.0.0.1"));
assertEquals(SubjectUtils.GUEST_DISPLAY_NAME, subjectUtils.getName(subject, null, true));
}
use of ddf.security.principal.impl.GuestPrincipal 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;
}
Aggregations