繁体   English   中英

AngularJS和Spring Security。 如何使用Spring Security处理AngularJS Urls

[英]AngularJS and Spring Security. How to handle AngularJS Urls with Spring Security

让我解释一下我的问题。 我已经在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安全性,以捕获每个调用并检查其是否具有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>

如果用户具有正确的ROLES,此配置将检查每个调用的URL,并且工作正常,并抛出401未经授权页面。

我遇到的问题是,当我将登录页面设置为所有人均可访问时,我将通过以下方式进行操作:

<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的权限,但未找到此页面。 有人知道这里会发生什么吗?

提前致谢!!!

我编写了一个小示例应用程序 ,通过将会话ID公开为HTTP标头(x-auth-token)来说明如何将AngularJS与Spring Security集成。 该示例还提供了一些(简单)授权(从服务器返回角色),以便客户端AngularJS应用程序可以对此做出反应。 当然,这主要是出于用户体验(UX)的目的。 始终确保REST端点具有属性安全性。

我的博客文章在这里

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM