我在OAuth2上遇到错误。我需要检索一个令牌才能开始使用这个工具,以保护我的资源。我想将它集成到我的所有请求映射中。
我将为授权和令牌端点添加错误。我希望有人管理过oauth2 ...非常感谢!
我的OauthServerConfig:
@Configuration
public class OAuth2ServerConfigAuthorizationServerConfiguration {
private static final String RESOURCE_ID = "restservice";
@Configuration
@EnableResourceServer
protected static class ResourceServerConfiguration extends
ResourceServerConfigurerAdapter {
@Override
public void configure(ResourceServerSecurityConfigurer resources) {
// @formatter:off
resources
.resourceId(RESOURCE_ID);
// @formatter:on
}
public void configure(HttpSecurity http) throws Exception {
// @formatter:off
http
.authorizeRequests()
.antMatchers("/api/**").authenticated();
// @formatter:on
}
}
@Configuration
@EnableAuthorizationServer
protected static class AuthorizationServerConfiguration extends
AuthorizationServerConfigurerAdapter {
private TokenStore tokenStore = new InMemoryTokenStore();
@Autowired
@Qualifier("authenticationManagerBean")
private AuthenticationManager authenticationManager;
@Override
public void configure(AuthorizationServerEndpointsConfigurer endpoints)
throws Exception {
// @formatter:off
endpoints
.tokenStore(this.tokenStore)
.authenticationManager(this.authenticationManager);
// .pathMapping("/oauth/token", "/entuzona/oauth/token");
// @formatter:on
}
@Override
public void configure(ClientDetailsServiceConfigurer clients) throws Exception {
// @formatter:off
clients
.inMemory()
.withClient("clientapp")
.authorizedGrantTypes("password","refresh_token")
.authorities("USER")
.scopes("read", "write")
.resourceIds(RESOURCE_ID)
.secret("123456");
// @formatter:on
}
@Bean
@Primary
public DefaultTokenServices tokenServices() {
DefaultTokenServices tokenServices = new DefaultTokenServices();
tokenServices.setSupportRefreshToken(true);
tokenServices.setTokenStore(this.tokenStore);
return tokenServices;
}
}
}
我的OauthClientConfig:
@Configuration
@ComponentScan({"com.sprhib"})
@EnableWebSecurity
@EnableWebMvcSecurity
public class OAuth2ClientConfig
extends WebSecurityConfigurerAdapter
{
protected void configure(AuthenticationManagerBuilder auth)
throws Exception
{
auth.inMemoryAuthentication().withUser("teste").password("teste").authorities("USER");
}
@Bean
public AuthenticationManager authenticationManagerBean()
throws Exception
{
return super.authenticationManagerBean();
}
}
如果我想制作/ oauth / authorize /:
关于我的要求有什么问题的任何想法?