我正在使用 Spring Security 来保护我的应用程序,并使用以下配置来尝试显示 Spring 默认登录页面:
spring-security.xml
<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.2.xsd">
<http auto-config="true">
<intercept-url pattern="/**" access="ROLE_USER" />
</http>
<authentication-manager>
<authentication-provider>
<user-service>
<user name="test.account" password="123456" authorities="ROLE_USER" />
</user-service>
</authentication-provider>
</authentication-manager>
</beans:beans>
我的问题是,除了始终向公众开放的 Angular 文件 (localhost:8080/#/notification) 之外,所有资源都已成功通过身份验证。
编辑 1:
我尝试在 Jetty 服务器上运行上述 spring 安全配置,效果很好。即使在将 <sessions-enabled>true</sessions-enabled>
添加到 appengine-web.xml 之后,该问题也仅在使用 Google AppEngine 时出现。
提前谢谢您。
最佳答案
我已经能够使用 <security-constraint>
在 Google AppEngine 上使用 Spring MVC 来保护静态文件的安全web.xml 文件的属性。
示例:
<security-constraint>
<web-resource-collection>
<web-resource-name>Public Area</web-resource-name>
<url-pattern>/xyz</url-pattern>
<url-pattern>/images/*</url-pattern>
<url-pattern>/yyz/*</url-pattern>
<url-pattern>*.xml</url-pattern>
</web-resource-collection>
</security-constraint>
<security-constraint>
<web-resource-collection>
<web-resource-name>Protected Area</web-resource-name>
<url-pattern>/*</url-pattern>
</web-resource-collection>
<auth-constraint>
<role-name>*</role-name>
</auth-constraint>
</security-constraint>
关于java - 无法使用 Spring Security 保护 AngularJS 页面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25341934/