Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/url/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
AngularJS和Spring Security。如何使用Spring安全性处理AngularJS URL_Spring_Url_Angularjs_Spring Security - Fatal编程技术网

AngularJS和Spring Security。如何使用Spring安全性处理AngularJS URL

AngularJS和Spring Security。如何使用Spring安全性处理AngularJS URL,spring,url,angularjs,spring-security,Spring,Url,Angularjs,Spring Security,让我解释一下我的问题。 我在AngularJS中实现了一个站点,访问方式如下: http://localhost:8080/example/resources/#/ 在这里,我们可以调用不同的页面,例如登录页面: http://localhost:8080/example/resources/#/login 管理页面: http://localhost:8080/example/resources/#/admin 用户页面: http://localhost:8080/example/re

让我解释一下我的问题。 我在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_用户权限。到目前为止,我已经在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,如果用户具有适当的角色,并且工作正常,则抛出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>

但是我不知道为什么SpringSecurity没有捕获这个URL。也许Angular对URL的管理有所不同

最后,我尝试删除
,并仅授予/login**对角色用户的访问权限,但未找到此页面。有人知道这里会发生什么吗

提前感谢

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


我的博客帖子是

,所以这真的与Angular无关。你知道吗?#之后的URL的所有部分都只被浏览器看到?Angular更改地址栏中的URL,但没有向服务器发出请求。向服务器发出的唯一请求是用于获取部分和调用REST服务的AJAX请求。这就是您必须确保的:其余服务。