Authentication Grails Spring安全性-在身份验证中使用其他属性

Authentication Grails Spring安全性-在身份验证中使用其他属性,authentication,grails,spring-security,Authentication,Grails,Spring Security,我只是想问一下,是否可以使用域类的用户名和密码以外的其他属性进行登录 例如,我有一个Person域类,它与Account域类有一对一的关系。我想使用Person域类中的firstName和birthDate属性对我的用户进行身份验证 是否有一种配置可以让这成为可能?是。那是可能的 您必须编写一个自定义的身份验证提供程序,在该提供程序中,您可以获取您想要进行身份验证的参数 例如,您可能会遇到如下情况: public class MyUserDetailsService implements Use

我只是想问一下,是否可以使用域类的用户名和密码以外的其他属性进行登录

例如,我有一个
Person
域类,它与
Account
域类有一对一的关系。我想使用
Person
域类中的
firstName
birthDate
属性对我的用户进行身份验证

是否有一种配置可以让这成为可能?

是。那是可能的

您必须编写一个自定义的
身份验证提供程序
,在该提供程序中,您可以获取您想要进行身份验证的参数

例如,您可能会遇到如下情况:

public class MyUserDetailsService implements UserDetailsService{
    @Override
    public UserDetails loadUserByUsername(String username){
        //You have to override this method to have your desired action
        //If those criteria are not satisfied you may return null
        //Otherwise have an UserDetails filled and returned
        org.springframework.security.core.userdetails.User userDetails = new org.springframework.security.core.userdetails.User(user.getUsername(), user.getPassword(), user.getIsActive(), true, true, true, getAuthorities(user));
        return userDetails

    }
<sec:authentication-manager alias="authenticationManager">
    <sec:authentication-provider user-service-ref="myUserDetailsService"/>
</sec:authentication-manager>
在bean配置中,使用自己的
身份验证提供程序
,如下所示:

public class MyUserDetailsService implements UserDetailsService{
    @Override
    public UserDetails loadUserByUsername(String username){
        //You have to override this method to have your desired action
        //If those criteria are not satisfied you may return null
        //Otherwise have an UserDetails filled and returned
        org.springframework.security.core.userdetails.User userDetails = new org.springframework.security.core.userdetails.User(user.getUsername(), user.getPassword(), user.getIsActive(), true, true, true, getAuthorities(user));
        return userDetails

    }
<sec:authentication-manager alias="authenticationManager">
    <sec:authentication-provider user-service-ref="myUserDetailsService"/>
</sec:authentication-manager>