Spring cloud security services combat -6-7jwt micro Revamping

Limit the flow of transformation.





Also be careful not to declare a Spring Bean
in the above statement Rateliiter

if we can get permission to continue to go down, no authority returns, to many request of the error message.

Applied to the filter chain


Spring Scurity filter before loading the first filter chain.

Start the gateway, the test


Copy acquired token.





Go the limit, then the certified filter, the filter is certified to write spring secutiry



eventually returned to filter the log, the log update out.

Carding

左边本质上都是过滤器,虽然最后一个不是叫做什么什么filter。右边都是自己写的一些组件。组件的作用是改变过滤器的行为。
在过滤器链上,绿色是我们自己写的,蓝色是Spring Security提供的,自己写的组件注入到Spring的过滤器里面,来改变或者是增强Spring 自己的过滤器里面的行为。

1.限流
2.从jwt或者其他的这些令牌里面,把当前的用户 身份提取出来
3。审计日志
4.从名字看是异常的转换过滤器。本身并没有任何业务逻辑。他的作用就是catch后面这个Interceptor抛出的来的异常,
5.作用就是判断权限,我们写的permissonSerice最终就是在这里生效的。

一个请求过来,他会按照这个顺序,经过所有的过滤器。当然还有一些其他的过滤器,就是SpringSecurity过滤器链上的其他过滤器。这些和我们核心讲 的没关系,我们就把它忽略了。但是跟我讲的安全相关的,就是核心的几个安全相关的过滤器都列出来了。按照这个顺序,请求会传过过滤器。

我们会把自己的权限的判断的逻辑放在PermissionService里面。然后把PermissionService给到一个表达式处理器WebSecurityExpressionHandler。
表达式处理器给到我们的SecurityInterceptor


最终我们写的表达式是交给WebSecurityExpressionHandler来处理,然后它又交给了PermissionService

PermissionService里面我们又写了如果你没有带token,就是你当前是个匿名用户 我就会抛出异常,如果你是个可以认出来的合法用户,那么你有没有权限,也会有个逻辑来判断。如果你没有权限,这里就会抛出相应的错误。就是Exception

抛出Exception会被ExceptionTranslationFilter捕获住,捕获住以后,会根据你抛出来的异常类型去调相应的处理器。在整个安全的里面一共就两种异常,一种是401一种是403

41就交给了GatewayAuthenticationEntryPoint来处理。你的令牌有问题或者是你没传令牌。

另一种是你的身份认证过了,但是当前这个请求你没权限,这是403交给GatewayAccessDeniedHandler来处理。

这两个组件都是注到ExceptionTranslationFilter来进行相应的处理的


同时GatewayAuthenticationEntryPoint也会被注到 OAuth2ClientAuthenticationProcessingFilter。有种情况是你的令牌传的不对,根本解析不了。

这就是jwt改造后在网关上做的所有事情。以及它的整个逻辑。

结束



 

Guess you like

Origin www.cnblogs.com/wangjunwei/p/11985555.html