没有UserDetailsS​​ervice方法的Spring Boot基本身份验证 [英] Spring boot basic authentication without UserDetailsService method

查看:77
本文介绍了没有UserDetailsS​​ervice方法的Spring Boot基本身份验证的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在我的应用中实现自定义基本身份验证,但是我不想使用UserDetailsS​​ervice方法...

I want to implement a custom basic authentication on my aplication, but i dont want to use the UserDetailsService method...

@Override
public UserDTO loadUserByEmail(String email) {
    UserDTO user = userMapper.usertoUserDTO(userRepository.findByEmail(email));

    if (user == null) {
        throw new UsernameNotFoundException(email);
    }

    return user;
}

因为我想使用自己的服务来检索用户.

Because i want to use my own service to retrieve the user.

之后,它会在我的回复中设置authorizator标头...有人可以帮我吗?

After that it set the authorizator header on my response... Can some one help me please?

我可以进行基本身份验证吗,还是需要使用jwt或类似的东西?

Can i make with basic authentication or i'll need to use jwt or something like this?

推荐答案

UserDetailsS​​ervice 只是一个接口,您应该使用自己的实现来加载用户并返回(可能是您自己的) UserDetails 界面,然后Spring会验证密码,其余的工作将

UserDetailsService is just an interface and you should use your own implementation to load the user and return ( possibly your own ) implementation of UserDetails interface and then Spring will verify the password do the rest.

之后,它会在我的回复中设置authorizator标头...有人可以帮我吗?

After that it set the authorizator header on my response... Can some one help me please?

即使在实现自己的 AuthenticationProvider 时也无济于事,因为您在上下文中还没有 ServletRequest 对象,但是只有 Authentication 详细信息

Even implementing your own AuthenticationProvider will not help here because you already don't have a ServletRequest object in context, but only Authentication details.

为此,我相信您可能需要改用 ServletFilter .

For this I believe you might need to use a ServletFilter instead.

这篇关于没有UserDetailsS​​ervice方法的Spring Boot基本身份验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆