Page 2 of 2 FirstFirst 12
Results 11 to 16 of 16

Thread: Custom Authentication Provider and User Details

  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.

  2. #12
    Join Date
    Dec 2008
    Posts
    8

    Default

    Is it possible to post your userDetailsService related java implementation classes, please?

    Thanks.
    Last edited by mdebac; Dec 30th, 2008 at 02:56 AM.

  3. #13
    Join Date
    Dec 2008
    Posts
    8

    Default

    do you have implmentation for grants?

    new GrantedAuthorityImpl(userRole)

    Thanks.

  4. #14
    Join Date
    Sep 2006
    Posts
    23

    Default

    Hi rhart,

    as you mentioned in the code of class UserDetailsServiceImpl

    Code:
    public UserDetails loadUserByUsername(String username)
          throws UsernameNotFoundException, DataAccessException {
        try {
          User user = userApplicationService.findUserByUsername(username);
          return assembler.buildAuthenticatedUserDTOFromUser(user);
        } catch (NoResultException e) {
          throw new UsernameNotFoundException(e.getLocalizedMessage());
        }
      }
    this method must return UserDetais object, I am not sure how can i do that....
    Please help me as i am new to this.

    Thanks in advance

  5. #15
    Join Date
    Mar 2009
    Posts
    2

    Post modify the password

    Is what possible to modify the password before the authentication.

  6. #16
    Join Date
    Mar 2009
    Posts
    1

    Default security.xml

    I've created a extended class of 创DaoAuthenticationProvider创 and initialized in security.xml:

    <bean id="myAuthenticationProvider" class="es.gva.cit.terceros.security.provider.MyAut henticationProvider">
    <security:custom-authentication-provider />
    </bean>

    But the definition of bean can't be accessible because of:

    SAXParseException: cvc-elt.1: Cannot find the declaration of element 'beans'

    What can I do to declare the bean element in the 创security.xml创 file?
    Where I have to declare the new bean? And if i have to add this new bean to a 创authenticationManager创 bean and declare it too.

Posting Permissions

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