springsecurity密码模式

1、在security配置文件添加bean

 @Override
    @Bean
    public AuthenticationManager authenticationManagerBean() throws Exception {
        return super.authenticationManagerBean();
    }

2、修改授权服务器配置

/**
 * 授权服务器配置
 *
 * @Author: wujun
 * @Date: 2022/3/30 14:39
 */
@Configuration
@EnableAuthorizationServer
public class AuthorizationServerConfig extends AuthorizationServerConfigurerAdapter {

    @Resource
    private PasswordEncoder passwordEncoder;

    @Resource
    private AuthenticationManager authenticationManager;

    @Resource
    private UserService userService;

    /**
     * 密码模式配置
     *
     * @param endpoints
     * @throws Exception
     */
    @Override
    public void configure(AuthorizationServerEndpointsConfigurer endpoints) throws Exception {
        endpoints.authenticationManager(authenticationManager)
                .userDetailsService(userService);
    }

    @Override
    public void configure(ClientDetailsServiceConfigurer clients) throws Exception {
        clients.inMemory()
                .withClient("gusulab")
                .secret(passwordEncoder.encode("112233"))
                .scopes("all")
                // 跳转成功地址
                .redirectUris("http://www.baidu.com")
                .authorizedGrantTypes("password");
    }
}

3、测试接口


image.png

你可能感兴趣的:(springsecurity密码模式)