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);
}
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);
}
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;
}
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;
}
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);
}
Aggregations