Announcement Announcement Module
No announcement yet.
extending LdapAuthenticationProvider + using HibernateDaoSupport Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • extending LdapAuthenticationProvider + using HibernateDaoSupport

    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:
    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);
    And the Hibernate implementation class is:
    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);
                GrantedAuthority temp = new GrantedAuthorityImpl(userRole.getRoleID());
            GrantedAuthority[] extraAuthorities = new GrantedAuthority[tempGrantedAuthorities.size()]; 
    		for (int i = 0; i < extraAuthorities.length; i++) {
        public List getUserRoleList(String userID) throws DataAccessException
        	logger.debug("getUserRoleList: " + userID);
    		return getHibernateTemplate().findByNamedQueryAndNamedParam("getRolesAuthenticated", "user_id", userID);
    I tried injecting the sessionFactory like the following but another error "No constructor with 0 arguments defined in class ''" comes out:
    	<bean id="appUserDetailsLdapImpl" class="">
    		<property name="sessionFactory" ref="sessionFactory" />
    Grateful if somebody could beam a light on this issue. Thanks!

  • #2
    Please post Spring Security questions in the Spring Security forum.