【发布时间】:2019-04-27 06:33:41
【问题描述】:
我正在使用内存授权服务器构建简单的密码授权类型,用于演示目的,然后与我现有的 Web 应用程序集成。
不确定我是否缺少任何配置。
还尝试了 base64 url、表单数据和其他选项,但仍然从服务器获得相同的响应。
spring boot 基本安全性被 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();
}
}
【问题讨论】:
标签: java spring spring-boot oauth-2.0