-2

How to configure different target URLs after login based on user roles? I'm using Spring security plugin.

drago
  • 1,207
  • 4
  • 24
  • 45
  • try to search for that issue in stackoverflow. there are many questions facing your issue. e.g. http://stackoverflow.com/questions/6968210/grails-spring-security-redirect-after-login-success-failure – hitty5 Nov 15 '11 at 10:05
  • That's not what I'm trying to do. I want to send users to different views after succesfull login depending on their roles. For example after successfull login user with ROLL_USER role is redirected to userIndex.gsp and user with ROLL_ADMIN role is redirected to adminIndex.gsp. This is one solution I guess: [link](http://omarello.com/2011/09/grails-custom-target-urls-after-login/) – drago Nov 15 '11 at 12:17

2 Answers2

1

I think you can define a defaultTargetUrl just like Denis mention or like in this site: Grails spring security like hitty5 said.

And you can put the logic of the redirect depending on the role of the user in the response of that default request.

With grails:

in config.groovy

grails.plugins.springsecurity.successHandler.defaultTargetUrl = '/login/loggedIn'

in LoginController (because that controller contains the default action configured)

@Secured(['ROLE_ADMIN', 'ROLE_DEFAULT'])
    def loggedIn = {
        Usuario user = springSecurityService.currentUser
        def roleDefault = Rol.findByAuthority("ROLE_DEFAULT")
        if(user.authorities.contains(roleDefault))
            redirect(controller: 'factura')
        def roleAdmin = Rol.findByAuthority("ROLE_ADMIN")
        if(user.authorities.contains(roleAdmin))
            redirect(controller: 'noticia')
    }

I hope it helps...

Community
  • 1
  • 1
mpccolorado
  • 817
  • 8
  • 16
0
<form-login
            login-processing-url="/user/login"
            login-page="/login"
            default-target-url="/loginsuccess"
            authentication-failure-url="/loginfailure" />

Why you couldn't do redirect to another page after check user role in Spring controller which mapped on the loginsuccess url?

Denis Loshkarev
  • 632
  • 7
  • 14