【问题标题】:Can not secure AngularJS page using Spring Security无法使用 Spring Security 保护 AngularJS 页面
【发布时间】:2014-10-10 02:31:11
【问题描述】:

我正在使用 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 安全配置,效果很好。仅在将&lt;sessions-enabled&gt;true&lt;/sessions-enabled&gt; 添加到 appengine-web.xml 后,使用 Google AppEngine 时才会出现此问题。

提前谢谢你。

【问题讨论】:

  • 那是因为该请求永远不会到达服务器。 hashbang 完全在客户端解决。您可能需要保护的是与该 hashbang 关联的视图,因此当您尝试获取该部分视图时,它会受到您的安全策略的保护。
  • @EdwinDalorzo 感谢您的帮助,保护我的 /index.html 页面的最佳做法是什么?
  • Spring 依赖于 MVC 在服务器端这一事实。但是 Angukar 将所有 MVC 转移到客户端。
  • @QhadR 那么有没有办法使用 Spring security 来保护它?
  • 请检查问题更新

标签: java angularjs spring google-app-engine spring-security


【解决方案1】:

我已经能够使用 web.xml 文件的 &lt;security-constraint&gt; 属性在 Google AppEngine 上使用 Spring MVC 保护静态文件。

例子:

<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>

【讨论】:

  • 在这里,我们可以按用户角色保护静态页面吗?
猜你喜欢
  • 2014-12-01
  • 1970-01-01
  • 2011-04-20
  • 2014-04-13
  • 2018-02-18
  • 2014-07-29
  • 2017-03-08
  • 2022-12-11
  • 2014-06-18
相关资源
最近更新 更多