【发布时间】:2018-07-09 18:21:04
【问题描述】:
我希望有一个主页,然后是登录页面,由于登录页面未经授权,根据我的理解,该页面变为 UnSecured。代码如下:
主页.html
<h2>1. Visit <a th:href="@{/admin}">Admin page (Spring Security protected, Need Admin Role)</a></h2>`enter code here`
<h2>2. Visit <a th:href="@{/user}">User page (Spring Security protected, Need User Role)</a></h2>
<h2>3. Visit <a th:href="@{/about}">Normal page</a></h2>
这里的登录页面将变得不安全,因为它没有得到spring boot security的授权。我该如何解决以下情况
http.csrf().disable()
.authorizeRequests()
.antMatchers("/", "/home", "/about").permitAll()
.antMatchers("/admin/**").hasAnyRole("ADMIN")
.antMatchers("/user/**").hasAnyRole("USER")
.anyRequest().authenticated()
.and()
.formLogin()
.loginPage("/login")
.permitAll()
.and()
.logout()
.permitAll()
.and()
.exceptionHandling().accessDeniedHandler(accessDeniedHandler);
'
请帮忙。使用上述方法使用 Spring Boot Security 是否可行?
【问题讨论】:
标签: spring-boot spring-security