Как получить токен доступа по двум разным путям весной? - PullRequest
0 голосов
/ 11 июня 2019

сейчас я получаю токен с этим путем:

http://localhost:9000/oauth/token

но я хочу разделить его на две конечные точки, которые будут возвращать мне один и тот же токен (я работаю с двумя версиями длямое приложение)

Я хочу, чтобы эти две конечные точки вернули токен доступа:

/v1/oauth/token

и

/v2/oauth/token

Я пытался использовать pathMapping (= делал только один путь) или создание restController, но ничего не получается ...

Сначала у меня вопрос: возможно ли это?и если да, то как?

я присоединяю свою конфигурацию:

OAuth2ServerConfiguration class

@Configuration
public class OAuth2ServerConfiguration {

    public static final String RESOURCE_ID = "restservice";

    @Configuration
    @EnableResourceServer
    public static class ResourceServerConfiguration extends ResourceServerConfigurerAdapter {

        @Autowired
        private CustomUserDetailsService userDetailsService;

        @Override
        public void configure(ResourceServerSecurityConfigurer resources) {
            resources.resourceId(RESOURCE_ID);
        }


        @Override
        public void configure(HttpSecurity http) throws Exception {
            http
                    .userDetailsService(userDetailsService)
                    .authorizeRequests()
                    .antMatchers(
                            "/**/users/**"
                            , "/**/groups/**"
                    )
                    .authenticated()
                    .and()
                    .authorizeRequests()
                    .anyRequest().permitAll();
        }

    }

    @Configuration
    @EnableAuthorizationServer
    public static class AuthorizationServerConfiguration extends AuthorizationServerConfigurerAdapter {

        @Autowired
        private DataSource dataSource;

        @Autowired
        @Qualifier("authenticationManagerBean")
        private AuthenticationManager authenticationManager;

        @Autowired
        private CustomUserDetailsService userDetailsService;


        @Override
        public void configure(AuthorizationServerSecurityConfigurer oauthServer) throws Exception {
            oauthServer.checkTokenAccess("permitAll()");

        }

        @Override
        public void configure(AuthorizationServerEndpointsConfigurer endpoints)
                throws Exception {
            endpoints
                    .tokenServices(tokenServices())
                    .authenticationManager(authenticationManager)
                    .userDetailsService(userDetailsService);
        }

        @Override
        public void configure(ClientDetailsServiceConfigurer clients) throws Exception {
            clients
                    .jdbc(dataSource)
        }


        @Bean
        @Primary
        @Qualifier("tokenServices")
        public AuthorizationServerTokenServices tokenServices() {
            final DefaultTokenServices defaultTokenServices = new CustomTokenServices();
            defaultTokenServices.setSupportRefreshToken(true);
            defaultTokenServices.setRefreshTokenValiditySeconds(0);
            defaultTokenServices.setAccessTokenValiditySeconds(86000);
            defaultTokenServices.setTokenStore(tokenStore());
            return defaultTokenServices;
        }

        @Bean
        public TokenStore tokenStore() {
            return new JdbcTokenStore(dataSource);
        }


    }
...