ERROR TO MANY REDIRECTS Spring Security Core and Grails

Asked

Viewed 162 times

1

Good morning, I am developing a Grails application and decided to implement authorization and authentication the same is working perfectly however I decided to change the login form to my form and not the standard of Spring Security Core however I am having the following error when trying to access the URL in Google Chrome, "ERRO_TO_MANY_REDIRECTS", the line I changed in my Config.groovy was:

 // Added by the Spring Security Core plugin:
    grails.plugin.springsecurity.userLookup.userDomainClassName = 'org.lab2.security.User'
    grails.plugin.springsecurity.userLookup.authorityJoinClassName = 'org.lab2.security.UserRole'
    grails.plugin.springsecurity.authority.className = 'org.lab2.security.Role'

// Aqui entra as alterações feitas por mim

   grails.plugin.springsecurity.auth.loginFormUrl = '/areaRestrita/login'  //Mostra qual a tela de login
    rails.plugin.springsecurity.auth.afterLogoutUrl = '/areaRestrita/logout' //Mostra qual a tela de logout
    grails.plugin.springsecurity.successHandler.defaultTargetUrl = '/contato/index' //Mostra qual URL chamada caso o login funcione

// Aqui termina minhas alterações

    grails.plugin.springsecurity.controllerAnnotations.staticRules = [
        '/':                              ['permitAll'],
        '/index':                         ['permitAll'],
        '/index.gsp':                     ['permitAll'],
        '/assets/**':                     ['permitAll'],
        '/**/js/**':                      ['permitAll'],
        '/**/css/**':                     ['permitAll'],
        '/**/images/**':                  ['permitAll'],
        '/**/favicon.ico':                ['permitAll']
    ]

Being that the lines in bold were the ones added by me to determine the login and logout form, along with the initial page when logging in. If anyone has a solution I’ll be grateful for your help.

1 answer

2


Gustavo, what is happening is that your login page is '/areaRestrita/login', and to access this area is necessary to be logged in to the system. What happens? When accessing the login area, because it is a restricted area, the user is redirected to the Login page.

As it has no permission, it goes to the login page, and so continues indefinitely, until the exception is cast. I recommend that you indicate that the login page is not restricted, your code will look like this:

 // Added by the Spring Security Core plugin:
    grails.plugin.springsecurity.userLookup.userDomainClassName = 'org.lab2.security.User'
    grails.plugin.springsecurity.userLookup.authorityJoinClassName = 'org.lab2.security.UserRole'
    grails.plugin.springsecurity.authority.className = 'org.lab2.security.Role'

// Aqui entra as alterações feitas por mim

   grails.plugin.springsecurity.auth.loginFormUrl = '/areaRestrita/login'  //Mostra qual a tela de login
    rails.plugin.springsecurity.auth.afterLogoutUrl = '/areaRestrita/logout' //Mostra qual a tela de logout
    grails.plugin.springsecurity.successHandler.defaultTargetUrl = '/contato/index' //Mostra qual URL chamada caso o login funcione

// Aqui termina minhas alterações

    grails.plugin.springsecurity.controllerAnnotations.staticRules = [
        '/areaRestrita/login':            ['permitAll'], //Alteração para deixar a tela de login acessível a usuários anônimos.
        '/':                              ['permitAll'],
        '/index':                         ['permitAll'],
        '/index.gsp':                     ['permitAll'],
        '/assets/**':                     ['permitAll'],
        '/**/js/**':                      ['permitAll'],
        '/**/css/**':                     ['permitAll'],
        '/**/images/**':                  ['permitAll'],
        '/**/favicon.ico':                ['permitAll']
    ]

PS: I don’t have any Rails or grails environment installed here, I’ve never actually used grails, but I imagine that’s the problem. My research source was a similar error to yours: http://www.grailsbrasil.com/post/show/1568

  • Perfect guy, worked the page dr login was displayed however not logging in.

  • I suggest marking this answer as correct then and creating a new question regarding the login page, displaying its source code and further detailing the problem.

  • Modifying the login form for Spring Security Core and Groovy Grails - http://answall.com/q/63755/22504

  • Take a look at this case Maybe you can help me

  • I saw the problem you posted regarding the view, however, as I still have no reputation in pt.stackoverflow I can not comment there. You can also post the code of the controller that is receiving the request?

  • 1

    I did not post the controller code here due to the fact that this controller is generated by grails scaffolding dynamically this is the responsibility of Spring Security Core, however already found the solution was Tomcat error. Anything give a look there in the comment of the question.

Show 1 more comment

Browser other questions tagged

You are not signed in. Login or sign up in order to post.