没有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.