0

I have a web application using spring 3.2.The login process is done through spring security.When a user gives a url to view the profile of a particular user he will redirect to login page if he is not logged in.I need to go back to the user's profile if he is not successfully logged in.Since I am using angular js my urls are in the form

http://mydomain.com/#/view-profile/71 to view the profile of the user.If I am not logged in it will redirect to login page.In the browser url becomes http://mydomain.com/login#/view-profile/71 but after successful login it is not redirecting to the specified url.How can I make that with angularjs.

In app.js I have given like this

$routeProvider.when('/view-profile/:id',
    {
        templateUrl: '/partials/editor/view-profile.htm',
        action: 'kc.view-profile',
        resolve: {
            loadData: ViewCtrl.loadUserProfile
        }
    }
);

And for authentication in security.xml it is written like

    <http use-expressions="true">
            <!-- Authentication policy -->
            <form-login login-page="/login" login-processing-url="/j_security_check" authentication-failure-url="/login?error=true"/>
            <logout logout-url="/signout" delete-cookies="JSESSIONID" />
            <intercept-url pattern="/assets/**" access="permitAll" />
            <intercept-url pattern="/application/signin/**" access="permitAll" />
            <intercept-url pattern="/application/signup/**" access="permitAll" />
            <intercept-url pattern="/application/manage/**" access="ROLE_EDITOR" />
            <interce

pt-url pattern="/application/**" access="isAuthenticated()"  />
        <!--<intercept-url pattern="/application/connect/**" access="permitAll" />-->
    </http>


    <authentication-manager alias="authenticationManager">
        <authentication-provider user-service-ref="userDao">
            <password-encoder ref="passwordEncoder"/>
        </authentication-provider>
    </authentication-manager>
2

1 Answer 1

1

Spring Security doesn't support Ajax login out-of-the-box, that's why your application isn't working correctly.

You can have a look at this sample application that handles Ajax login/logout with AngularJS + Spring Security:

https://github.com/jhipster/jhipster-sample-app

I had to implement some specific Ajax handlers, as you can see here:

https://github.com/jhipster/jhipster-sample-app/tree/master/src/main/java/com/mycompany/myapp/security

Sign up to request clarification or add additional context in comments.

1 Comment

The sample app that you have pointed out looks really good in case of having a login form within angular. And I really liked the way the http-auth-interceptor scripts work. But I'm trying to find pretty much the same concept except for Spring Security being implemented with a SSO concept like Siteminder. That would be a great help for a lot of folks out there. Thanks ! Really appreciate your work :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.