Thanks for answering, I changed the populator
Code:
<beans:bean id="ldapAuthProvider"
class="com.packtpub.springsecurity.security.CustomLdapAuthentication">
<beans:constructor-arg>
<beans:bean
class="org.springframework.security.ldap.authentication.BindAuthenticator">
<beans:constructor-arg ref="contextSource" />
<beans:property name="userDnPatterns">
<beans:list>
<beans:value>uid={0},ou=people</beans:value>
</beans:list>
</beans:property>
</beans:bean>
</beans:constructor-arg>
<beans:constructor-arg>
<beans:bean
class="com.packtpub.springsecurity.security.MyAuthoritiesPopulator">
<beans:constructor-arg ref="contextSource" />
<beans:constructor-arg value="ou=people" />
<beans:property name="groupRoleAttribute" value="ou" />
</beans:bean>
</beans:constructor-arg>
</beans:bean>
but this error is shown:
org.springframework.beans.factory.BeanCreationExce ption: Error creating bean with name 'ldapAuthProvider' defined in ServletContext resource [/WEB-INF/dogstore-security.xml]: Cannot create inner bean 'com.packtpub.springsecurity.security.MyAuthoritie sPopulator#11bed71' of type [com.packtpub.springsecurity.security.MyAuthorities Populator] while setting constructor argument; nested exception is org.springframework.beans.factory.BeanCreationExce ption: Error creating bean with name 'com.packtpub.springsecurity.security.MyAuthoritie sPopulator#11bed71' defined in ServletContext resource [/WEB-INF/dogstore-security.xml]: Could not resolve matching constructor (hint: specify index/type/name arguments for simple parameters to avoid type ambiguities)
I think that something is missing here
Code:
<beans:constructor-arg>
<beans:bean
class="com.packtpub.springsecurity.security.MyAuthoritiesPopulator">
<beans:constructor-arg ref="contextSource" />
<beans:constructor-arg value="ou=people" />
<beans:property name="groupRoleAttribute" value="ou" />
</beans:bean>
</beans:constructor-arg
MyAuthoritiesPopulator.java is :
Code:
public class MyAuthoritiesPopulator implements LdapAuthoritiesPopulator {
@Autowired
JdbcTemplate template;
@Override
public List<GrantedAuthority> getGrantedAuthorities(
DirContextOperations userData, String username) {
List<GrantedAuthority> userPerms = template.query(
"select role from roles where username = ?",
new String[] { username }, new RowMapper<GrantedAuthority>() {
/**
* We're assuming here that you're using the standard
* convention of using the role prefix "ROLE_" to mark
* attributes which are supported by Spring Security's
* RoleVoter.
*/
public GrantedAuthority mapRow(ResultSet rs, int rowNum)
throws SQLException {
return new GrantedAuthorityImpl("ROLE_"
+ rs.getString(1));
}
});
return userPerms;
}
}
Any idea?