I have a Spring application (Spring version 2.5.6.SEC01, Spring Security version 2.0.5) with the following setup (this is based off of this question):
In the security-config.xml file, I have the following configuration:
<http>
<!-- Restrict URLs based on role -->
<intercept-url pattern="/WEB-INF/jsp/login.jsp*" access="ROLE_ANONYMOUS" />
<intercept-url pattern="/WEB-INF/jsp/header.jsp*" access="ROLE_ANONYMOUS" />
<intercept-url pattern="/WEB-INF/jsp/footer.jsp*" access="ROLE_ANONYMOUS" />
<intercept-url pattern="/login*" access="ROLE_ANONYMOUS" />
<intercept-url pattern="/index.jsp" access="ROLE_ANONYMOUS" />
<intercept-url pattern="/logoutSuccess*" access="ROLE_ANONYMOUS" />
<intercept-url pattern="/css/**" filters="none" />
<intercept-url pattern="/images/**" filters="none" />
<intercept-url pattern="/**" access="ROLE_ANONYMOUS" />
<anonymous />
<form-login login-page="/login.jsp"/>
</http>
<beans:bean id="myUserDetailsService" class="com.example.login.MyUserDetailsService">
<beans:property name="dataSource" ref="dataSource" />
<custom-authentication-provider />
</beans:bean>
<authentication-provider user-service-ref="myUserDetailsService" />
The com.example.login.MyUserDetailsService class is defined:
public class MyUserDetailsService extends SimpleJdbcDaoSupport implements UserDetailsService {
@Override
public UserDetails loadUserByUsername(String userName) throws UsernameNotFoundException,
DataAccessException {
logger.info("MyUserDetailsService.loadUserByUsername: Entered method. Username [" + userName + "]");
...
}
}
But I'm not seeing this log line. How do I define a custom UserDetailsService so I can set the security roles? I don't even need a custom service, but having this in the security-config.xml
<authentication-provider> <jdbc-user-service data-source-ref="dataSource" />
</authentication-provider>
wasn't setting the role even though I have the users and authorities tables. How can I set the Spring Security Roles?