【发布时间】:2013-07-16 08:34:47
【问题描述】:
让我解释一下我的问题。 我在 AngularJS 中实现了一个站点,可以这样访问:
http://localhost:8080/example/resources/#/
这里我们可以调用不同的页面,例如登录页面:
http://localhost:8080/example/resources/#/login
管理页面:
http://localhost:8080/example/resources/#/admin
用户页面:
http://localhost:8080/example/resources/#/user
现在,我在示例中实现了 Spring Security,以便捕获每个调用并检查它是否具有 ROLE_USER 权限。到目前为止一切顺利,我在 Spring 安全上下文文件中做了这样的配置:
<security:http create-session="stateless" entry-point-ref="restAuthenticationEntryPoint"
authentication-manager-ref="authenticationManager">
<security:custom-filter ref="customRestFilter" position="BASIC_AUTH_FILTER" />
<security:intercept-url pattern="/**" access="ROLE_USER" />
</security:http>
此配置检查每个调用的 url,如果用户具有正确的 ROLES,并且它工作正常,则抛出 401 Unauthorized page。
我遇到的问题是,当我让每个人都可以访问登录页面时,我会这样做:
<security:http create-session="stateless" entry-point-ref="restAuthenticationEntryPoint"
authentication-manager-ref="authenticationManager">
<security:custom-filter ref="customRestFilter" position="BASIC_AUTH_FILTER" />
<security:intercept-url pattern="/login**" access="ROLE_ANONYMOUS" />
<security:intercept-url pattern="/**" access="ROLE_USER" />
</security:http>
但我不知道为什么 spring security 没有捕捉到这个 URL。也许 Angular 以不同的方式管理 URL。
最后,我尝试删除 <security:intercept-url pattern="/**" access="ROLE_USER" /> 并仅授予 /login** 对 ROLE_USER 的访问权限,但未找到此页面。有人知道这里会发生什么吗?
提前致谢!!!
【问题讨论】:
-
所以这真的与 Angular 无关
-
你知道#之后的所有URL部分都只能被浏览器看到吗? Angular 更改了地址栏中的 URL,但没有向服务器发出请求。向服务器发出的唯一请求是用于获取部分和调用 REST 服务的 AJAX 请求。这就是您必须保护的东西:REST 服务。
标签: spring url angularjs spring-security