spring security记录

4版本

登录跳转

自定义自己的成功失败handler

生成session后 set-cookie响应头用js取不到?

https://github.com/axios/axios/issues/295
https://developer.mozilla.org/zh-CN/docs/Web/HTTP/Headers/Set-Cookie

解决方式:把sessionId写到响应体里面..

session过期异常 返回状态码401 前端ajax捕获不了302

客户端持有一个sessionid (存在cookie中), 服务器集群使用共享session存储的基本原理是:每次从sessionid去取,
客户端sessionid没有过期是不变的, 如果一直有操作,session的过期时间一直会保持最新

无操作的最大时长在哪设置

其中一个生效

  1. @EnableRedisHttpSession(maxInactiveIntervalInSeconds = 3600)
  2. server.session.timeout=

spring session生成的cookie name

401错误重定向原理

tomcat中 response.sendError调用时, 会自动forward到另一个路径, 然后再走一次dispatchServlet返回了spring定义的消息体
org.apache.catalina.core.StandardHostValve#status

如何修改spring error定义的消息体
能否禁用tomcat forward?

permitAll就是不生效 http.csrf().disable()

集成prometheus actuator时,配置安全密码只拦截actuator的Endpoint, 但是其他所有的接口都不能调用了

http.authorizeRequests()
                .requestMatchers(EndpointRequest.toAnyEndpoint()).authenticated()
                .anyRequest().permitAll()
            .and()
                .httpBasic();

调试很长时间,filter没过,一直返回403, spring security框架引入了好多个filter,到底是哪个filter过不去,默认还没有任何日志信息,卧槽

十几个filter 撸一遍 就只看到request url被强制转到了/error

设置所有的springframework log为debug,原来时CsrfFilter这个把请求直接重定向到/error
我加个密码拦截怎么还和跨域有关系了, 浪费一下午时间(官方文档没有任何提示,NMD)
https://www.jianshu.com/p/e6655328b211

    @Override
    protected void configure(HttpSecurity http) throws Exception {
        http.authorizeRequests()
                .requestMatchers(EndpointRequest.toAnyEndpoint()).authenticated()
                .anyRequest().permitAll()
            .and()
                .httpBasic();
        // csrf disable is required !!!
        http.csrf().disable();
    }
原文地址:https://www.cnblogs.com/yszzu/p/11672051.html