【问题标题】:Turn off Spring boot OAuth in selected profile在选定的配置文件中关闭 Spring Boot OAuth
【发布时间】:2016-02-02 13:42:00
【问题描述】:

我有一个用 Spring boot 编写的 API,它使用 OAuth 来授权所有请求。

我正在使用 Spring OAuth2:

<dependency>
    <groupId>org.springframework.security.oauth</groupId>
    <artifactId>spring-security-oauth2</artifactId>
</dependency>

以及application.properties中的如下设置:

security.oauth2.client.client-id: xxxx
security.oauth2.client.client-secret: xxxx
security.oauth2.client.scope: read,write

我在各种不同的配置文件(“live”、“development”、“staging”等)中运行 API,我想在其中一些配置文件中禁用 OAuth。可以在不删除 maven 依赖项的情况下这样做(也许通过向 application-development.properties 添加一些东西?)。

到目前为止,我还没有找到任何直接的方法来做到这一点。我在应用程序启动期间以编程方式选择上下文,但这似乎不像 Spring 的方式。

【问题讨论】:

    标签: java oauth oauth-2.0 spring-boot


    【解决方案1】:

    你可以制作3个application-${profile}.properties文件

    application-live.properties
    application-development.properties
    application-staging.properties
    

    然后您可以在您想要的配置文件中添加 OAuth 的属性。 检查这个link

    【讨论】:

    • 我正在考虑这样做,但是如果我将配置保留在某些配置文件中并在我想禁用 oauth 的配置文件中省略它们,它会退回到一些自动生成的默认凭据,仍然需要我使用它们。
    • 您可以在配置类上添加您想要的配置文件@Profile,然后不会为其他配置文件加载它,例如。 @Profile("生产")
    【解决方案2】:

    @ConditionalAnnotation 添加到使用@EnableOAuth2Sso 注释的配置类中

    【讨论】:

    • 我没有任何带有此注释的课程。没有它似乎工作得很好......
    猜你喜欢
    • 2015-05-14
    • 2015-12-25
    • 2014-08-28
    • 2016-12-27
    • 1970-01-01
    • 1970-01-01
    • 2019-07-13
    • 1970-01-01
    相关资源
    最近更新 更多