Spring-Boot-Security:自定义身份验证器

时间:2021-01-16 08:56:31

标签: java spring spring-boot spring-security

我从 Spring-Boot 开始,并且有一个带有 WebSecurity 的应用程序。 它工作正常,我使用静态用户/密码进行 InMemory 身份验证。

现在我不需要 DB 或 LDAP 或 ...

@Override
public void configure (AuthenticationManagerBuilder auth) throws Exception
{
    auth.inMemoryAuthentication ()
        .withUser ("sam").
        .password (passwordEncoder ().encode ("secret"))
        .authorities ("ROLE_USER");
}

但我想构建一个使用动态数据的自定义身份验证器(例如,密码中包含当前时间)。

如何实现自定义身份验证器?如何查看用户名和密码并进行检查?

感谢您的帮助!

1 个答案:

答案 0 :(得分:1)

要提供自定义身份验证,您可以参考此链接 https://youtu.be/TNt3GHuayXs 并查看用户名和密码以进行检查,您可以使用这样的主体对象

 Object principal= SecurityContextHolder.getContext().getAuthentication().getPrincipal();

如果您需要更多信息,请告诉我

相关问题