关于spring-security:springsecurity的认证鉴权acloauth20

30次阅读

共计 2086 个字符,预计需要花费 6 分钟才能阅读完成。

次要就是一些拦截器链,@PreAuthorize,@PreFilter,@PostAuthorize 和 @PostFilter

认证 AuthenticationManager

基于列表的 ProviderManager 实现,每个处理器都有机会解决验证胜利或失败

AuthenticationProvider 获取适配的处理器

鉴权 AccessDecisionManager

基于投票的 AccessDecisionManager 实现,投票决策管理器 AccessDecisionVoter

根本实现:

RoleVoter 投票 ROLE_结尾的权限

AuthenticatedVoter 用于辨别匿名、齐全身份验证和记住我身份验证的用户

RoleHierarchyVoter 层级角色,容许您配置哪些角色 admin(或权限)应该包含其余角色 user(或权限)

AfterInvocationManager

调用后处理,批改平安对象调用理论返回的对象的办法

acl(域对象)访问控制列表

能够应用 PermissionEvaluator 接口 基于表达式的访问控制 hasPermission(target, permission)

boolean hasPermission(Authentication authentication, Object targetDomainObject, Object permission); 第一种用于拜访被管制的域对象曾经加载的状况。

boolean hasPermission(Authentication authentication, Serializable targetId, String targetType, Object permission); 第二个版本用于未加载对象但其标识符已知的状况。

旨在表达式零碎和 Spring Security 的 ACL 零碎之间架起桥梁,容许您依据形象权限指定对域对象的受权束缚。它对 ACL 模块没有显式依赖,因而您能够依据须要将其替换为代替实现。

在 spring-security-acl.jar 里有建表语句,能够开箱即用 AclService,AclEntryVoter 等类

oauth2 协定资源服务器和资源受权服务器

有两个我的项目,spring-security-oauth2 和 spring-security 我的项目下的 oauth2 模块,目前 spring 把性能都迁徙到 spring-security 了,举荐应用 spring-security。

spring-security 的 oauth2.0 客户端反对是通过 oauth2Client() DSL(配置,fromLogin 那里)办法实现的。资源服务器反对是通过 oauth2ResourceServer() DSL 实现的,并且提供了一个 OAuth2AuthorizedClientService 开箱即用的类。受权服务器目前 security 还没有集成 oauth2.0 的,所以只能先用 oauth2.0 的,应用 @EnableAuthorizationServer 注解

提供了 @RegisteredOAuth2AuthorizedClient 注解,将受权的客户端存储在本人的 OAuth2AuthorizedClientRepository。

ClientRegistrationRepository 来示意客户端,能够通过 Spring Security DSL 提供。或者,这些也能够通过 Spring Boot 进行配置。

能够定义多个 SecurityFilterChain, 依据 matches 申请走不同的过滤器链

  @Bean
  @Order(Ordered.HIGHEST_PRECEDENCE)
  public SecurityFilterChain systemSecurityFilterChain(HttpSecurity http) throws Exception {OAuth2AuthorizationServerConfiguration.applyDefaultSecurity(http);
        http.getConfigurer(OAuth2AuthorizationServerConfigurer.class)
                .authorizationEndpoint(config->{OAuth2AuthorizationEndpointConfigurer configurer = (OAuth2AuthorizationEndpointConfigurer) config;
 
        });
        return http.build();}
 
    @Bean
    public SecurityFilterChain clientSecurityFilterChain(HttpSecurity http) throws Exception {http.authorizeRequests()
                .requestMatchers(requestMatchers).permitAll()
                .anyRequest().denyAll().and()
                .formLogin().and();
        return http.build();}

正文完
 0