use of net.sf.acegisecurity.providers.UsernamePasswordAuthenticationToken in project alfresco-repository by Alfresco.
the class TestAuthenticationServiceImpl method setCurrentUser.
/**
* Explicitly set the current user to be authenticated.
*
* @param userName
* String
* @return Authentication
*/
public Authentication setCurrentUser(String userName) throws AuthenticationException {
if (userName == null) {
throw new AuthenticationException("Null user name");
}
try {
UserDetails ud = null;
if (userName.equals(SYSTEM_USER_NAME)) {
GrantedAuthority[] gas = new GrantedAuthority[1];
gas[0] = new GrantedAuthorityImpl("ROLE_SYSTEM");
ud = new User(SYSTEM_USER_NAME, "", true, true, true, true, gas);
} else if (userName.equalsIgnoreCase(AuthenticationUtil.getGuestUserName())) {
GrantedAuthority[] gas = new GrantedAuthority[0];
ud = new User(AuthenticationUtil.getGuestUserName().toLowerCase(), "", true, true, true, true, gas);
} else {
ud = getUserDetails(userName);
}
UsernamePasswordAuthenticationToken auth = new UsernamePasswordAuthenticationToken(ud, "", ud.getAuthorities());
auth.setDetails(ud);
auth.setAuthenticated(true);
return setCurrentAuthentication(auth);
} catch (net.sf.acegisecurity.AuthenticationException ae) {
throw new AuthenticationException(ae.getMessage(), ae);
}
}
Aggregations