Em chào anh trong quá trình chuyển spring 2.4.x lên 3.1.x phần xác thực oauth2 trong dự án em gặp vấn đề
- Spring 3.1.x không còn hỗ trợ WebSecurityConfigurerAdapter Lib spring-security-oauth2-autoconfigure
em chuyển sang các thư viện thay thế
spring-boot-starter-oauth2-resource-server 3.1.4
spring-boot-starter-oauth2-client 3.1.4
spring-security-oauth2-authorization-server 1.1.3
và cấu hình
spring.security.oauth2.client.registration.sales.authorization-grant-type=password,authorization_code
spring.security.oauth2.client.registration.sales.client-id=sales
spring.security.oauth2.client.registration.sales.client-secret=password
spring.security.oauth2.client.registration.sales.scope[0]=user_info
spring.security.oauth2.client.provider.sales.authorization-uri=http://port:8668/sso-server/oauth/check_token
nhưng có vẻ không hoạt động
làm sao để cấu hình lại phần oauth2 ạ
code config ban đầu
@Configuration
@EnableResourceServer
@EnableGlobalMethodSecurity(prePostEnabled = true)
public class ResourceServer extends ResourceServerConfigurerAdapter {
@Value("")
private String tokenEndpointUrl;
@Value("")
private String clientId;
@Value("")
private String clientSecret;
@Bean
public RemoteTokenServices tokenServices() throws KeyStoreException, NoSuchAlgorithmException, KeyManagementException {
RemoteTokenServices tokenServices = new RemoteTokenServices(); tokenServices.setCheckTokenEndpointUrl(tokenEndpointUrl);
tokenServices.setClientId(clientId);
tokenServices.setClientSecret(clientSecret);
return tokenServices; }
@Override public void configure(HttpSecurity http) throws Exception {
http.cors().and()
.requestMatchers().antMatchers("/api/**").and().authorizeRequests().anyRequest().authenticated();
} }