gpt4 book ai didi

java - 如何在 Spring Security OAuth2 中生成没有 client_secret 的 token

转载 作者:搜寻专家 更新时间:2023-11-01 03:56:32 26 4
gpt4 key购买 nike

<分区>

我有一个基于 Spring Security OAuth 2.0 的应用程序,配置了 JDBC 和 LDAP。根据 OAuth 2.0 规范,客户端密码必须。

当我使用以下 URL 生成 token 时,它会生成 token 并正常工作:

/oauth/token?grant_type=password&client_secret=test&client_id=test&username=test&password=test

当我尝试在没有 client_secret 的情况下生成 token 时,它给出:

401: Unauthorized

error_description: "Bad User Credentials"

但我想生成没有 client_secret 的 token ,例如:

/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;
}

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com