Hi Folks,
I find problem using HibernateDaoSupport when I try to get user information from database. My original design was getting ldap authentication through acegi security api and getting user role from my own database.
What I did was extending the LdapAuthenticationProvider and overriding the createUserDetails function inside.
My problem is that while executing the getHibernateTemplate(), a NullPointerException is triggered.
Here is my java class:
And the Hibernate implementation class is:Code:public class MyLdapAuthenticationProvider extends LdapAuthenticationProvider { ... protected UserDetails createUserDetails(LdapUserDetails ldapUser, String username, String password) { UserDetails userDetails = super.createUserDetails(ldapUser, username, password); return new AppUserDetailsLdapImpl((LdapUserDetails) userDetails); } }
I tried injecting the sessionFactory like the following but another error "No constructor with 0 arguments defined in class 'com.xyz.AppUserDetailsLdapImpl'" comes out:Code:public class AppUserDetailsLdapImpl extends HibernateDaoSupport implements LdapUserDetails { private final LdapUserDetails ldapUserDetails; private List userRoleList; public AppUserDetailsLdapImpl(final LdapUserDetails ldapUserDetails) { this.ldapUserDetails = ldapUserDetails; Attributes attributes = this.ldapUserDetails.getAttributes(); String userName = this.ldapUserDetails.getUsername(); LdapUserDetailsImpl.Essence user = new LdapUserDetailsImpl.Essence(ldapUserDetails); ArrayList tempGrantedAuthorities = new ArrayList(); userRoleList = getUserRoleList(userName); Iterator it = userRoleList.iterator(); while (it.hasNext()) { UserRole userRole = (UserRole)it.next(); GrantedAuthority temp = new GrantedAuthorityImpl(userRole.getRoleID()); tempGrantedAuthorities.add(temp); } GrantedAuthority[] extraAuthorities = new GrantedAuthority[tempGrantedAuthorities.size()]; tempGrantedAuthorities.toArray(extraAuthorities); for (int i = 0; i < extraAuthorities.length; i++) { user.addAuthority(extraAuthorities[i]); } } public List getUserRoleList(String userID) throws DataAccessException { logger.debug("getUserRoleList: " + userID); return getHibernateTemplate().findByNamedQueryAndNamedParam("getRolesAuthenticated", "user_id", userID); } ...
Grateful if somebody could beam a light on this issue. Thanks!Code:<bean id="appUserDetailsLdapImpl" class="com.fimat.security.util.AppUserDetailsLdapImpl"> <property name="sessionFactory" ref="sessionFactory" /> </bean>


Reply With Quote