这是使用旧形式的旧形式action
地址(导致重定向的核心问题)和用户名/密码的旧名称(潜在的问题会更令人沮丧,因为它总是会以正确的值失败,因为如果设置错误,它们将不可用参数名称)。
在 3.x 中覆盖插件文件并不像在 2.x 中那么简单。在 2.x 中,插件是在项目根目录中解压的 zip 文件target
目录,您可以使用插件源做有效和/或疯狂的事情。在 3.x 中,插件是编译后的 jar,因此希望我们减少了疯狂的总量,但我们也让做这样的有效事情变得更加困难。
但这是开源软件,确切的 .gsp 文件或足够接近的文件很容易在源代码库中找到,即here https://github.com/grails-plugins/grails-spring-security-core.
auth.gsp
很少改变,所以得到它很好master 分支的最新文件 https://github.com/grails-plugins/grails-spring-security-core/blob/master/plugin/grails-app/views/login/auth.gsp,或者您可以查看历史记录(最近的版本是,未来的版本将继续被标记),这样很容易获得旧版本,例如从3.0.4版本开始 https://github.com/grails-plugins/grails-spring-security-core/blob/v3.0.4/grails-app/views/login/auth.gsp.
但这不一定是最终答案,因为该插件是非常可配置的,并且您可以覆盖配置中 GSP 中使用的多个变量,因此您应该仅用值替换查找值的代码,因为您的应用程序不太可能从中受益灵活性。配置设置的默认值位于DefaultSecurityConfig.groovy
,但我将此 GSP 留在查找代码中,因此您只需删除它并保留值即可。
这是内部form
元素(您需要整个文件,但我没有显示不需要更改的部分):
<form action="${postUrl ?: '/login/authenticate'}" method="POST" id="loginForm" class="cssform" autocomplete="off">
<p>
<label for="username"><g:message code='springSecurity.login.username.label'/>:</label>
<input type="text" class="text_" name="${usernameParameter ?: 'username'}" id="username"/>
</p>
<p>
<label for="password"><g:message code='springSecurity.login.password.label'/>:</label>
<input type="password" class="text_" name="${passwordParameter ?: 'password'}" id="password"/>
</p>
<p id="remember_me_holder">
<input type="checkbox" class="chk" name="${rememberMeParameter ?: 'remember-me'}" id="remember_me" <g:if test='${hasCookie}'>checked="checked"</g:if>/>
<label for="remember_me"><g:message code='springSecurity.login.remember.me.label'/></label>
</p>
<p>
<input type="submit" id="submit" value="${message(code: 'springSecurity.login.button')}"/>
</p>
</form>
对于初始传递,您需要将其更改为:
<form action="/login/authenticate' method="POST" id="loginForm" class="cssform" autocomplete="off">
<p>
<label for="username"><g:message code='springSecurity.login.username.label'/>:</label>
<input type="text" class="text_" name="username" id="username"/>
</p>
<p>
<label for="password"><g:message code='springSecurity.login.password.label'/>:</label>
<input type="password" class="text_" name="password" id="password"/>
</p>
<p id="remember_me_holder">
<input type="checkbox" class="chk" name="remember-me" id="remember_me"/>
<label for="remember_me"><g:message code='springSecurity.login.remember.me.label'/></label>
</p>
<p>
<input type="submit" id="submit" value="${message(code: 'springSecurity.login.button')}"/>
</p>
</form>
您可以使用您想要的任何帖子 url 和用户名/密码参数名称,包括旧的参数名称,但您需要设置配置属性,以便处理登录的 Spring Security 过滤器正在查看正确的 uri 并期望您的参数名称重发。如果您同意默认值,那么这将起作用,您当然可以进行任何您想要的常规 HTML 和 CSS/JS 更改。