Answer the question
In order to leave comments, you need to log in
How to add page access restrictions in spring?
Hello. Help, please solve the problem.
Wrote a simple spring-based application that has 3 pages. Each page has a servlet attached to it. Like this.
@RequestMapping(value = "/home", method = RequestMethod.POST)
public String login(@Validated Beans user, Model model) {
model.addAttribute("userName", user);
return "user";
}
Answer the question
In order to leave comments, you need to log in
I have, for example, written like this. By /users/** - there is signup, signin, signout, so everyone has access.
The rest is for registered users only. You can write other rules.
@Override
protected void configure(HttpSecurity http) throws Exception {
http
.authorizeRequests()
.antMatchers("/ping", "/users/**")
.permitAll()
.anyRequest()
.hasRole("USER");
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question