Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/spring-boot/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Spring boot 第二节:授权=";isAuthenticated();触发器“;创建SecureRandom实例“;在“a”中;“无国籍”;SpringBootWeb应用程序_Spring Boot_Spring Security_Thymeleaf_Stateless - Fatal编程技术网

Spring boot 第二节:授权=";isAuthenticated();触发器“;创建SecureRandom实例“;在“a”中;“无国籍”;SpringBootWeb应用程序

Spring boot 第二节:授权=";isAuthenticated();触发器“;创建SecureRandom实例“;在“a”中;“无国籍”;SpringBootWeb应用程序,spring-boot,spring-security,thymeleaf,stateless,Spring Boot,Spring Security,Thymeleaf,Stateless,我的Spring Boot web应用程序是无状态的。代替会话cookie,我在身份验证时创建一个JWTcookie,并在每个后续请求中检查它。实施是有效的。作为参考,在其自定义websecurityConfigureAdapter类中,您可以找到如下配置: @覆盖 受保护的无效配置(HttpSecurity http)引发异常{ http .会议管理() .sessionCreationPolicy(sessionCreationPolicy.STATELESS)//禁用默认会话cookie;

我的Spring Boot web应用程序是无状态的。代替会话cookie,我在身份验证时创建一个JWTcookie,并在每个后续请求中检查它。实施是有效的。作为参考,在其自定义
websecurityConfigureAdapter
类中,您可以找到如下配置:

@覆盖
受保护的无效配置(HttpSecurity http)引发异常{
http
.会议管理()
.sessionCreationPolicy(sessionCreationPolicy.STATELESS)//禁用默认会话cookie;我们将改用JWT身份验证cookie。
.及()
.addFilter(新的JWTAuthenticationFilter(authenticationManager())//此筛选器拦截登录,对用户进行身份验证,并在cookie中创建JWT令牌以授权后续请求。。
.addFilterBefore(new JWTAuthorizationFilter(),UsernamePasswordAuthenticationFilter.class)//此筛选器在后续请求时从cookie读取JWT令牌,并授权用户(或不授权用户)。
.formLogin()
.及()
//等等。。。
当用户第一次访问主页(或除登录页面以外的任何页面)时,我一直注意到日志中有一个警告

因为我没有会话ID,所以我不需要这个SecureRandom实例。看起来我也在将一个新的JSESSIONID cookie附加到响应上!通过选择性地注释内容,我发现页脚中的“注销”按钮正在触发会话的创建。罪魁祸首如下:

<footer>
    <form sec:authorize="isAuthenticated()" th:action="@{/logout}" method="post">
        <input type="submit" value="Sign Out"/>
    </form>
</footer>


这里有一个问题:如何在我的Thymeleaf模板中检查用户是否经过身份验证,而不触发意外创建会话?我希望返回541毫秒!

最后,这似乎是Tomcat的事情,而不是Spring引导的事情。禁用它的可能性不大。最后,这似乎是这将是一个Tomcat的东西,而不是一个Spring Boot的东西。没有太多机会禁用它。
<footer>
    <form sec:authorize="isAuthenticated()" th:action="@{/logout}" method="post">
        <input type="submit" value="Sign Out"/>
    </form>
</footer>