当前位置: 首页 > 知识库问答 >
问题:

Spring OAuthredirect_uri不使用https

邹星火
2023-03-14

我有一个Spring Boot 1.3.0应用程序,其中包含Spring Security OAuth,作为一种SSO集成。

问题是,应用程序运行在非SSL环境中,负载平衡器(F5)后面有一个非标准端口,强制使用SSL,OAuth提供程序要求将所有重定向URL注册为https,但Spring OAuth客户端(使用@EnableOAuthso自动配置)将仅使用以下URL重定向到OAuth提供程序。。。

https://[provider_host]/oauth/授权?client_id=[编辑]

请注意,return redirect\u uri生成为http。尽管F5会在返回的过程中强制它使用https,但我们的OAuth提供程序将不允许使用非SSL重定向URI。如何配置?

除了我的Spring Data JPA控制器,这是整个应用程序。。。

@SpringBootApplication(exclude = { HibernateJpaAutoConfiguration.class })
@EnableJpaRepositories
public class AppConfig extends SpringBootServletInitializer {

    public static void main(final String... args) {
        SpringApplication.run(AppConfig.class, args);
    }

    @Autowired
    public DataSource dataSource;

    @Bean(name = "entityManagerFactory")
    public LocalContainerEntityManagerFactoryBean getEntityManagerFactoryInfo() {
        final LocalContainerEntityManagerFactoryBean fac = new LocalContainerEntityManagerFactoryBean();
        fac.setDataSource(dataSource);
        fac.setJpaVendorAdapter(new HibernateJpaVendorAdapter());
        fac.setPackagesToScan("[redact]");

        final Properties props = new Properties();
        props.put("hibernate.dialect", "org.hibernate.dialect.SQLServerDialect");
        props.put("hibernate.show_sql", "true");
        props.put("hibernate.format_sql", "true");
        fac.setJpaProperties(props);

        return fac;
    }

    @Bean(name = "transactionManager")
    public PlatformTransactionManager getTransactionManager() {
        final JpaTransactionManager transactMngr = new JpaTransactionManager();
        transactMngr.setEntityManagerFactory(getEntityManagerFactoryInfo().getObject());
        return transactMngr;
    }

}
@Configuration
@EnableOAuth2Sso
public class SecurityConfig {

}
server.port=9916
server.contextPath=

server.use-forward-headers=true

security.oauth2.client.clientId=[redact]
security.oauth2.client.clientSecret=[redact]
security.oauth2.client.scope=[redact]
security.oauth2.client.accessTokenUri=https://[provider_host]/oauth/token
security.oauth2.client.userAuthorizationUri=https://[provider_host]/oauth/authorize
security.oauth2.resource.userInfoUri=https://[provider_host]/oauth/me
security.oauth2.resource.preferTokenInfo=false

logging.level.org.springframework=TRACE

共有3个答案

严斌
2023-03-14

我的答案是针对使用最新spring版本的人的,因为上面建议的答案对我并不适用。我使用的是Spring Boot 2.3.5。释放

我也有同样的问题,我正在使用Azure AD进行oauth2身份验证。我的应用程序运行在反向代理之后,形成的重定向uri采用http而不是https。

阅读文档后https://docs.spring.io/spring-security/site/docs/5.2.x/reference/html/oauth2.html#oauth2Client-身份验证代码重定向uri,我在应用程序的下面一行添加了它。属性文件,它对我有用

spring.security.oauth2.client.registration.azure.redirect-uri=https://{baseHost}{basePort}{basePath}/login/oauth2/code/azure
魏雅惠
2023-03-14

您可能需要确保应用程序理解负载平衡器的x转发头。

将其放入我的应用程序中。yml解决了我在AWS ELB后面的应用程序中遇到的类似问题:

server:
  tomcat:
    remote-ip-header: x-forwarded-for
    protocol-header: x-forwarded-proto

编辑:这可以通过更通用的配置来简化:

server:
  use-forward-headers: true

对于Apache Tomcat,请在服务器中使用RemoteIpValve。xml(以上为AccessLogValve):

    <Valve className="org.apache.catalina.valves.RemoteIpValve" 
        protocolHeader="X-Forwarded-Proto" />

另请参见:https://tomcat.apache.org/tomcat-7.0-doc/api/org/apache/catalina/valves/RemoteIpValve.html.

袁单鹗
2023-03-14

在手动挖掘配置类之后,我能够找到并添加以下内容,这就成功了。。。

security.oauth2.client.pre-established-redirect-uri=https://[application_host]/login
security.oauth2.client.registered-redirect-uri=https://[application_host]/login
security.oauth2.client.use-current-uri=false

我不相信没有更好的方法来解决强制HTTPS重定向URL的问题,但这个修复对我来说很有效。

 类似资料:
  • 问题内容: 此页面- http://labs.qt.nokia.com/2011/10/28/rpath-and- runpath/ -说,大约为了在ld.so库搜索: 然后建议: 运送二进制文件时,请使用RPATH而不是RUNPATH或确保在运行它们之前已设置LD_LIBRARY_PATH。 那么,with的使用是不好的,因为kind- of会取消,因此间接动态加载无法按预期工作?但是,为什么然

  • 正是标题所说的。有没有办法在不安装TCL的情况下使用matplotlib库?请不要告诉我咬紧牙关安装TCL——我知道怎么做,但出于我自己(好吧,也许很愚蠢)的原因,我不想这么做。 我不关心显示的图,我只希望能够输出他们在png。我尝试了各种各样的东西(使用不同的后端等),但是matplotlib总是想找到tcl来工作:(为什么TCL对matplotlib如此重要? 此外,请注意,我正在使用wind

  • 当登录失败时,我试图重定向登录页面上输入的用户名,但在我的控制器中,从“@modelattribute(”user“)”检索的用户的用户名为空。当我不使用spring security时,这是有效的。 我假设form实际上首先发送到spring security,然后重定向到控制器,因此在spring security之间输入的信息丢失。 编辑(解决方案): 谢谢。@James创建一个failur

  • 我在windows服务器上安装了imagemagick,当我尝试使用CMD时,它成功地转换了文件,但当我在php中使用以下代码时:- 它给出了以下错误:- ImagickException:无法打开图像“弧”。pdf“:没有此类文件或目录@错误/blob。c:\wamp\www\test\test中的c/OpenBlob/2638。php第10行 我也试过了 然后给出:- ImagickExcep

  • 我试图使用Hibernate的logback,似乎很容易,但我不能得到它的工作 hibernate.cfg.xml logback.xml 控制台输出 4.aziendagru2.aziendagru2.aziendagru2.id.aziendagru2.id.aziendagru2.id.id.azienda作为一个gruppo作为一个id1作为一个id1作为一个id1作为一个id1作为一个i

  • 我目前正在尝试训练一个聊天机器人,更具体地说是这个。但是,当我开始训练聊天机器人时,它使用了我100%的CPU和大约10%的GPU。有人知道为什么吗。 我已经安装了,并确保我有正确的CUDA和cuDNN版本。我还确保我没有安装基本的pip包。我的GPU也有最新的英伟达驱动程序。我也尝试过卸载和重新安装我所有的驱动程序,CUDA,cuDNN,tensorflow gpu和它所有的依赖和python本