Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jdbc-user-service adding fields to the SQL

this is sort of close to my previous question but i have been looking up how to do it

Current code in applicationContext-security.xml:

<authentication-manager alias="authenticationManager">
    <!-- DAO Based Security -->
    <authentication-provider>
        <password-encoder hash="sha-256" />
        <jdbc-user-service data-source-ref="dataSource"
            users-by-username-query="SELECT user_name AS username, user_password AS password, enabled FROM user where user_name=?"
            authorities-by-username-query="SELECT user_name as username, R.name as authority FROM user U, roles R WHERE U.roles = R.Id AND user_name=?"/>
    </authentication-provider>
</authentication-manager>

What i want to change:

<authentication-manager alias="authenticationManager">
    <!-- DAO Based Security -->
    <authentication-provider>
        <password-encoder hash="sha-256" />
        <jdbc-user-service data-source-ref="dataSource"
            users-by-username-query="SELECT user_name AS username, user_password AS password, id, location, userFirstName, userLastName, enabled FROM user where user_name=?"
            authorities-by-username-query="SELECT user_name as username, R.name as authority FROM user U, roles R WHERE U.roles = R.Id AND user_name=?"/>
    </authentication-provider>
</authentication-manager>

basically i want to retrieve 4 more fields from the database

the issue i have at the moment is i do not know what i need to do, i've attempted to customize userDetails and userDetailsService but i cannot seem to get that to work using the code from this website http://www.theserverside.com/tip/-Spring-Security-Customizing-Your-User-and-Authorization-in

like image 211
adam2510 Avatar asked Oct 23 '22 18:10

adam2510


1 Answers

You can not do that with the original org.springframework.security.core.userdetails.jdbc.JdbcDaoImpl (thats the class behind jdbc-user-service). You need to subclass it or, need to implement your complete own UserDetailsService.

like image 89
Ralph Avatar answered Nov 02 '22 08:11

Ralph