【发布时间】:2020-07-01 20:58:44
【问题描述】:
我正在尝试创建一个登录页面,该页面将根据用户拥有的角色登录到特定帐户,但由于某种原因,spring security 永远不会识别用户名和密码
这里是登录控制器
package login_page
导入 grails.plugin.springsecurity.userdetails.DefaultPostAuthenticationChecks 导入 org.springframework.security.access.annotation.Secured
@Secured('permitAll') 类 LoginController 扩展 grails.plugin.springsecurity.LoginController {
PersonService personService
def index() {
if (isLoggedIn()) {
redirect uri: conf.successHandler.defaultTargetUrl
}
else {
redirect action: 'auth', params: params
}
}
def auth() {
def conf = getConf()
if (isLoggedIn()) {
redirect uri: conf.successHandler.defaultTargetUrl
return
}
String postUrl = request.contextPath + conf.apf.filterProcessesUrl
render view: 'index', model: [postUrl: postUrl,
rememberMeParameter: conf.rememberMe.parameter,
usernameParameter: conf.apf.usernameParameter,
passwordParameter: conf.apf.passwordParameter,
]
}
}
成功的 uri 是 /person/LoginPage
LoginPage 方法是这样的
@Secured(['ROLE_USER','ROLE_ADMIN','ROLE_SUPERADMIN'])
def LoginPage() {
refreshCurrentUser()
if (currentPerson == null) {
notFound()
}else {
if(currentPerson.getAuthorities()[0].getAuthority()=="ROLE_SUPERADMIN"){
redirect(controller:'superAdmin', action: 'superAdminShow', id: currentPerson.id)
}
else if(currentPerson.getAuthorities()[0].getAuthority()=="ROLE_ADMIN"){
redirect(controller:'admin', action: 'adminShow', id: currentPerson.id)
}
else if(currentPerson.getAuthorities()[0].getAuthority()=="ROLE_USER"){
redirect(action: 'show', id: currentPerson.id)
}
}
}
【问题讨论】:
-
另外,伙计们,我有一个带有表单操作的自定义登录页面:- /login/authenticate
-
spring 对安全性真的很挑剔,如果在声明 spring-boot 时它在路径中,它会启动,阻止一切,因为它没有配置。
-
是的,这就是为什么我要覆盖 index 和 auth 方法,但由于某种原因,它无法识别我为 person 对象拥有的用户名和密码
-
我的观点是,当安全 jar 在路径中,并且没有进行安全更改时,它通常会返回权限错误,直到设置安全,这是我的 spring-boot 经验
-
所以我们可以通过提供用户名和密码凭据来设置安全性吗?