User is able to access secured URLs without being prompted for loging in. Below is the example of such a URL for which user should be prompted to log in but it is accessed without authentication.
http://localhost:9090/HospitalProject/web/patient/home
Security configuration:
@Configuration
@EnableWebSecurity
public class SecurityConfig extends WebSecurityConfigurerAdapter {
@Autowired
Environment env;
@Autowired
public void configureAuthentication(AuthenticationManagerBuilder auth) throws Exception {
auth
.inMemoryAuthentication()
.withUser("root")
.password("root")
.roles("ADMIN");
auth
.inMemoryAuthentication()
.withUser("notroot")
.password("notroot")
.roles("SUPER_ADMIN");
}
@Override
protected void configure(HttpSecurity http) throws Exception {
http
.csrf().disable()
.authorizeRequests()
.antMatchers("/web/login").permitAll()
.antMatchers("/web/**").access("hasRole('ADMIN') or hasRole('SUPER_ADMIN')")
.and()
.formLogin()
.loginPage("/web/login")
.loginProcessingUrl("/web/login")
.usernameParameter("username")
.passwordParameter("password")
.and()
.logout().logoutSuccessUrl("/login?logout");
}
}
Security initializer:
public class SecurityWebApplicationIntializer extends AbstractSecurityWebApplicationInitializer {
public SecurityWebApplicationIntializer() {
super(SecurityConfig.class);
}
}
Controller:
@Controller
public class MasterController {
@GetMapping(value={"/", "/web/login"})
public ModelAndView loginForm(){
ModelAndView mv = new ModelAndView("login");
mv.addObject("loginForm", new LoginForm());
return mv;
}
}
Any clue what's missing?