ERROR TO MANY REDIRECTS Spring Security Core and Grails

1
Well, I'm developing a Grails application and I've decided to implement authorization and authentication. It's working perfectly, however. I've decided to change the login form to my form, not the Spring Security Core standard. However, I'm having the following error. try 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']
    ]

Since the bold line has been added by me to determine the form of login and logout, along with the home page when logging in. If someone has a solution, I'll be grateful for the help.

    
asked by anonymous 13.05.2015 / 17:06

1 answer

2

Gustavo, what is happening is that your login page is '/areaRestrita/login' , and to access this area you must be logged into the system. What happens? By accessing the login area, as this is a restricted area, the user is redirected to the Login page.

Because you do not have permission, you go to the login page, and so it continues indefinitely, until the exception is thrown. 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 have no rails or grails environment installed here, to tell you the truth, I have never used grails, but I imagine that is the problem. My search source was an error similar to yours: link

    
13.05.2015 / 17:55