【发布时间】:2016-02-22 02:26:50
【问题描述】:
我有一个 Spring Boot 1.3.0 应用程序,其中包含 Spring Security OAuth 作为一种 SSO 集成。
问题是应用程序在非 SSL 环境中运行,负载均衡器 (F5) 后面有一个非标准端口,强制 SSL 并且 OAuth 提供程序要求所有重定向 URL 都注册为 https,但 Spring OAuth客户端(使用 @EnableOAuthSso 自动配置)只会重定向到具有以下 URL 的 OAuth 提供程序...
https://[provider_host]/oauth/authorize?client_id=[redact]&redirect_uri=http://[application_host]/login&response_type=code&scope=[redact]&state=IpMYTe
请注意,返回的 redirect_uri 生成为 http。即使 F5 会在返回的途中强制它使用 https,我们的 OAuth 提供程序也不会允许非 SSL 重定向 URI。我该如何配置?
除了我的 Spring Data JPA 控制器之外,这是整个应用程序...
AppConfig.java
@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;
}
}
SecurityConfig.java
@Configuration
@EnableOAuth2Sso
public class SecurityConfig {
}
application.properties
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
【问题讨论】:
-
我遇到了类似的问题,但不是想成为 HTTPS,而是当我想要 HTTP 时,URI 总是以 HTTPS 的形式返回给我。你知道如何做同样的事情,但方向相反吗?我已经将您的答案应用于 application.properties 文件,但没有成功。
标签: oauth spring-boot