you can use the isUserInRole method of the HttpServletRequest object.
something like:
public String createForm(HttpSession session, HttpServletRequest request, ModelMap modelMap) {
if (request.isUserInRole("ROLE_ADMIN")) {
// code here
}
}
More Related Contents:
- Filter invoke twice when register as Spring bean
- How to get active user’s UserDetails
- How To Inject AuthenticationManager using Java Configuration in a Custom Filter
- When using Spring Security, what is the proper way to obtain current username (i.e. SecurityContext) information in a bean?
- How to disable spring security for particular url
- How to manually set an authenticated user in Spring Security / SpringMVC
- Can Spring Security use @PreAuthorize on Spring controllers methods?
- How to disable ‘X-Frame-Options’ response header in Spring Security?
- How to enable HTTP response caching in Spring Boot
- “Defective token detected” error (NTLM not Kerberos) with Kerberos/Spring Security/IE/Active Directory
- 401 instead of 403 with Spring Boot 2
- How to redirect to the homepage if the user accesses the login page after being logged in?
- multiple authentication mechanisms in a single app using java config
- How to get the current logged in user object from spring security?
- Customize authentication failure response in Spring Security using AuthenticationFailureHandler
- Unit testing with Spring Security
- Spring Security with roles and permissions
- spring web, security + web.xml + mvc dispatcher + Bean is created twice
- How to apply Spring Security filter only on secured endpoints?
- Spring security’s SecurityContextHolder: session or request bound?
- Securing Spring Boot API with API key and secret
- Creating multiple HTTP sections in Spring Security Java Config
- PartialResultException when authenticating with Spring Security and JavaConfig
- How to reload authorities on user update with Spring Security
- How do I disable resolving login parameters passed as url parameters / from the url
- How do I add method based security to a Spring Boot project?
- Spring security @PreAuthorize hasRole() properties injection
- How to secure REST API with Spring Boot and Spring Security?
- Why BCryptPasswordEncoder from Spring generate different outputs for same input?
- Cross-Origin Resource Sharing with Spring Security