コード例 #1
0
 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;
 }
コード例 #2
0
  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;
  }