简体   繁体   English

ratpack:实现自定义PublicAddress强制https

[英]ratpack: implementing a custom PublicAddress to force https

I was on a pac4j mail thread discussing why the redirect url ratpack-pac4j uses is using http even when the original page request is served over https. 我在一个pac4j邮件线程上讨论了即使原始页面请求是通过https进行服务的,为什么重定向URL ratpack-pac4j使用的重定向URL仍使用http。 I did some digging and it looks like ratpack-pac4j is using the InferringPublicAddress. 我做了一些挖掘,看来ratpack-pac4j正在使用InferringPublicAddress。 This works for local development, but because my elasticbean host proxies 443 to 80, ratpack-pac4j thinks it's over http and uses http for the redirect url. 这适用于本地开发,但是由于我的Elasticbean主机代理443至80,ratpack-pac4j认为它在http之上,并使用http作为重定向URL。 I want this call to be over https when on the server. 我希望此呼叫在服务器上时通过https进行。

I'm trying to register a custom PublicAddress class that always returns http in development mode, but https in production mode: 我正在尝试注册一个自定义PublicAddress类,该类始终在开发模式下返回http,但在生产模式下返回https:

        .registry(Guice.registry(b -> { 
            b
                .module(SessionModule.class)
                .module(ThymeleafModule.class, conf -> conf.templatesMode("LEGACYHTML5"))
                .add(PublicAddress.class, ForcedHttpsPublicAddress.create()); //PublicAddress.class, PublicAddress.inferred("https"));
        }))

...

static private class ForcedHttpsPublicAddress implements PublicAddress
{
    static ForcedHttpsPublicAddress create() {
        return new ForcedHttpsPublicAddress();
    }
    ForcedHttpsPublicAddress() {
    }
}

But when I call ctx.get(PublicAddress.class), it's still returning InferringPublicAddress. 但是当我调用ctx.get(PublicAddress.class)时,它仍然返回InferringPublicAddress。 Am I registering the custom PublicAddress incorrectly? 我是否注册了自定义的PublicAddress错误?

Got help on the Ratpack forum. 在Ratpack论坛上获得了帮助。 I needed to bind it instead of add it. 我需要绑定它而不是添加它。

.bind(PublicAddress.class, ForcedHttpsPublicAddress.class)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM