private UsernamePasswordAuthenticationToken generateAuthenticationToken( final String username, final String password) { final AuthenticationResult authResult = authenticateUser(username, password); // Grant access final List<GrantedAuthority> authorities = new ArrayList<GrantedAuthority>(); authorities.add(new SimpleGrantedAuthority(authResult.getRole().name())); final UsernamePasswordAuthenticationToken auth = new UsernamePasswordAuthenticationToken(username, password, authorities); auth.setDetails(authResult); return auth; }
private AuthenticationResult authenticateUser(final String username, final String password) { // Authenticate in Code Center final AuthenticationResult authResult = userAuthenticationService.authenticate(username, password); if (!authResult.isAuthenticated()) { logger.debug("Authentication failed"); throw new AuthenticationServiceException(authResult.getMessage()); } return authResult; }