0
자바 플레이! RESTful API 역할을하는 Heroku의 앱 모든 클라이언트 연결에 대해 TLS over HTTP를 시행하고 싶습니다. 그 일을하는 가장 좋은 방법은 무엇입니까?java for https를 실행하는 방법 Play! 헤로 쿠 앱?
자바 플레이! RESTful API 역할을하는 Heroku의 앱 모든 클라이언트 연결에 대해 TLS over HTTP를 시행하고 싶습니다. 그 일을하는 가장 좋은 방법은 무엇입니까?java for https를 실행하는 방법 Play! 헤로 쿠 앱?
가장 짧은 코드는 Global.java
@Override
public Action onRequest(final Http.Request request, Method actionMethod) {
//contains http or https
String header=request.getHeader("x-forwarded-proto");
if(header != null && header.equals("http")){
return new Action.Simple() {
@Override
public F.Promise<Result> call(Http.Context ctx) throws Throwable {
return F.Promise.pure(redirect("https://" + request.host() + request.path()));
}
};
}
}
또는 액션 조성 차단 요청이다 새로운 ForceHttps.java
에서
(당신의 "분별있는"웹 서비스를 선택하는 것이 유용) :
를package actions;
import play.Play;
import play.libs.F;
import play.mvc.*;
public class ForceHttps extends Action<Controller> {
// heroku header
private static final String SSL_HEADER = "x-forwarded-proto";
@Override
public F.Promise<SimpleResult> call(Http.Context ctx) throws Throwable {
if (Play.isProd() && !isHttpsRequest(ctx.request())) {
return F.Promise.promise(() -> redirect("https://" + ctx.request().host() + ctx.request().uri()));
}
// let request proceed
return this.delegate.call(ctx);
}
private static boolean isHttpsRequest(Http.Request request) {
// heroku passes header on
return request.getHeader(SSL_HEADER) != null && request.getHeader(SSL_HEADER).contains("https");
}
}
Application.java
(또는 어떤 수업/방법보다) :
@With(ForceHttps.class)
public class Application extends Controller {
Julien에게 Play 도움말을 제공해 주셔서 감사합니다. Heroku는 이미 HTTPS를 기본적으로 지원합니다. "모든 기본 appname.herokuapp.com 도메인은 이미 SSL을 사용할 수 있으며 https://appname.herokuapp.com과 같은 https를 사용하여 간단히 액세스 할 수 있습니다." –
실제로 SSL 애드온을 설정하면 http : //myapp.herokuapp.com에 액세스 할 수 있지만 사용자가이를 사용한다는 의미는 아닙니다. 웹 사이트의 보안을 유지하거나 자격 증명 보안 또는 신용 카드 번호를 유지하려면 httpS –