Hi I have implemented SecurityFilterChain as bean as latest way, I am loading urls and assigned roles from database and added at ant machers, it loads fine for the first time from the database and works well and protect urls according to role.
But when after login, when I update roles for the specific urls, without restart, update does not work. After restart spring boot project, last update works. so how can I fix it? Here is my code:
@Bean
public SecurityFilterChain filterChain(HttpSecurity httpSecurity) throws Exception {
httpSecurity.authorizeRequests((authz) ->
authz.antMatchers(HttpMethod.GET, "/admin").hasRole("ADMIN")
);
geturlListfromDatabase(httpSecurity);//it does not refresh after reassign role
httpSecurity.authorizeRequests().antMatchers("/user").hasRole("USER")
.and()
.formLogin()
.loginPage("/signin")
.defaultSuccessUrl("/dashboard")
.permitAll()
.and()
.logout()
.logoutRequestMatcher(new AntPathRequestMatcher("/signout"))
.logoutSuccessUrl("/signin?signout")
.invalidateHttpSession(true)
.clearAuthentication(true)
.deleteCookies()
.permitAll()
.and()
.exceptionHandling()
.accessDeniedHandler(accessDeniedHandler)
.and()
.csrf(c -> c
.csrfTokenRepository(CookieCsrfTokenRepository.withHttpOnlyFalse())
);
httpSecurity.authorizeRequests().anyRequest().authenticated();
return httpSecurity.build();
}