Гость
Целевая тема:
Создать новую тему:
Автор:
Форумы / Java [игнор отключен] [закрыт для гостей] / Spring security, access-refresh tokens / 5 сообщений из 5, страница 1 из 1
18.04.2018, 13:24
    #39632457
andreykaT
Участник
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Spring security, access-refresh tokens
собссно вопрос такой.. не уверен вообще насколько это верно.

когда юзер логинится ему дается скажем аксесс токен А с ттл Х, и рефреш токен Б.

через некоторое время юзер делает запрос гет токен по рефреш токену, и ему возвращается новый акцесс токен.

а можно ли сделать с токенгрантером так, чтоб он аналогично логину пока аксесс токен не истек по гет токен по рефреш токену всегда возвращал одинаковый аксесс токен, пока он не истечет??

сейчас при получении аксесс токена через рефреш токен он каждый раз возвращает разный.
если же я буду по логину паролю просить аксесс токен - то он всегда возвращает одинаковый (пока не истечет ттл).

хотелось бы иметь аналогичное поведение и в первом случае, но не совсем могу разобраться что из параметров ему надо сказать.
...
Рейтинг: 0 / 0
18.04.2018, 16:31
    #39632655
Blazkowicz
Участник
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Spring security, access-refresh tokens
По-моему параметрами этого не добиться. Задача refresh token-а и есть получение нового access token-а. Но можно отнаслодоваться от DefaultTokenServices и переписать поведение на нужное.
...
Рейтинг: 0 / 0
18.04.2018, 19:13
    #39632793
andreykaT
Участник
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Spring security, access-refresh tokens
отнаследовался и сделал. этот гад всё-равно юзает дефолтовый, а мой игнорирует.. ща вообще не стартует:

Код: java
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
20.
21.
22.
23.
24.
25.
26.
    @Configuration
    @EnableResourceServer
    protected static class ResourceServerConfiguration extends ResourceServerConfigurerAdapter {

.....

        @Override
        public void configure(ResourceServerSecurityConfigurer resources) throws Exception {
            resources
                    .expressionHandler(new CustomWebSecurityExpressionHandler())
                    .tokenStore(tokenStore())
                    .tokenServices(customTokenServices())
                    .resourceId(RESOURCE_ID);

        }


        @Bean
        @Primary
        public CustomTokenServices customTokenServices() throws Exception {
            CustomTokenServices tokenServices = new CustomTokenServices();
            tokenServices.setSupportRefreshToken(true);
            tokenServices.setTokenStore(tokenStore());
            tokenServices.setClientDetailsService(clientDetailsService());
            return tokenServices;
        }




валится с этим:

Код: java
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
20.
21.
22.
23.
24.
25.
26.
27.
28.
29.
30.
31.
32.
33.
34.
35.
36.
37.
38.
39.
40.
41.
42.
43.
44.
45.
46.
47.
48.
49.
50.
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'springSecurityFilterChain' defined in class path resource [org/springframework/security/config/annotation/web/configuration/WebSecurityConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [javax.servlet.Filter]: Factory method 'springSecurityFilterChain' threw exception; nested exception is java.lang.IllegalStateException: @Bean method ResourceServerConfiguration.customTokenServices called as a bean reference for type [com.zzzzzzzzz.config.CustomTokenServices] but overridden by non-compatible bean instance of type [com.sun.proxy.$Proxy210]. Overriding bean of same name declared in: class path resource [com/zzzzzzzzzzz/config/OAuth2Config$ResourceServerConfiguration.class]
	at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:599)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1173)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1067)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:513)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:483)
	at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306)
	at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
	at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302)
	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197)
	at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:296)
	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197)
	at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:761)
	at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:867)
	at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:543)
	at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:122)
	at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:762)
	at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:372)
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:316)
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:1187)
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:1176)
	at com.zzzzzzzzzzzz.Bootstrap.main(Bootstrap.java:107)
Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [javax.servlet.Filter]: Factory method 'springSecurityFilterChain' threw exception; nested exception is java.lang.IllegalStateException: @Bean method ResourceServerConfiguration.customTokenServices called as a bean reference for type [com.zzzzzzzzzzzz.config.CustomTokenServices] but overridden by non-compatible bean instance of type [com.sun.proxy.$Proxy210]. Overriding bean of same name declared in: class path resource [com/zzzzzzzzzzzzzzzz/config/OAuth2Config$ResourceServerConfiguration.class]
	at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:189)
	at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:588)
	... 20 common frames omitted
Caused by: java.lang.IllegalStateException: @Bean method ResourceServerConfiguration.customTokenServices called as a bean reference for type [com.zzzzzzzzzzzz.config.CustomTokenServices] but overridden by non-compatible bean instance of type [com.sun.proxy.$Proxy210]. Overriding bean of same name declared in: class path resource [com/zzzzzzzzzzzz/config/OAuth2Config$ResourceServerConfiguration.class]
	at org.springframework.context.annotation.ConfigurationClassEnhancer$BeanMethodInterceptor.obtainBeanInstanceFromFactory(ConfigurationClassEnhancer.java:402)
	at org.springframework.context.annotation.ConfigurationClassEnhancer$BeanMethodInterceptor.intercept(ConfigurationClassEnhancer.java:361)
	at com.zzzzzz.config.OAuth2Config$ResourceServerConfiguration$$EnhancerBySpringCGLIB$$340cd24b.customTokenServices(<generated>)
	at com.zzzzzzzzzz.config.OAuth2Config$ResourceServerConfiguration.configure(OAuth2Config.java:99)
	at org.springframework.security.oauth2.config.annotation.web.configuration.ResourceServerConfiguration.configure(ResourceServerConfiguration.java:147)
	at org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter.getHttp(WebSecurityConfigurerAdapter.java:199)
	at org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter.init(WebSecurityConfigurerAdapter.java:283)
	at org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter.init(WebSecurityConfigurerAdapter.java:68)
	at org.springframework.security.oauth2.config.annotation.web.configuration.ResourceServerConfiguration$$EnhancerBySpringCGLIB$$45b78fc8.init(<generated>)
	at org.springframework.security.config.annotation.AbstractConfiguredSecurityBuilder.init(AbstractConfiguredSecurityBuilder.java:367)
	at org.springframework.security.config.annotation.AbstractConfiguredSecurityBuilder.doBuild(AbstractConfiguredSecurityBuilder.java:320)
	at org.springframework.security.config.annotation.AbstractSecurityBuilder.build(AbstractSecurityBuilder.java:39)
	at org.springframework.security.config.annotation.web.configuration.WebSecurityConfiguration.springSecurityFilterChain(WebSecurityConfiguration.java:98)
	at org.springframework.security.config.annotation.web.configuration.WebSecurityConfiguration$$EnhancerBySpringCGLIB$$406f1142.CGLIB$springSecurityFilterChain$3(<generated>)
	at org.springframework.security.config.annotation.web.configuration.WebSecurityConfiguration$$EnhancerBySpringCGLIB$$406f1142$$FastClassBySpringCGLIB$$356a1535.invoke(<generated>)
	at org.springframework.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.java:228)
	at org.springframework.context.annotation.ConfigurationClassEnhancer$BeanMethodInterceptor.intercept(ConfigurationClassEnhancer.java:358)
	at org.springframework.security.config.annotation.web.configuration.WebSecurityConfiguration$$EnhancerBySpringCGLIB$$406f1142.springSecurityFilterChain(<generated>)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:162)
...
Рейтинг: 0 / 0
19.04.2018, 10:53
    #39633017
andreykaT
Участник
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Spring security, access-refresh tokens
короче, решено.

сам дураг. сервисы дергали методы из суперкласса т.к. я их и не переписал в детском классе. и не проинитил поля которые заюзаны в этих методах у суперкласса.

всё работает.
...
Рейтинг: 0 / 0
25.04.2018, 09:45
    #39635829
andreykaT
Участник
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Spring security, access-refresh tokens
в общем, ковырял ковырял. выкатил решение заказчику с кастомным токен сервисом, чтоб выдавал токены как он хотел. а он сказал что тут слишком много кода и он лучше попросит пофиксить свой баг на фронте
...
Рейтинг: 0 / 0
Форумы / Java [игнор отключен] [закрыт для гостей] / Spring security, access-refresh tokens / 5 сообщений из 5, страница 1 из 1
Найденые пользователи ...
Разблокировать пользователей ...
Читали форум (0):
Пользователи онлайн (0):
x
x
Закрыть


Просмотр
0 / 0
Close
Debug Console [Select Text]