为非引导 spring 框架配置 spring-oauth2-client
Configuring spring-oauth2-client for non boot spring framework
在 spring 引导中,application.yml 接受 Spring oauth2 客户端配置。如何为非启动应用程序配置它。通过配置,我的意思是提供客户端 ID、秘密、范围和重定向 URI。
如果您不使用SpringBoot : 没有application.yml 即使您可以添加对yml 文件的支持。它不会处理您的 oauth2 客户端配置。
无论如何,您都可以使用 Spring 安全性来实现您的自定义授权服务、用户服务并实现您选择的令牌存储(例如 JBDCTokenStore 或 JWTTokenStore)。但这是一个非常广泛的问题,具体取决于您的业务逻辑。
您可以在 上找到一些有据可查的示例:
https://github.com/spring-projects/spring-security-oauth/tree/master/spring-security-oauth2
当然,您可以处理 XML 和 javaConfig 甚至混合 Spring 配置。
在包含组件或 bean 定义的包上使用 @ComponentScan 创建 @Configuration class。
@Configuration
@ComponentScan({ "com.firm.product.config.xml","com.firm.product.config.java" })
public class SpringConfig {
}
您还可以使用@PropertySource() 和@Value 注释设置属性。它有很好的记录。
你可以在这里找到一个例子:
https://www.baeldung.com/spring-security-5-oauth2-login#non-boot
您需要:
- 打造你的
ClientRegistration
.
- 一个
ClientRegistrationRepository
.
- 在
WebSecurityConfigurerAdapter
上注册您的存储库。
在 spring 引导中,application.yml 接受 Spring oauth2 客户端配置。如何为非启动应用程序配置它。通过配置,我的意思是提供客户端 ID、秘密、范围和重定向 URI。
如果您不使用SpringBoot : 没有application.yml 即使您可以添加对yml 文件的支持。它不会处理您的 oauth2 客户端配置。
无论如何,您都可以使用 Spring 安全性来实现您的自定义授权服务、用户服务并实现您选择的令牌存储(例如 JBDCTokenStore 或 JWTTokenStore)。但这是一个非常广泛的问题,具体取决于您的业务逻辑。
您可以在 上找到一些有据可查的示例: https://github.com/spring-projects/spring-security-oauth/tree/master/spring-security-oauth2
当然,您可以处理 XML 和 javaConfig 甚至混合 Spring 配置。 在包含组件或 bean 定义的包上使用 @ComponentScan 创建 @Configuration class。
@Configuration
@ComponentScan({ "com.firm.product.config.xml","com.firm.product.config.java" })
public class SpringConfig {
}
您还可以使用@PropertySource() 和@Value 注释设置属性。它有很好的记录。
你可以在这里找到一个例子:
https://www.baeldung.com/spring-security-5-oauth2-login#non-boot
您需要:
- 打造你的
ClientRegistration
. - 一个
ClientRegistrationRepository
. - 在
WebSecurityConfigurerAdapter
上注册您的存储库。