LDAP成功登录后,如何将用户详细信息存储到数据库中?

时间:2019-06-11 14:29:23

标签: spring-boot spring-ldap

我正在使用Spring Boot应用程序,我需要通过添加LDAP身份验证使其安全。基于LDAPusername / password的身份验证过程正在运行,但是在成功登录并将用户数据(用户名,全名等)并将其存储到数据库中时,我很难。

1 个答案:

答案 0 :(得分:2)

您可以确定将LDAP用户的数据保存在数据库中。成功通过身份验证后,您可以调用自定义类,如下所示:

import org.springframework.security.ldap.userdetails.LdapUserDetailsMapper;

@Service
public class LDAPUserDetailsMapper extends LdapUserDetailsMapper{}

然后您可以覆盖该方法:

@Override
public UserDetails mapUserFromContext(DirContextOperations ctx, String username,
        Collection<? extends GrantedAuthority> authorities) {
/** your custom logic goes here. Here you can get the user details from ctx, 
and then use the information to store the data in db and then return the user details.**/
}