Results 1 to 10 of 16

Thread: Custom Authentication Provider and User Details

Threaded View

  1. #11

    Default

    I am unable to paste my code in so there may be some typos.
    CustomProviderAuthentication
    Code:
    public class CustomAuthenticationProvider implements AuthenticationProvider {
    
    @Resource DataSource dataSource;
    
    public Authentication authenticate(Authentication authentication) throws AuthenticationException {
    UsernamePasswordAuthenticationToken auth = (UsernamePasswordAuthenticationToken) authentication;
    String username = String.valueOf(auth.getPrincipal());
    String password = String.valueOf(auth.getCredentials());
    Connection conn = null;
    try{
       //In this call I use the username and password and pass them to my oracle proxy connection and then try to    connect to the database 
       conn = dataSourceAdapter.doGetConnection(username, password);
    }
    catch(SQLException sqle) {
     throw new BadCredentialsException(LoginException.handleLoginErrors(sqle));
    }
    //I use the same connection to get the granted authorities, user's role and user's id
    return new UsernamePasswordAuthenticationToken(username, password,new GrantedAuthority[] {new GrantedAuthorityImpl(userRole)});
    }
    It works well for testing the database connection.
    Last edited by kmsheph; Dec 23rd, 2008 at 04:21 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •