我有一个使用spring安全插件的grails应用程序。该应用程序托管在Tomcat中,面向HTTPD。我使用以下设置强制使用HTTPS:
Tomcat中的server.xml
<Valve
className="org.apache.catalina.valves.RemoteIpValve"
internalProxies=".*"
protocolHeader="X-Forwarded-Proto"
httpsServerPort="443"
/>
httpd.conf (强制使用HTTPS)
<Location /myapp>
RewriteEngine On
RewriteCond %{HTTPS} !=on
RewriteRule ^/?(.*) https://my.server.com/myapp [R,L]
</Location>
ssl.conf
<Location /myapp>
ProxyPass http://localhost:9090/myapp
ProxyPassReverse http://localhost:9090/myapp
RequestHeader unset X-Forwarded-Proto
RequestHeader add X-Forwarded-Proto "https"
</Location>
Spring安全设置
grails.plugin.springsecurity.secureChannel.definition = [ '/**': 'REQUIRES_SECURE_CHANNEL' ]
grails.plugin.springsecurity.secureChannel.useHeaderCheckChannelSecurity = true
grails.plugin.springsecurity.auth.forceHttps = true
grails.plugin.springsecurity.portMapper.httpPort = 80
grails.plugin.springsecurity.portMapper.httpsPort = 443
grails.plugin.springsecurity.secureChannel.secureHeaderName = 'X-FORWARDED-PROTO'
grails.plugin.springsecurity.secureChannel.secureHeaderValue = 'http'
grails.plugin.springsecurity.secureChannel.insecureHeaderName = 'X-FORWARDED-PROTO'
grails.plugin.springsecurity.secureChannel.insecureHeaderValue = 'https'
问题
我可以通过http://my.server.com/myapp
访问该网站(重定向到HTTPS)。但问题是,当我尝试登录时 - 提交用户名/密码并单击“提交”后,我将被重定向到:https://localhost/myapp/login/authfail?login_error=1
(请注意主机名已从my.server.com
更改为{{1} })。这在成功或不成功登录时发生。
同样的问题也发生在localhost
上。点击logout
即可转到https://my.server.com/myapp/logout
以下是跟踪网络电话的屏幕截图