use of org.apache.ftpserver.usermanager.UsernamePasswordAuthentication in project ddf by codice.
the class UserManagerImplTest method nullShiroSubject.
@Test(expected = AuthenticationFailedException.class)
public void nullShiroSubject() throws SecurityServiceException, AuthenticationFailedException {
UsernamePasswordAuthentication upa = mock(UsernamePasswordAuthentication.class);
when(upa.getUsername()).thenReturn(USER);
when(upa.getPassword()).thenReturn(PASSWORD);
when(securityManager.getSubject(upa)).thenReturn(null);
userManager.authenticate(upa);
}
use of org.apache.ftpserver.usermanager.UsernamePasswordAuthentication in project ddf by codice.
the class UserManagerImplTest method shiroUnsupportedAuthentication.
@Test(expected = AuthenticationFailedException.class)
public void shiroUnsupportedAuthentication() throws SecurityServiceException, AuthenticationFailedException {
UsernamePasswordAuthentication upa = mock(UsernamePasswordAuthentication.class);
when(upa.getUsername()).thenReturn(USER);
when(upa.getPassword()).thenReturn(PASSWORD);
when(securityManager.getSubject(any(Authentication.class))).thenThrow(SecurityServiceException.class);
userManager.authenticate(upa);
}
use of org.apache.ftpserver.usermanager.UsernamePasswordAuthentication in project ddf by codice.
the class UserManagerImplTest method authenticationSuccess.
@Test
public void authenticationSuccess() throws SecurityServiceException, AuthenticationFailedException {
UsernamePasswordAuthentication upa = mock(UsernamePasswordAuthentication.class);
Subject subject = mock(Subject.class);
when(upa.getUsername()).thenReturn(USER);
when(upa.getPassword()).thenReturn(PASSWORD);
when(securityManager.getSubject(any(Authentication.class))).thenReturn(subject);
userManager.setKarafLocalRoles("admin,localhost");
assertEquals(userManager.createUser(USER, subject), userManager.authenticate(upa));
}
use of org.apache.ftpserver.usermanager.UsernamePasswordAuthentication in project ddf by codice.
the class UserManagerImpl method authenticate.
/**
* @param authentication The {@link Authentication} that proves the users identity. {@link org.apache.ftpserver.usermanager.AnonymousAuthentication} is not permitted
* @return {@link User} upon successful authorization
* @throws AuthenticationFailedException upon unsuccessful authorization
*/
public User authenticate(Authentication authentication) throws AuthenticationFailedException {
UPAuthenticationToken upAuthenticationToken;
String username;
User user;
if (authentication instanceof UsernamePasswordAuthentication) {
username = ((UsernamePasswordAuthentication) authentication).getUsername();
upAuthenticationToken = new UPAuthenticationToken(username, ((UsernamePasswordAuthentication) authentication).getPassword());
try {
Subject subject = securityManager.getSubject(upAuthenticationToken);
if (subject != null) {
if (!doesExist(username)) {
user = createUser(username, subject);
} else {
user = getUserByName(username);
updateUserSubject(user, subject);
}
return user;
}
} catch (SecurityServiceException e) {
LOGGER.info("Failure to retrieve subject.", e);
throw new AuthenticationFailedException("Failure to retrieve subject.");
}
}
throw new AuthenticationFailedException("Authentication failed");
}
Aggregations