【发布时间】:2018-05-25 12:52:45
【问题描述】:
我正在尝试为安全路由 /admin 配置 Spring Security(仅允许 ADMIN 角色访问),但我想允许所有其他路由而不对我的配置文件中的所有路由进行硬编码。
这是我的spring安全程序配置:
http.
authorizeRequests()
.mvcMatchers("/", "/login", "/registration", "/news/**").permitAll()
.mvcMatchers("/admin/**").hasAuthority("ADMIN").anyRequest().authenticated()
.and()
.csrf().disable()
.formLogin()
.loginPage("/login")
.failureUrl("/login?error=true")
.defaultSuccessUrl("/admin/news/")
.usernameParameter("username")
.passwordParameter("password")
.and()
.logout()
.logoutRequestMatcher(new AntPathRequestMatcher("/logout"))
.logoutSuccessUrl("/")
.and()
.exceptionHandling()
.accessDeniedPage("/access-denied");
如何允许所有路由并仅保护 /admin 路由和子路由?
当我改变这行配置时
.mvcMatchers("/", "/login", "/registration", "/news/**").permitAll()
到
.mvcMatchers("/**").permitAll()
我的 /admin 路由变得不安全,我可以在没有登录的情况下打开。 怎么办?
【问题讨论】:
标签: spring-mvc security spring-boot spring-security