houzhongjian
2024-07-23 d9f9ba31913bb9f5053ad78109e8a3c1c00f1e6a
iailab-framework/iailab-common-security/src/main/java/com/iailab/framework/security/config/IailabSecurityAutoConfiguration.java
@@ -1,5 +1,6 @@
package com.iailab.framework.security.config;
import cn.hutool.extra.spring.SpringUtil;
import com.iailab.framework.security.core.aop.PreAuthenticatedAspect;
import com.iailab.framework.security.core.context.TransmittableThreadLocalSecurityContextHolderStrategy;
import com.iailab.framework.security.core.filter.TokenAuthenticationFilter;
@@ -10,6 +11,7 @@
import com.iailab.framework.web.core.handler.GlobalExceptionHandler;
import com.iailab.module.system.api.oauth2.OAuth2TokenApi;
import com.iailab.module.system.api.permission.PermissionApi;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.beans.factory.config.MethodInvokingFactoryBean;
import org.springframework.boot.autoconfigure.AutoConfiguration;
import org.springframework.boot.autoconfigure.AutoConfigureOrder;
@@ -80,11 +82,23 @@
    @Bean
    public TokenAuthenticationFilter authenticationTokenFilter(GlobalExceptionHandler globalExceptionHandler,
                                                               OAuth2TokenApi oauth2TokenApi) {
        try {
            OAuth2TokenApi oAuth2TokenApi = SpringUtil.getBean("aAuth2TokenApiImpl", OAuth2TokenApi.class);
            if (oAuth2TokenApi != null) {
                oauth2TokenApi = oAuth2TokenApi;
            }
        } catch (Exception ignored) {}
        return new TokenAuthenticationFilter(securityProperties, globalExceptionHandler, oauth2TokenApi);
    }
    @Bean("ss") // 使用 Spring Security 的缩写,方便使用
    public SecurityFrameworkService securityFrameworkService(PermissionApi permissionApi) {
        try {
            PermissionApi permissionApiImpl = SpringUtil.getBean("permissionApiImpl", PermissionApi.class);
            if (permissionApiImpl != null) {
                permissionApi = permissionApiImpl;
            }
        } catch (Exception ignored) {}
        return new SecurityFrameworkServiceImpl(permissionApi);
    }