【发布时间】:2017-01-05 07:43:27
【问题描述】:
我有一个基于 Spring Security OAuth 2.0 的应用程序,配置了 JDBC 和 LDAP。根据 OAuth 2.0 规范,客户端密码必须。
当我使用以下 URL 生成令牌时,它会生成令牌并且工作正常:
/oauth/token?grant_type=password&client_secret=test&client_id=test&username=test&password=test
当我尝试在没有client_secret 的情况下生成令牌时,它给出:
401:未经授权
error_description:“错误的用户凭据”
但我想生成没有client_secret 的令牌,例如:
/oauth/token?grant_type=password&username=test&password=test
securityConfig.java:
@Configuration
@EnableWebSecurity
@EnableGlobalMethodSecurity( prePostEnabled = true )
public class ApplicationSecurityConfig extends WebSecurityConfigurerAdapter {
private static final int EMBEDDED_LDAP_SERVER_PORT = 33388;
@Autowired
private UserAuthenticationProvider userAuthenticationProvider;
@Autowired
private LdapAuthenticationProvider ldapAuthenticationProvider;
@Autowired
private AuthTokenStore oAuthTokenStore;
@Autowired
private AuthDelegatingAuthenticationEntryPoint delegatingAuthenticationEntryPoint;
@Override
@Qualifier("authenticationManagerBean")
@Bean
protected AuthenticationManager authenticationManager() throws Exception {
return new ProviderManager(Arrays.asList((AuthenticationProvider) ldapAuthenticationProvider,userAuthenticationProvider));
}
@Override
protected void configure(HttpSecurity http) throws Exception {
http
.csrf().disable()
.sessionManagement()
.sessionCreationPolicy(SessionCreationPolicy.STATELESS)
.and()
.authorizeRequests()
.anyRequest().authenticated()
.and()
.exceptionHandling().authenticationEntryPoint(delegatingAuthenticationEntryPoint);
}
@Bean
public ResourceServerTokenServices tokenService() {
DefaultTokenServices tokenServices = new DefaultTokenServices();
tokenServices.setTokenStore(oAuthTokenStore);
tokenServices.setReuseRefreshToken(true);
return tokenServices;
}
【问题讨论】:
-
如果授权类型是密码,你可以只传递 client_id 不需要客户端密码..like
/oauth/token?grant_type=password&username=test&password=test&client_id=CLIENT_ID -
我该如何处理这个网址? /oauth/token?grant_type=password&username=test&password=test&client_id=CLIENT_ID @PrasannaKumar
-
在安全配置中提及客户端 ID 并传递该客户端 ID...它将返回令牌
-
我应该在哪里通过 securityConfig 中的 client_id 并且我正在使用 ClientCredentialsTokenEndpointFilter 但它不起作用@PrasannaKumar
标签: java spring spring-security oauth spring-security-oauth2