I am using spring security to authenticate users.
AdminController.java
@Controller
@Secured("ROLE_ADMIN")
public class AdminController {
@RequestMapping("/list")
public ModelAndView listProductController(@ModelAttribute("pForm") Product product, ModelMap model)
{
return new ModelAndView("list", model);
}
}
I the above code, I want only admins can visit the url http://localhost/Pgga/list
, but even without login, I am able to visit this page.
spring-security.xml
<beans:beans xmlns="http://www.springframework.org/schema/security"
xmlns:beans="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/security
http://www.springframework.org/schema/security/spring-security.xsd">
<global-method-security secured-annotations="enabled" />
<!-- enable use-expressions -->
<http auto-config="true" use-expressions="true">
<intercept-url pattern="/admin*" access="ROLE_ADMIN" />
<!-- access denied page -->
<access-denied-handler error-page="/403" />
<form-login
login-page="/login"
login-processing-url="/login.do"
default-target-url="/index"
authentication-failure-url="/login?error"
username-parameter="emailID"
password-parameter="password" />
<logout
logout-success-url="/login?logout"
delete-cookies="JSESSIONID"
invalidate-session="true" />
<csrf/>
</http>
<authentication-manager>
<authentication-provider user-service-ref="userAuthenticationProvider">
<password-encoder hash="plaintext" />
</authentication-provider>
</authentication-manager>
</beans:beans>
How can I allow only admins to enter admin area?