【发布时间】:2018-02-11 05:52:11
【问题描述】:
我已经设置了 Spring Boot 安全依赖项
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
我还在我的 WebSecurityConfigAdapter 中限制了一些页面,例如
http
.authorizeRequests()
.antMatchers("/").permitAll()
.antMatchers("/admin/**").hasRole("ADMIN")
(我还完成了 UsersDetailsService 等的各种其他样板设置)
在我使用 html/thymeleaf 的传统前端中,如果用户已登录,我可以简单地执行类似这样的操作来显示注销链接。
<form sec:authorize="isAuthenticated()" id="frmlogout" th:action="@{/logout}" method="post" class="form-inline">
<a href="javascript:{}" onclick="document.getElementById('frmlogout').submit(); return false;">Logout</a>
</form>
问题是,如何从我的 react .js 类中进行类似的“isAuthenticated()”检查(以及角色检查)?有没有可能?
期望的结果是我可以将注销按钮添加到我的导航栏,该导航栏在我的 .js 类中定义。
【问题讨论】:
标签: spring reactjs spring-mvc spring-boot spring-security