Redirect Loop with Requestmap with grails spring security core 2.0RC4

末鹿安然 提交于 2019-12-25 03:27:29

问题


I have been facing Failed to load resource: net::ERR_TOO_MANY_REDIRECTS with grails 2.4.4. I have User, Role and Requestmap in com.usermanagement.auth package(those were generated with s2-quickstart). Requestmaps, users and roles seem to be stored in the database(I am using mysql).

BuildConfig.groovy

compile ":spring-security-core:2.0-RC4"

Bootstrap.groovy on init method

        User admin = new User(username:'admin', password:'secret', enabled:true).save()
        User john = new User(username:'john', password:'secret', enabled:true).save()
        User jane = new User(username:'jane', password:'secret', enabled:true).save()
        Role royalty = new Role(authority: 'ROLE_ROYALTY').save()
        Role common = new Role(authority: 'ROLE_COMMON').save()
        UserRole.create(admin, royalty)
        UserRole.create(admin, common)
        UserRole.create(john, common)

        for (String url in [
                '/', '/index', '/index.gsp', '/**/favicon.ico',
                '/assets/**', '/**/js/**', '/**/css/**', '/**/images/**',
                '/login', '/login.*', '/login/*',
                '/logout', '/logout.*', '/logout/*']) {
            new Requestmap(url: url, configAttribute: 'permitAll').save()
        }

        new Requestmap(url: '/*', configAttribute: 'IS_AUTHENTICATED_ANONYMOUSLY').save();
        new Requestmap(url: '/dbconsole/**', configAttribute: 'permitAll').save();
        new Requestmap(url: '/logout/**', configAttribute: 'IS_AUTHENTICATED_REMEMBERED,IS_AUTHENTICATED_FULLY').save();
        new Requestmap(url: '/login/**', configAttribute: 'IS_AUTHENTICATED_ANONYMOUSLY').save();
        new Requestmap(url: '/index/**', configAttribute: 'IS_AUTHENTICATED_ANONYMOUSLY').save();
        new Requestmap(url: '/', configAttribute: 'permitAll').save();

Config.groovy

// Added by the Spring Security Core plugin:
grails.plugin.springsecurity.userLookup.userDomainClassName = 'com.usermanagement.auth.User'
grails.plugin.springsecurity.userLookup.authorityJoinClassName = 'com.usermanagement.auth.UserRole'
grails.plugin.springsecurity.authority.className = 'com.usermanagement.auth.Role'
grails.plugin.springsecurity.requestMap.className = 'com.usermanagement.auth.Requestmap'
grails.plugin.springsecurity.securityConfigType = 'Requestmap'
grails.plugin.springsecurity.rejectIfNoRule = true

Whenever I try to access localhost:8080/appname/, this results in too many redirects error after being redirected to http://localhost:8080/appname/login/auth. What may be causing this issue? I am even unable to access dbconsole.


回答1:


As it turns out, this had been a bug as mentioned in https://jira.grails.org/browse/GPSPRINGSECURITYCORE-312. Spring Security Core is unable to load RequestMaps stored in the database in Grails 2.4.4. I followed a work around mentioned in the link; I basically downgraded the hibernate plugin from 4.3.6.1 to 4.3.5.5. There are other workaround mentioned. But this worked for me.

// runtime ":hibernate4:4.3.6.1" // or ":hibernate:3.6.10.18"
runtime ":hibernate4:4.3.5.5" // or ":hibernate:3.6.10.17"



回答2:


I encountered the same problem with Grails 3.2.3 and spring-security-core:3.1.1. The hibernate5 plugin was causing the problem. After changing to the hibernate4 plugin, it appears to be working correctly.




回答3:


Its works for me....

    if (!Requestmap.count()) {

        for (String url in [
                '/' , '/error', '/index', '/index.gsp', '/**/favicon.ico', '/shutdown',
                '/**/js/**', '/**/css/**', '/**/images/**',
                '/login', '/login.*', '/login/*',
                '/logout', '/logout.*', '/logout/*', '/assets/**','/home/repopulate']) {
            new Requestmap(url: url, configAttribute: 'permitAll').save(flush:true)
        }

        new Requestmap(url: "/**", configAttribute: 'ROLE_ADMIN').save(flush:true)

        //TODO: eliminar para cerrar por roles el request
        //new Requestmap(url: '/**', configAttribute: 'IS_AUTHENTICATED_FULLY').save(flush:true)

    }
    springSecurityService.clearCachedRequestmaps()


来源:https://stackoverflow.com/questions/28628398/redirect-loop-with-requestmap-with-grails-spring-security-core-2-0rc4

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!