Я создаю простой тип предоставления пароля с помощью сервера авторизации в памяти для демонстрационной цели, а затем для интеграции с моим существующим веб-приложением.
Не уверен, что мне не хватает какой-либо конфигурации.
Также пробовал с URL-адресом base64, данными формы и другими параметрами, но по-прежнему получал тот же ответ от сервера.
Базовая безопасность при весенней загрузке отключена с management.security.enabled = false
Сервер авторизации
@Configuration
@EnableAuthorizationServer
@EnableAutoConfiguration
public class AuthorizationServerConfig extends AuthorizationServerConfigurerAdapter {
@Autowired
private AuthenticationManager authenticationManager;
@Autowired
private TokenStore tokenStore;
@Override
public void configure (AuthorizationServerEndpointsConfigurer endpoints) throws Exception {
endpoints
.authenticationManager (authenticationManager)
.tokenStore (tokenStore);
}
@Bean
public TokenStore tokenStore () {
return new InMemoryTokenStore ();
}
@Bean
public PasswordEncoder passwordEncoder () {
return new BCryptPasswordEncoder ();
}
@Override
public void configure(ClientDetailsServiceConfigurer clients) throws Exception {
clients.inMemory().withClient("java-client").secret(passwordEncoder (). encode ("java-secret"))
.authorities ("ROLE_CLIENT", "ROLE_TRUSTED_CLIENT", "USER")
.autoApprove (true)
.authorizedGrantTypes("authorization_code", "refresh_token", "password").scopes("read", "write");
}
}
// Security Config
@Configuration
@EnableWebSecurity
public class SecurityConfig extends WebSecurityConfigurerAdapter {
@Override
protected void configure(HttpSecurity http) throws Exception { // @formatter:off
http.authorizeRequests()
.antMatchers("**").permitAll();
} // @formatter:on
@Bean
public BCryptPasswordEncoder passwordEncoder(){
return new BCryptPasswordEncoder();
}
@Autowired
public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception{
auth.inMemoryAuthentication().withUser("user").password("password").roles("USER");
}
public void configure(AuthorizationServerSecurityConfigurer security) throws Exception {
security.allowFormAuthenticationForClients();
}
}