I want to migrate this Spring security configuration to latest Spring Cloud:
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.security.oauth2.resource.ResourceServerProperties;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.oauth2.config.annotation.web.configuration.ResourceServerConfigurerAdapter;
import org.springframework.security.oauth2.config.annotation.web.configurers.ResourceServerSecurityConfigurer;
import org.springframework.security.oauth2.provider.error.OAuth2AuthenticationEntryPoint;
import org.springframework.security.oauth2.provider.token.DefaultAccessTokenConverter;
import org.springframework.security.oauth2.provider.token.DefaultTokenServices;
import org.springframework.security.oauth2.provider.token.TokenStore;
import org.springframework.security.oauth2.provider.token.store.JwtAccessTokenConverter;
import org.springframework.security.oauth2.provider.token.store.JwtTokenStore;
public class DefaultSecurityConfig extends ResourceServerConfigurerAdapter {
@Autowired
private ResourceServerProperties resource;
@Autowired
private CustomUserDataAuthenticationConverter customUserDataAuthenticationConverter;
public DefaultSecurityConfig() {
}
@Override
public void configure(final HttpSecurity http) throws Exception {
http.authorizeRequests()
.antMatchers("/configuration/**",)
.permitAll();
http.authorizeRequests().antMatchers("/**").authenticated();
final OAuth2AuthenticationEntryPoint oAuth2AuthenticationEntryPoint =
new CustomOAuth2AuthenticationEntryPoint();
http.exceptionHandling().authenticationEntryPoint(oAuth2AuthenticationEntryPoint);
}
@Override
public void configure(final ResourceServerSecurityConfigurer resources) {
resources.tokenServices(tokenServices());
resources.resourceId(resource.getResourceId());
}
private TokenStore customTokenStore() {
return new JwtTokenStore(accessTokenConverter());
}
private JwtAccessTokenConverter accessTokenConverter() {
JwtAccessTokenConverter converter = new NonValidatingAccessTokenConverter();
converter.setAccessTokenConverter(customAccessTokenConverter());
return converter;
}
private DefaultTokenServices tokenServices() {
DefaultTokenServices defaultTokenServices = new DefaultTokenServices();
defaultTokenServices.setTokenStore(customTokenStore());
return defaultTokenServices;
}
private DefaultAccessTokenConverter customAccessTokenConverter() {
DefaultAccessTokenConverter tokenConverter = new DefaultAccessTokenConverter();
tokenConverter.setUserTokenConverter(customUserDataAuthenticationConverter);
return tokenConverter;
}
}
As you can see I migrate parts of the code but several issues are not clear:
implementation 'org.springframework.security.oauth.boot:spring-security-oauth2-autoconfigure' Is removed from
spring.dependency.management
package. What package should replace it?ResourceServerConfigurerAdapter
is deprecated. How to replace it?OAuth2AuthenticationEntryPoint
is deprecated. How to replace it?
What should be the proper way to migrate the code accordingly?