资源服务优化

This commit is contained in:
zlt2000
2024-06-04 18:26:49 +08:00
parent ed1fdb06d5
commit 591cf2fea3
2 changed files with 10 additions and 5 deletions
@@ -3,10 +3,12 @@ package com.central.oauth2.common.config;
import cn.hutool.extra.spring.SpringUtil; import cn.hutool.extra.spring.SpringUtil;
import com.central.oauth2.common.component.CustomAuthorizationServiceIntrospector; import com.central.oauth2.common.component.CustomAuthorizationServiceIntrospector;
import com.central.oauth2.common.component.CustomBearerTokenResolver; import com.central.oauth2.common.component.CustomBearerTokenResolver;
import com.central.oauth2.common.enums.TokenType;
import com.central.oauth2.common.properties.SecurityProperties; import com.central.oauth2.common.properties.SecurityProperties;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Import; import org.springframework.context.annotation.Import;
import org.springframework.http.HttpMethod; import org.springframework.http.HttpMethod;
import org.springframework.security.config.Customizer;
import org.springframework.security.config.annotation.web.builders.HttpSecurity; import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity; import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.security.config.annotation.web.configurers.AbstractHttpConfigurer; import org.springframework.security.config.annotation.web.configurers.AbstractHttpConfigurer;
@@ -64,8 +66,13 @@ public class DefaultResourceServerConf {
http.oauth2ResourceServer(oauth2 -> { http.oauth2ResourceServer(oauth2 -> {
oauth2.authenticationEntryPoint(authenticationEntryPoint) oauth2.authenticationEntryPoint(authenticationEntryPoint)
.bearerTokenResolver(customBearerTokenResolver) .bearerTokenResolver(customBearerTokenResolver)
.accessDeniedHandler(oAuth2AccessDeniedHandler) .accessDeniedHandler(oAuth2AccessDeniedHandler);
.opaqueToken(token -> token.introspector(this.getOpaqueTokenIntrospector())); if (TokenType.JWT.getName().equals(securityProperties.getResourceServer().getTokenType())) {
oauth2.jwt(Customizer.withDefaults());
} else {
oauth2.opaqueToken(token -> token.introspector(this.getOpaqueTokenIntrospector()));
}
//.opaqueToken(token -> token.introspector(this.getOpaqueTokenIntrospector()));
}); });
return http.build(); return http.build();
@@ -1,5 +1,6 @@
package org.zlt.config; package org.zlt.config;
import com.central.oauth2.common.config.DefaultResourceServerConf;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
/** /**
@@ -12,9 +13,6 @@ import org.springframework.context.annotation.Configuration;
* Blog: http://zlt2000.gitee.io * Blog: http://zlt2000.gitee.io
* Github: https://github.com/zlt2000 * Github: https://github.com/zlt2000
*/ */
/*
@Configuration @Configuration
@EnableResourceServer
public class MyResourceConfig extends DefaultResourceServerConf { public class MyResourceConfig extends DefaultResourceServerConf {
} }
*/