有趣的文章
一次http请求的过程

http无状态的解决方法
简要
cookie
指的是 浏览器永久存储的一种数据,仅仅是浏览器实现的一种数据存储功能。
session
一种抽象概念-会话: 表示一个人和你交谈的时候, 你知道这个人是张三还是李四。
session通常需要借助cookie来实现:
浏览器在cookie存储sessionId,而 服务器在内存中存储所有用户的sessionId。
当浏览器发送请求时会携带 cookie,服务器在处理请求时会取出cookie中的sessionId,验证 sessionId的有效性,继而判断用户的合法性。
session方式 有以下缺点:
- 服务器不好横向扩展,每个服务器需要同步所有的session信息
- 需要存储所有的session信息,占用内存
token
token实现
token 是对session方式的一种改进。
服务器使用秘钥对userId进行加密计算得到一个token,并把token传给浏览器。浏览器每次请求时,会将token一起发送过来。服务器只需再使用秘钥对userId进行加密计算得到一个新的token,然后比较新旧token。如果新旧token一致,说明用户是合法的。
特点是 利用cpu计算时间 换取 session存储空间 的方法。


token过期
详细
0_spark_on_yarn
在 spark on yarn 模式下,spark-submit.sh 的源码流程。
spark_on_yarn架构
Client Mode

Cluster Mode

auth2
ApplicationFilterChain: tomcat 过滤器链
OAuth2ClientContextFilter: 处理 UserRedirectRequiredException 异常,并重定向
OAuth2ClientAuthenticationProcessingFilter:
使某个用户的session立即失效(转)
当修改用户的相关权限后,每次都需要客户手动重新登录,这样的实现方式一点也不优美。本篇转载了《Spring - Expiring all Sessions of a User》
获取PreAuthorize认证异常
1 | @PreAuthorize("hasAuthority('ROLE_ZZZZ')") |
当 hasAuthority('ROLE_ZZZZ')认证失败时,会 throw AccessDeniedException 。
原本的期望是 该异常被自定义的 AccessDeniedHandler处理。但发现并非如此,他会直接抛出500异常。
在google 找到答案:
The access-denied-handler is used by the ExceptionTranslationFilter in case of an AccessDeniedException. However, the org.springframework.web.servlet.DispatcherServlet was first trying the handle the exception. Specifically, I had a org.springframework.web.servlet.handler.SimpleMappingExceptionResolver defined with a defaultErrorView. Consequently, the SimpleMappingExceptionResolver was consuming the exception by redirecting to an appropriate view, and consequently, there was no exception left to bubble up to the ExceptionTranslationFilter.
The fix was rather simple. Configure the SimpleMappingExceptionResolver to ignore all AccessDeniedException.
1 | <bean class="org.springframework.web.servlet.handler.SimpleMappingExceptionResolver"> |
Now, whenever an AccessDeniedException is thrown, the resolver ignores it and allows it to bubble up the stack to the ExceptionTranslationFilter which then calls upon the access-denied-handler to handle the exception.