我有一个启用了spring-security 3.1.0的webapp ,可以在本地正常使用。
mvn jetty:run
当远程部署在码头(端口80的nginx后面)上时,spring-security会一起停止工作。也就是说,除了受保护的部分之外,其余所有Webapp都可以正常工作。
当我导航到安全位置时,我将重定向到登录页面,以便该部分正常工作。问题在于,提交登录表单时,似乎什么也没有发生。我总是回到登录表单,好像什么也没发生。
当我尝试记录事件时,spring-security完全处于静默状态。可能是个线索...
log4j.appender.stdout = org.apache.log4j.ConsoleAppender
log4j.appender.stdout.Target = System.out
log4j.appender.stdout.layout = org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern = %-5p %d [%t][%F:%L] : %m%n
log4j.rootLogger = INFO, stdout
log4j.logger.org.springframework.security=DEBUG
我唯一能想到的与本地设置真正不同的是,在远程服务器上,nginx位于码头前面。
有人知道这里可能出什么问题吗?
这是配置的相关部分。
location /test-app {
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_pass http://localhost:8080/test-app;
}
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<filter>
<filter-name>springSecurityFilterChain</filter-name>
<filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
</filter>
<filter-mapping>
<filter-name>springSecurityFilterChain</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<beans:beans xmlns="http://www.springframework.org/schema/security"
xmlns:beans="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/security
http://www.springframework.org/schema/security/spring-security-3.1.xsd">
<authentication-manager alias="authenticationManager">
<authentication-provider>
<user-service>
<user name="test" password="test" authorities="ROLE_USER, ROLE_ADMIN" />
</user-service>
</authentication-provider>
</authentication-manager>
<http auto-config="true">
<intercept-url pattern="/secured/login*" access="IS_AUTHENTICATED_ANONYMOUSLY" />
<intercept-url pattern="/secured/**" access="ROLE_USER" />
<form-login login-page="/secured/login" login-processing-url="/secured/login/auth"
authentication-failure-url="/secured/login?error=BadCredentials"
username-parameter="username" password-parameter="password"
default-target-url="/secured" />
<logout logout-url="/secured/logout" logout-success-url="/secured" />
</http>
</beans:beans>
如果您直接使用端口8080连接到远程码头,是否可以正常工作?
如果是这样,则问题可能与nginx有关。
当Spring Security身份验证成功时,它应该能够通过响应中的Set-Cookie标头在浏览器上设置cookie。也许nginx对此有麻烦。
您可以在Chrome浏览器中使用流量进行调试,然后按F12键并打开“网络”标签。转到登录页面,然后尝试登录。如果成功,您应该能够在Cookies选项卡中看到cookie JSESSIONID。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句