有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java无法使用Spring Security保护AngularJS页面

我正在使用spring security通过以下配置保护我的应用程序,以尝试显示spring默认登录页面:

春季安全。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安全配置,效果很好。这个问题只有在使用Google AppEngine时才会出现,即使是在AppEngine web中添加了<sessions-enabled>true</sessions-enabled>之后。xml

提前谢谢你


共 (1) 个答案

  1. # 1 楼答案

    我已经能够在Google AppEngine上使用Spring MVC,使用web的<security-constraint>属性保护静态文件。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>