diff --git a/pigx-common/pigx-common-security/src/main/java/com/pig4cloud/pigx/common/security/component/PigxResourceServerAutoConfiguration.java b/pigx-common/pigx-common-security/src/main/java/com/pig4cloud/pigx/common/security/component/PigxResourceServerAutoConfiguration.java index 51950ee1d..bdf9b1f4e 100644 --- a/pigx-common/pigx-common-security/src/main/java/com/pig4cloud/pigx/common/security/component/PigxResourceServerAutoConfiguration.java +++ b/pigx-common/pigx-common-security/src/main/java/com/pig4cloud/pigx/common/security/component/PigxResourceServerAutoConfiguration.java @@ -23,6 +23,8 @@ import org.springframework.context.MessageSource; import org.springframework.context.annotation.Bean; import org.springframework.security.oauth2.server.authorization.OAuth2AuthorizationService; import org.springframework.security.oauth2.server.resource.introspection.OpaqueTokenIntrospector; +import org.springframework.security.oauth2.server.resource.web.BearerTokenResolver; +import org.springframework.security.oauth2.server.resource.web.DefaultBearerTokenResolver; /** * @author lengleng @@ -32,45 +34,51 @@ import org.springframework.security.oauth2.server.resource.introspection.OpaqueT @EnableConfigurationProperties(PermitAllUrlProperties.class) public class PigxResourceServerAutoConfiguration { - /** - * 鉴权具体的实现逻辑 - * @return (#pms.xxx) - */ - @Bean("pms") - public PermissionService permissionService() { - return new PermissionService(); - } + /** + * 鉴权具体的实现逻辑 + * + * @return (#pms.xxx) + */ + @Bean("pms") + public PermissionService permissionService() { + return new PermissionService(); + } - /** - * 请求令牌的抽取逻辑 - * @param urlProperties 对外暴露的接口列表 - * @return BearerTokenExtractor - */ - @Bean - public PigxBearerTokenExtractor pigBearerTokenExtractor(PermitAllUrlProperties urlProperties) { - return new PigxBearerTokenExtractor(urlProperties); - } + /** + * 请求令牌的抽取逻辑 + * + * @return BearerTokenExtractor + */ + @Bean + public BearerTokenResolver pigBearerTokenExtractor() { + DefaultBearerTokenResolver defaultBearerTokenResolver = new DefaultBearerTokenResolver(); + defaultBearerTokenResolver.setAllowUriQueryParameter(true); + defaultBearerTokenResolver.setAllowFormEncodedBodyParameter(true); + return defaultBearerTokenResolver; + } - /** - * 资源服务器异常处理 - * @param objectMapper jackson 输出对象 - * @param securityMessageSource 自定义国际化处理器 - * @return ResourceAuthExceptionEntryPoint - */ - @Bean - public ResourceAuthExceptionEntryPoint resourceAuthExceptionEntryPoint(ObjectMapper objectMapper, - MessageSource securityMessageSource) { - return new ResourceAuthExceptionEntryPoint(objectMapper, securityMessageSource); - } + /** + * 资源服务器异常处理 + * + * @param objectMapper jackson 输出对象 + * @param securityMessageSource 自定义国际化处理器 + * @return ResourceAuthExceptionEntryPoint + */ + @Bean + public ResourceAuthExceptionEntryPoint resourceAuthExceptionEntryPoint(ObjectMapper objectMapper, + MessageSource securityMessageSource) { + return new ResourceAuthExceptionEntryPoint(objectMapper, securityMessageSource); + } - /** - * 资源服务器toke内省处理器 - * @param authorizationService token 存储实现 - * @return TokenIntrospector - */ - @Bean - public OpaqueTokenIntrospector opaqueTokenIntrospector(OAuth2AuthorizationService authorizationService) { - return new PigxCustomOpaqueTokenIntrospector(authorizationService); - } + /** + * 资源服务器toke内省处理器 + * + * @param authorizationService token 存储实现 + * @return TokenIntrospector + */ + @Bean + public OpaqueTokenIntrospector opaqueTokenIntrospector(OAuth2AuthorizationService authorizationService) { + return new PigxCustomOpaqueTokenIntrospector(authorizationService); + } } diff --git a/pigx-common/pigx-common-security/src/main/java/com/pig4cloud/pigx/common/security/component/PigxResourceServerConfiguration.java b/pigx-common/pigx-common-security/src/main/java/com/pig4cloud/pigx/common/security/component/PigxResourceServerConfiguration.java index ab73caf14..6dba398f5 100644 --- a/pigx-common/pigx-common-security/src/main/java/com/pig4cloud/pigx/common/security/component/PigxResourceServerConfiguration.java +++ b/pigx-common/pigx-common-security/src/main/java/com/pig4cloud/pigx/common/security/component/PigxResourceServerConfiguration.java @@ -46,8 +46,6 @@ public class PigxResourceServerConfiguration { private final PermitAllUrlProperties permitAllUrl; - private final PigxBearerTokenExtractor pigxBearerTokenExtractor; - private final OpaqueTokenIntrospector customOpaqueTokenIntrospector; @Bean @@ -65,8 +63,7 @@ public class PigxResourceServerConfiguration { .authenticated()) .oauth2ResourceServer( oauth2 -> oauth2.opaqueToken(token -> token.introspector(customOpaqueTokenIntrospector)) - .authenticationEntryPoint(resourceAuthExceptionEntryPoint) - .bearerTokenResolver(pigxBearerTokenExtractor)) + .authenticationEntryPoint(resourceAuthExceptionEntryPoint)) .headers(headers -> headers.frameOptions(HeadersConfigurer.FrameOptionsConfig::disable)) .csrf(AbstractHttpConfigurer::disable);