在IBM Cloud CF Java BuildPack上使用Spring Boot OAuth 2...
https://github.com/ericis/oauth-cf-https-issue
*我试过下面的每一种组合。
完全配置:
http.
requiresChannel().anyRequest().requiresSecure().
authorizeRequests().
// allow access to...
antMatchers("favicon.ico", "/login", "/loginFailure", "/oauth2/authorization/ghe")
.permitAll().anyRequest().authenticated().and().oauth2Login().
// Codify "spring.security.oauth2.client.registration/.provider"
clientRegistrationRepository(this.clientRegistrationRepository()).
// setup OAuth2 client service to use clientRegistrationRepository
authorizedClientService(this.authorizedClientService()).
successHandler(this.successHandler()).
// customize login pages
loginPage("/login").failureUrl("/loginFailure").
userInfoEndpoint().
// customize the principal
userService(this.userService());
我也试过:
>
使用HTTPS
的服务器配置
server:
useForwardHeaders: true
tomcat:
protocolHeader: x-forwarded-proto
import java.io.IOException;
import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
@Component
public class HttpToHttpsFilter implements Filter {
private static final Logger log = LoggerFactory.getLogger(HttpToHttpsFilter.class);
private static final String HTTP = "http";
private static final String SCHEME_HTTP = "http://";
private static final String SCHEME_HTTPS = "https://";
private static final String LOCAL_ID = "0:0:0:0:0:0:0:1";
private static final String LOCALHOST = "localhost";
@Value("${local.ip}")
private String localIp;
public HttpToHttpsFilter() {
// Sonar
}
@Override
public void doFilter(final ServletRequest req, final ServletResponse res, final FilterChain chain)
throws IOException, ServletException {
final HttpServletRequest request = (HttpServletRequest) req;
final HttpServletResponse response = (HttpServletResponse) res;
// http, not localhost, not localhost ipv6, not local IP
if (HTTP.equals(request.getScheme()) &&
!LOCALHOST.equals(request.getRemoteHost()) &&
!LOCAL_ID.equals(request.getRemoteHost()) &&
(this.localIp != null && !this.localIp.equals(request.getRemoteHost()))) {
final String query = request.getQueryString();
String oldLocation = request.getRequestURL().toString();
if (query != null) {
oldLocation += "?" + query;
}
final String newLocation = oldLocation.replaceFirst(SCHEME_HTTP, SCHEME_HTTPS);
try {
log.info("HTTP redirect from {} to {} ", oldLocation, newLocation);
response.sendRedirect(newLocation);
} catch (IOException e) {
log.error("Cannot redirect to {} {} ", newLocation, e);
}
} else {
chain.doFilter(req, res);
}
}
@Override
public void destroy() {
// Sonar
}
@Override
public void init(FilterConfig arg0) throws ServletException {
// Sonar
}
}
dependencies {
//
// BASICS
// health and monitoring
// compile('org.springframework.boot:spring-boot-starter-actuator')
// security
compile('org.springframework.boot:spring-boot-starter-security')
// configuration
compile('org.springframework.boot:spring-boot-configuration-processor')
//
// WEB
// web
compile('org.springframework.boot:spring-boot-starter-web')
// thymeleaf view render
compile('org.springframework.boot:spring-boot-starter-thymeleaf')
// thymeleaf security extras
compile('org.thymeleaf.extras:thymeleaf-extras-springsecurity4')
//
// OAUTH
// OAuth client
compile('org.springframework.security:spring-security-oauth2-client')
// OAuth lib
compile('org.springframework.security:spring-security-oauth2-jose')
// OAuth config
compile('org.springframework.security.oauth.boot:spring-security-oauth2-autoconfigure:2.0.0.RELEASE')
//
// CLOUD
// cloud connectors (e.g. vcaps)
compile('org.springframework.boot:spring-boot-starter-cloud-connectors')
//
// TOOLS
runtime('org.springframework.boot:spring-boot-devtools')
//
// TEST
// test
testCompile('org.springframework.boot:spring-boot-starter-test')
// security test
testCompile('org.springframework.security:spring-security-test')
}
这件事已经解决了。有关此问题的详细信息,请访问:https://github.com/spring-projects/spring-security/issues/5535#issuecomment-407413944
正在工作的示例项目:https://github.com/ericis/oauth-cf-https-issue
简短的回答是:
@Bean
FilterRegistrationBean<ForwardedHeaderFilter> forwardedHeaderFilter() {
final FilterRegistrationBean<ForwardedHeaderFilter> filterRegistrationBean = new FilterRegistrationBean<ForwardedHeaderFilter>();
filterRegistrationBean.setFilter(new ForwardedHeaderFilter());
filterRegistrationBean.setOrder(Ordered.HIGHEST_PRECEDENCE);
return filterRegistrationBean;
}
问题内容: __Apache 环境中心 尝试设置从http到https的自动重定向 我尝试将以下内容添加到我的httpd.conf中,但是没有用 有任何想法吗? 问题答案: 我实际上已经遵循了这个示例,并且对我有用:) 然后做:
奇怪的问题。我使用FullCalendar向服务器上的endpoint发起ajax请求。终点是: 请注意,它是显式的HTTPS。但是,当我发起一个请求时(即当Fullcalendar发起一个请求时),我会得到一个301和一个到非HTTPSendpoint的重定向: 因为页面是通过HTTPS加载的,所以失败。 endpoint工作正常--当我将它加载到浏览器中时,我会得到预期的json输出(通过ht
每当我访问网址https://localhost:9002/trainingstorefront/?site=electronics,它总是重定向到站点主页。这个请求映射实际上是如何发生的,以及它在哪里决定要加载的站点。
请不要向我推荐超过173票的长而详细的帖子。这对我不起作用。我也试过很多其他的(1,2,3,4)。他们都给我太多的重定向或错误500。因此,我的问题是: 用我的电流。htaccess,这就是发生的情况: https://www.dukescasino.com/-工作完美 https://dukescasino.com/-重定向到上面的内容,这很好 下面的两个选项加载罚款,但它应该重定向到https
我们使用拉维5。要将http连接重定向到https,请使用中间件HttpsProtocol。 在我们的4个测试用例中,只有1个正确工作(最后一个重定向)。其他3种情况的中间件添加了url extra index.php。 http://www.aqualink.az/index.php ---
好吧,我恨死它了。我已经想解决这个问题几个小时了,但我还是不知道是不是错了,或者我错过了什么。 我有这个代码: 它会将http请求重定向到https,但每当我键入domain.com时,它都会重定向到https://domain.com,并抛出一个ssl错误: 这可能不是你要找的网站!您试图访问域。但实际上您到达了一个服务器,该服务器的名称为www.domain.com。这可能是由于服务器配置错误