【问题标题】:Spring security doesn't work with angularJSSpring 安全性不适用于 angularJS
【发布时间】:2015-03-18 16:53:18
【问题描述】:

我已经使用 java 和 angularJS 编写了一个应用程序。现在我想添加 Spring Security,但 Spring 不适用于 Angular 的路径。

以下是安全属性:

<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" use-expressions="true">

        <intercept-url pattern="/login" access="permitAll" />
        <intercept-url pattern="/rest#/registration" access="permitAll" />
        <intercept-url pattern="/rest**" access="hasRole('ROLE_USER')" />

        <form-login login-page="/login" 
            default-target-url="/rest"
            authentication-failure-url="/login?error" username-parameter="username"
            password-parameter="password" />
        <logout logout-success-url="/login?logout" />
    </http>

    <authentication-manager>
        <authentication-provider user-service-ref="myUserDetailsService">
            <password-encoder hash="md5" />
        </authentication-provider>
    </authentication-manager>

</beans:beans>

Spring 阻止了所有由“/rest”启动的路径,所以我无法打开注册页面。

【问题讨论】:

    标签: java angularjs spring spring-mvc


    【解决方案1】:

    Spring 在服务器上,它确实知道关于#paths 的任何信息,它只与客户端相关。你需要做的是: 1.使用角度隐藏视图。 (基于您从服务器获得的用户角色) 2.使用spring来保护ajax调用。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-09-22
      • 2020-10-02
      • 1970-01-01
      • 2015-03-05
      • 2019-05-25
      • 2016-10-26
      • 2014-09-04
      • 2017-11-23
      相关资源
      最近更新 更多