Search in sources :

Example 1 with GuestPrincipal

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;
}
Also used : GuestPrincipal(ddf.security.principal.impl.GuestPrincipal) SecurityAssertion(ddf.security.assertion.SecurityAssertion)

Example 2 with GuestPrincipal

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));
}
Also used : GuestPrincipal(ddf.security.principal.impl.GuestPrincipal) Test(org.junit.Test)

Example 3 with GuestPrincipal

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;
}
Also used : DefaultSecurityAssertionBuilder(ddf.security.assertion.impl.DefaultSecurityAssertionBuilder) AttributeDefault(ddf.security.assertion.impl.AttributeDefault) SimplePrincipalCollection(org.apache.shiro.subject.SimplePrincipalCollection) SecurityAssertion(ddf.security.assertion.SecurityAssertion) URI(java.net.URI) Date(java.util.Date) AttributeStatementDefault(ddf.security.assertion.impl.AttributeStatementDefault) GuestPrincipal(ddf.security.principal.impl.GuestPrincipal) ArrayList(java.util.ArrayList) List(java.util.List) HashMap(java.util.HashMap) Map(java.util.Map) Principal(java.security.Principal) GuestPrincipal(ddf.security.principal.impl.GuestPrincipal)

Aggregations

GuestPrincipal (ddf.security.principal.impl.GuestPrincipal)3 SecurityAssertion (ddf.security.assertion.SecurityAssertion)2 AttributeDefault (ddf.security.assertion.impl.AttributeDefault)1 AttributeStatementDefault (ddf.security.assertion.impl.AttributeStatementDefault)1 DefaultSecurityAssertionBuilder (ddf.security.assertion.impl.DefaultSecurityAssertionBuilder)1 URI (java.net.URI)1 Principal (java.security.Principal)1 ArrayList (java.util.ArrayList)1 Date (java.util.Date)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1 SimplePrincipalCollection (org.apache.shiro.subject.SimplePrincipalCollection)1 Test (org.junit.Test)1