简体   繁体   English

Grails - SSL和Spring安全核心

[英]Grails - SSL and Spring security core

I would like to have my application running exclusively with SSL turned on. 我希望我的应用程序专门在启用SSL的情况下运行。 I am using the Spring Security core plugin. 我正在使用Spring Security核心插件。

This is how I attempt to do it in Config.groovy : 这就是我在Config.groovy尝试这样做的方法:

grails.plugins.springsecurity.portMapper.httpPort = 8080
grails.plugins.springsecurity.portMapper.httpsPort = 8443
grails.plugins.springsecurity.secureChannel.definition = [ '/**' : 'REQUIRES_SECURE_CHANNEL']

I was expecting this to cause redirects every time I would try to access a Url using HTTP. 每次我尝试使用HTTP访问Url时,我都希望这会导致重定向。 However, I am never redirected, and can navigate through both HTTP and HTTPS. 但是,我从未被重定向,并且可以通过HTTP和HTTPS进行导航。 I may add I am starting my application using grails run-app -https 我可以添加我使用grails run-app -https启动我的应用grails run-app -https

Am I getting this all wrong ? 我错了吗?

Any suggestion is most welcome. 任何建议都是最受欢迎的。

Do you have a custom filterchain declared in your config? 您是否在配置中声明了自定义过滤链?

you might need to add 'channelProcessingFilter' to your chain in that case 在这种情况下,您可能需要将“channelProcessingFilter”添加到您的链中

http://static.springsource.org/spring-security/site/docs/3.0.x/reference/security-filter-chain.html http://static.springsource.org/spring-security/site/docs/3.0.x/reference/security-filter-chain.html

您也可以尝试使用forceHttps选项

grails.plugins.springsecurity.auth.forceHttps = true

You don't have any wildcards, so the definition is literally matching the root URL ( / ), but nothing below it ( /foo ). 您没有任何通配符,因此该定义实际上与根URL( / )匹配,但不在其下方( /foo )。 What you want is: 你想要的是:

grails.plugins.springsecurity.secureChannel.definition = [ '/**' : 'REQUIRES_SECURE_CHANNEL']
                                                             ^^

(You can clearly see the wildcards in the documentation :-) (您可以在文档中清楚地看到通配符:-)

Finally, if your server is behind a load balancer or other firewall that hides the protocol, check that same page for instructions on checking the header. 最后,如果您的服务器位于负载平衡器或隐藏协议的其他防火墙之后,请检查该页面以获取有关检查标头的说明。

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

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