Search in sources :

Example 6 with BaseAuthenticationToken

use of org.codice.ddf.security.handler.BaseAuthenticationToken in project ddf by codice.

the class UsernamePasswordRealmTest method testSupportsGood.

@Test
public void testSupportsGood() {
    BaseAuthenticationToken authenticationToken = mock(BaseAuthenticationToken.class);
    when(authenticationToken.getCredentials()).thenReturn("");
    when(authenticationToken.getType()).thenReturn(AuthenticationTokenType.USERNAME);
    boolean supports = upRealm.supports(authenticationToken);
    assertTrue(supports);
}
Also used : BaseAuthenticationToken(org.codice.ddf.security.handler.BaseAuthenticationToken) Test(org.junit.Test)

Example 7 with BaseAuthenticationToken

use of org.codice.ddf.security.handler.BaseAuthenticationToken in project ddf by codice.

the class UsernamePasswordRealmTest method testSupportsBad.

@Test
public void testSupportsBad() {
    BaseAuthenticationToken authenticationToken = mock(BaseAuthenticationToken.class);
    boolean supports = upRealm.supports(authenticationToken);
    assertFalse(supports);
    when(authenticationToken.getType()).thenReturn(AuthenticationTokenType.PKI);
    supports = upRealm.supports(authenticationToken);
    assertFalse(supports);
    when(authenticationToken.getType()).thenReturn(AuthenticationTokenType.USERNAME);
    authenticationToken = mock(BaseAuthenticationToken.class);
    supports = upRealm.supports(authenticationToken);
    assertFalse(supports);
    when(authenticationToken.getCredentials()).thenReturn(new Object());
    supports = upRealm.supports(authenticationToken);
    assertFalse(supports);
    when(authenticationToken.getCredentials()).thenReturn("");
    supports = upRealm.supports(authenticationToken);
    assertFalse(supports);
}
Also used : BaseAuthenticationToken(org.codice.ddf.security.handler.BaseAuthenticationToken) Test(org.junit.Test)

Example 8 with BaseAuthenticationToken

use of org.codice.ddf.security.handler.BaseAuthenticationToken in project ddf by codice.

the class Security method getSubject.

/**
 * Gets the {@link Subject} given a user name and password.
 *
 * @param username username
 * @param password password
 * @return {@link Subject} associated with the user name and password provided
 */
@Override
public Subject getSubject(String username, String password, String ip) {
    AuthenticationTokenFactory tokenFactory = createBasicTokenFactory();
    AuthenticationToken token = tokenFactory.fromUsernamePassword(username, password, ip);
    SecurityManager securityManager = getSecurityManager();
    if (securityManager != null) {
        try {
            // TODO - Change when class is a service
            if (token instanceof BaseAuthenticationToken) {
                ((BaseAuthenticationToken) token).setAllowGuest(true);
            }
            return securityManager.getSubject(token);
        } catch (SecurityServiceException | RuntimeException e) {
            LOGGER.info("Unable to request subject for {} user.", username, e);
        }
    }
    return null;
}
Also used : SecurityServiceException(ddf.security.service.SecurityServiceException) AuthenticationToken(org.apache.shiro.authc.AuthenticationToken) BaseAuthenticationToken(org.codice.ddf.security.handler.BaseAuthenticationToken) GuestAuthenticationToken(org.codice.ddf.security.handler.GuestAuthenticationToken) SecurityManager(ddf.security.service.SecurityManager) BaseAuthenticationToken(org.codice.ddf.security.handler.BaseAuthenticationToken) AuthenticationTokenFactory(org.codice.ddf.security.handler.AuthenticationTokenFactory)

Example 9 with BaseAuthenticationToken

use of org.codice.ddf.security.handler.BaseAuthenticationToken in project ddf by codice.

the class PKIRealm method supports.

/**
 * Determine if the supplied token is supported by this realm.
 */
@Override
public boolean supports(AuthenticationToken token) {
    if (!(token instanceof BaseAuthenticationToken)) {
        LOGGER.debug("The supplied authentication token is not an instance of BaseAuthenticationToken. Sending back not supported.");
        return false;
    }
    BaseAuthenticationToken authToken = (BaseAuthenticationToken) token;
    Object credentials = authToken.getCredentials();
    Object principal = authToken.getPrincipal();
    if (authToken.getType() != AuthenticationTokenType.PKI) {
        LOGGER.debug("The supplied authentication token has null/empty credentials. Sending back no supported.");
        return false;
    }
    if (credentials instanceof X509Certificate[] && principal instanceof X500Principal) {
        LOGGER.debug("Token {} is supported by {}.", token.getClass(), PKIRealm.class.getName());
        return true;
    }
    return false;
}
Also used : BaseAuthenticationToken(org.codice.ddf.security.handler.BaseAuthenticationToken) X500Principal(javax.security.auth.x500.X500Principal) X509Certificate(java.security.cert.X509Certificate)

Example 10 with BaseAuthenticationToken

use of org.codice.ddf.security.handler.BaseAuthenticationToken in project ddf by codice.

the class GuestRealmTest method testSupportsBaseGuestNotAllowed.

@Test
public void testSupportsBaseGuestNotAllowed() {
    BaseAuthenticationToken baseAuthenticationToken = new MockBaseAuthenticationToken("principal", "credentials", "0.0.0.0");
    baseAuthenticationToken.setAllowGuest(false);
    boolean supports = guestRealm.supports(baseAuthenticationToken);
    assertFalse(supports);
}
Also used : BaseAuthenticationToken(org.codice.ddf.security.handler.BaseAuthenticationToken) Test(org.junit.Test)

Aggregations

BaseAuthenticationToken (org.codice.ddf.security.handler.BaseAuthenticationToken)17 Test (org.junit.Test)9 X509Certificate (java.security.cert.X509Certificate)4 X500Principal (javax.security.auth.x500.X500Principal)4 SecurityAssertion (ddf.security.assertion.SecurityAssertion)3 SecurityServiceException (ddf.security.service.SecurityServiceException)3 AuthenticationInfo (org.apache.shiro.authc.AuthenticationInfo)3 AuthenticationToken (org.apache.shiro.authc.AuthenticationToken)3 GuestAuthenticationToken (org.codice.ddf.security.handler.GuestAuthenticationToken)3 Attribute (ddf.security.assertion.Attribute)2 SecurityManager (ddf.security.service.SecurityManager)2 PrincipalCollection (org.apache.shiro.subject.PrincipalCollection)2 SimplePrincipalCollection (org.apache.shiro.subject.SimplePrincipalCollection)2 AuthenticationException (org.codice.ddf.platform.filter.AuthenticationException)2 AuthenticationTokenFactory (org.codice.ddf.security.handler.AuthenticationTokenFactory)2 HandlerResultImpl (org.codice.ddf.security.handler.HandlerResultImpl)2 HandlerResult (org.codice.ddf.security.handler.api.HandlerResult)2 Subject (ddf.security.Subject)1 AttributeStatement (ddf.security.assertion.AttributeStatement)1 SecurityAssertionSaml (ddf.security.assertion.saml.impl.SecurityAssertionSaml)1