I am facing a really strange issue. The switch user feature is throwing 404 page not found error on our main application but it works in a new hello world app.
First of all i am using Grails 4.0.10 and spring security compile 'org.grails.plugins:spring-security-core:4.0.3'
the switch user form looks like this
<form action='${request.contextPath}/login/impersonate' method='POST'>
<input type="hidden" name="username" value="${user.email}"/>
<input type="hidden" name="${grailsApplication.config.grails.plugins.springsecurity.successHandler.targetUrlParameter}" value="/user/index"/>
<input type='submit' value="${message(code: 'user.button.switch.user')}" class="button"/>
</form>
the error thrown is
2022-08-31 00:24:20.851 WARN --- [nio-8443-exec-4] o.s.web.servlet.PageNotFound : No mapping for POST /roadrace/login/impersonate
the strange thing is i have implemented a simple switch user in a new hello world app following tutorial from https://grails.github.io/grails-spring-security-core/4.0.x/index.html#switchUser it works in the hello world app but not in my main application. i have double checked all the configuration are in place
here are the relevant configuration
in application.groovy i have
grails.plugin.springsecurity.useSwitchUserFilter = true
grails.plugin.springsecurity.interceptUrlMap = [
[pattern: '/login/impersonate', access: ['ROLE_ADMIN', 'IS_AUTHENTICATED_FULLY']]
]
grails.plugin.springsecurity.controllerAnnotations.staticRules = [
//'/public/**': 'ANY_CHANNEL',
[pattern: '/homePage/**', access: 'ANY_CHANNEL'],
[pattern: '/race/search*', access: 'ANY_CHANNEL'],
[pattern: '/images/**', access: 'ANY_CHANNEL'],
[pattern: '/uploads/**', access: 'ANY_CHANNEL'],
[pattern: '/css/**', access: 'ANY_CHANNEL'],
[pattern: '/js/**', access: 'ANY_CHANNEL'],
[pattern:'/static/**' , access: 'ANY_CHANNEL'],
[pattern: '/error/**', access: 'ANY_CHANNEL'],
[pattern: '/grails**', access: 'ANY_CHANNEL'],
[pattern:'/grails/**' , access:'ANY_CHANNEL' ],
[pattern: '/login/impersonate', access: ['ROLE_ADMIN', 'IS_AUTHENTICATED_FULLY']],
[pattern: '/logout/index', access: 'ANY_CHANNEL'],
[pattern: '/*', access: 'ANY_CHANNEL'],
[pattern: '/*/**', access: 'REQUIRES_SECURE_CHANNEL']
]
these are the minimal configuration to make switch user feature work.
what could be preventing the switch user feature to work or what could cause /login/impersonate to be not found?
I am also sharing the hello world app i created to test switch user
https://github.com/sanjaygir/switchuserhelloworld
if you run this grails 4 app and go to http://localhost:8080/secure/index there are two users with username me and me2 and the password is password. You can login as me with password password then in the switch user box you can type me2 and click switch. if you go again at http://localhost:8080/secure/index you can see it switched to me2.
i have used all the same configuration from this hello world app in my main app. it works in hello world app but it doesnt work in main app i.e it is throwing 404 when posting to /login/impersonate.
I appreciate any guidance to this strange issue? Thanks!