简体   繁体   中英

Spring security doesn't work with angularJS

I have written an aplication using java and angularJS. Now I would like to add Spring Security but Spring isn't working with angular's paths.

Here are the security properties:

<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 is blocking all paths started by "/rest" so I can't open the registration page.

Spring is on server and it does know anything about #paths, which relates to client only. What you need to do is: 1. Use angular to hide views. (based on user role u accure from server) 2. Use spring to secure ajax calls.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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