Spring security jsp tag authorize
can be used to check against the url:
<sec:authorize url="/details" var="allow_url_details"/>
It uses WebInvocationPrivilegeEvaluator for evaluation. The rules has been taken from HttpSecurity config:
@Bean
public SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
http.authorizeHttpRequests(auth -> auth
.requestMatchers("/details").hasAnyRole("OPERATOR","TECH")
.requestMatchers("/static/*", "/*", "/favicon/*").permitAll()
.anyRequest().authenticated()
);
// ...
}
From other side, I have @EnableMethodSecurity(jsr250Enabled = true)
, and on contoller there is @RolesAllowed:
@Controller
public class DetailController extends ControllerTemplate {
@GetMapping("/details")
@RolesAllowed({"OPERATOR", "TECH"})
public String list() {
return "details/list";
}
So, we have two places of security allowance declaration:
- in
http.authorizeHttpRequests
(to get<sec:authorize url="/details">
work) - and with @GetMapping (or @Controller)
Can I (How to) use only JSR 250 way of defining allowed urls, so I can use sec:authorize
tag without configuring the same urls in HttpSecurity setup?