【问题标题】:Spring-Boot-Security: Custom AuthenticatorSpring-Boot-Security:自定义身份验证器
【发布时间】:2021-04-21 04:22:58
【问题描述】:

我从 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");
}

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

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

感谢您的帮助!

【问题讨论】:

标签: java spring spring-boot spring-security


【解决方案1】:

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

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

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

【讨论】:

    猜你喜欢
    • 2020-12-05
    • 2014-04-20
    • 2014-12-13
    • 2016-08-05
    • 2015-04-27
    • 2014-01-12
    • 2016-09-05
    • 2016-10-31
    • 1970-01-01
    相关资源
    最近更新 更多