From 5283b8ce19dcc43976bd8bcb640f36dcec2f6d1e Mon Sep 17 00:00:00 2001 From: qraddx Date: Thu, 10 Feb 2022 14:32:57 +0800 Subject: [PATCH] =?UTF-8?q?:sparkles:=20Introducing=20new=20features.=20cl?= =?UTF-8?q?ose=20#3603=20=E8=B5=84=E6=BA=90=E6=9C=8D=E5=8A=A1=E5=99=A8?= =?UTF-8?q?=E6=9C=AC=E5=9C=B0=E6=A8=A1=E5=BC=8F=E9=BB=98=E8=AE=A4=E4=B8=BA?= =?UTF-8?q?Local=20=E9=AB=98=E6=80=A7=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../annotation/EnablePigxResourceServer.java | 6 -- ...xLocalResourceServerConfigurerAdapter.java | 2 +- .../PigxResourceServerConfigurerAdapter.java | 79 ------------------- .../PigxSecurityBeanDefinitionRegistrar.java | 12 +-- 4 files changed, 2 insertions(+), 97 deletions(-) delete mode 100644 pigx-common/pigx-common-security/src/main/java/com/pig4cloud/pigx/common/security/component/PigxResourceServerConfigurerAdapter.java diff --git a/pigx-common/pigx-common-security/src/main/java/com/pig4cloud/pigx/common/security/annotation/EnablePigxResourceServer.java b/pigx-common/pigx-common-security/src/main/java/com/pig4cloud/pigx/common/security/annotation/EnablePigxResourceServer.java index 02dcd7aad..d951467b8 100644 --- a/pigx-common/pigx-common-security/src/main/java/com/pig4cloud/pigx/common/security/annotation/EnablePigxResourceServer.java +++ b/pigx-common/pigx-common-security/src/main/java/com/pig4cloud/pigx/common/security/annotation/EnablePigxResourceServer.java @@ -40,10 +40,4 @@ import java.lang.annotation.*; @Import({ PigxResourceServerAutoConfiguration.class, PigxSecurityBeanDefinitionRegistrar.class }) public @interface EnablePigxResourceServer { - /** - * 是否开启本地模式 - * @return true - */ - boolean isLocal() default true; - } diff --git a/pigx-common/pigx-common-security/src/main/java/com/pig4cloud/pigx/common/security/component/PigxLocalResourceServerConfigurerAdapter.java b/pigx-common/pigx-common-security/src/main/java/com/pig4cloud/pigx/common/security/component/PigxLocalResourceServerConfigurerAdapter.java index a658989f3..891a851a4 100644 --- a/pigx-common/pigx-common-security/src/main/java/com/pig4cloud/pigx/common/security/component/PigxLocalResourceServerConfigurerAdapter.java +++ b/pigx-common/pigx-common-security/src/main/java/com/pig4cloud/pigx/common/security/component/PigxLocalResourceServerConfigurerAdapter.java @@ -32,7 +32,7 @@ import org.springframework.security.web.AuthenticationEntryPoint; * @author lengleng * @date 2020/9/30 *

- * 支持本地模式 [不仅过认证中 CheckToken]的的资源服务器配置 + * 支持本地模式 [不进过认证中心 CheckToken]的的资源服务器配置 */ @Slf4j public class PigxLocalResourceServerConfigurerAdapter extends ResourceServerConfigurerAdapter { diff --git a/pigx-common/pigx-common-security/src/main/java/com/pig4cloud/pigx/common/security/component/PigxResourceServerConfigurerAdapter.java b/pigx-common/pigx-common-security/src/main/java/com/pig4cloud/pigx/common/security/component/PigxResourceServerConfigurerAdapter.java deleted file mode 100644 index 1555e8981..000000000 --- a/pigx-common/pigx-common-security/src/main/java/com/pig4cloud/pigx/common/security/component/PigxResourceServerConfigurerAdapter.java +++ /dev/null @@ -1,79 +0,0 @@ -/* - * Copyright (c) 2018-2025, lengleng All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * Neither the name of the pig4cloud.com developer nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * Author: lengleng (wangiegie@gmail.com) - */ - -package com.pig4cloud.pigx.common.security.component; - -import lombok.SneakyThrows; -import lombok.extern.slf4j.Slf4j; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.security.config.annotation.web.builders.HttpSecurity; -import org.springframework.security.config.annotation.web.configurers.ExpressionUrlAuthorizationConfigurer; -import org.springframework.security.oauth2.config.annotation.web.configuration.ResourceServerConfigurerAdapter; -import org.springframework.security.oauth2.config.annotation.web.configurers.ResourceServerSecurityConfigurer; -import org.springframework.security.oauth2.provider.authentication.TokenExtractor; -import org.springframework.security.oauth2.provider.token.RemoteTokenServices; -import org.springframework.security.web.AuthenticationEntryPoint; -import org.springframework.web.client.RestTemplate; - -/** - * @author lengleng - * @date 2018/6/22 - *

- * 1. 支持remoteTokenServices 负载均衡 2. 支持 获取用户全部信息 - */ -@Slf4j -public class PigxResourceServerConfigurerAdapter extends ResourceServerConfigurerAdapter { - - @Autowired - protected AuthenticationEntryPoint resourceAuthExceptionEntryPoint; - - @Autowired - protected RemoteTokenServices remoteTokenServices; - - @Autowired - private PermitAllUrlResolver permitAllUrlResolver; - - @Autowired - private TokenExtractor tokenExtractor; - - @Autowired - private RestTemplate lbRestTemplate; - - /** - * 默认的配置,对外暴露 - * @param httpSecurity - */ - @Override - @SneakyThrows - public void configure(HttpSecurity httpSecurity) { - // 允许使用iframe 嵌套,避免swagger-ui 不被加载的问题 - httpSecurity.headers().frameOptions().disable(); - ExpressionUrlAuthorizationConfigurer.ExpressionInterceptUrlRegistry registry = httpSecurity - .authorizeRequests(); - // 配置对外暴露接口 - permitAllUrlResolver.registry(registry); - registry.anyRequest().authenticated().and().csrf().disable(); - } - - @Override - public void configure(ResourceServerSecurityConfigurer resources) { - remoteTokenServices.setRestTemplate(lbRestTemplate); - resources.authenticationEntryPoint(resourceAuthExceptionEntryPoint).tokenExtractor(tokenExtractor) - .tokenServices(remoteTokenServices); - } - -} diff --git a/pigx-common/pigx-common-security/src/main/java/com/pig4cloud/pigx/common/security/component/PigxSecurityBeanDefinitionRegistrar.java b/pigx-common/pigx-common-security/src/main/java/com/pig4cloud/pigx/common/security/component/PigxSecurityBeanDefinitionRegistrar.java index 929d7fe71..9c71506e8 100644 --- a/pigx-common/pigx-common-security/src/main/java/com/pig4cloud/pigx/common/security/component/PigxSecurityBeanDefinitionRegistrar.java +++ b/pigx-common/pigx-common-security/src/main/java/com/pig4cloud/pigx/common/security/component/PigxSecurityBeanDefinitionRegistrar.java @@ -18,7 +18,6 @@ package com.pig4cloud.pigx.common.security.component; import com.pig4cloud.pigx.common.core.constant.SecurityConstants; -import com.pig4cloud.pigx.common.security.annotation.EnablePigxResourceServer; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.support.BeanDefinitionRegistry; import org.springframework.beans.factory.support.GenericBeanDefinition; @@ -45,16 +44,7 @@ public class PigxSecurityBeanDefinitionRegistrar implements ImportBeanDefinition } GenericBeanDefinition beanDefinition = new GenericBeanDefinition(); - - Boolean isLocal = (Boolean) metadata.getAnnotationAttributes(EnablePigxResourceServer.class.getName()) - .get("isLocal"); - if (isLocal) { - beanDefinition.setBeanClass(PigxLocalResourceServerConfigurerAdapter.class); - } - else { - beanDefinition.setBeanClass(PigxResourceServerConfigurerAdapter.class); - } - + beanDefinition.setBeanClass(PigxLocalResourceServerConfigurerAdapter.class); registry.registerBeanDefinition(SecurityConstants.RESOURCE_SERVER_CONFIGURER, beanDefinition); }