These are chat archives for spring-cloud/spring-cloud

19th
Jan 2017
Bryan Perino
@bryantp
Jan 19 2017 00:05
@dsyer So, I got it to authenticate by somewhat manually adjusting the URLs
I am having a little bit of a hard time overriding the default beans though, mostly AuthorizationCodeResourceDetails which is defined here:
    @Configuration
    @ConditionalOnBean(OAuth2ClientConfiguration.class)
    @ConditionalOnWebApplication
    protected static class SessionScopedConfiguration {

        @Bean
        @ConfigurationProperties("security.oauth2.client")
        @Primary
        public AuthorizationCodeResourceDetails oauth2RemoteResource() {
            AuthorizationCodeResourceDetails details = new AuthorizationCodeResourceDetails();
            return details;
        }
Since it's primary, I can't overrule it
Dave Syer
@dsyer
Jan 19 2017 07:52
That's why I said you might need a BPP
Bryan Perino
@bryantp
Jan 19 2017 13:00
That's how I am currently getting it to work. Problem is that it's not dynamic per request
Dave Syer
@dsyer
Jan 19 2017 13:01
Then you didn't use @Scope("request")?
Bryan Perino
@bryantp
Jan 19 2017 13:02
Bean post processors support that?
Dave Syer
@dsyer
Jan 19 2017 13:03
They don't know anything about it
They just get passed the bean and its name
Bryan Perino
@bryantp
Jan 19 2017 13:03
Not sure which bean to scope though.
Dave Syer
@dsyer
Jan 19 2017 13:03
The one that you create, that you want to use to replace that primary one
Bryan Perino
@bryantp
Jan 19 2017 13:04
The details bean? It's marked as primary, so I am having a hard time overriding it
My bean definition was just ignored usually
I also couldnt get the rest templates to be scoped either. That was ignored as well.
Dave Syer
@dsyer
Jan 19 2017 13:06
I don't think you're following what I suggested
You need to create your own resource details. Put it in request scope. Replace the primary one with that one in a BPP.
Bryan Perino
@bryantp
Jan 19 2017 13:08
I don't think I can replace the template details. It creates a default one and then has another that is injected.
I don't think there is a setter method
Unless I am misunderstanding how the inject works
Dave Syer
@dsyer
Jan 19 2017 13:09
I don't think you have a BPP working yet then
It's all about getting to the instance of resource details before it is injected anywhere
Bryan Perino
@bryantp
Jan 19 2017 13:13
```
    @Override
    public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
        if(bean instanceof AuthorizationCodeResourceDetails){
            return coerce((AuthorizationCodeResourceDetails)bean);
        }
        return bean;
    }

    private AuthorizationCodeResourceDetails coerce(AuthorizationCodeResourceDetails details){
        final String currentAccessTokenUri = "http://coke.uaa.mydomain.io:8080/uaa/oauth/token";
        final String userAuthUrl = "http://coke.uaa.mydomain.io:8080/uaa/oauth/authorize";
        details.setAccessTokenUri(currentAccessTokenUri);
        details.setUserAuthorizationUri(userAuthUrl);
        return details;
    }
That is what I have currently. I have the domain hardcoded.
Dave Syer
@dsyer
Jan 19 2017 13:14
That's no good though because the AuthorizationCodeResourceDetails you create is not request scoped.
You need to do a bean lookup in that method, instead of creating an instance.
Bryan Perino
@bryantp
Jan 19 2017 13:15
Ok, I see what you're saying
I need to create a different bean of type AuthorizationCodeResourceDetails
and intercept that?
Dave Syer
@dsyer
Jan 19 2017 13:15
Yes. And no.
Bryan Perino
@bryantp
Jan 19 2017 13:15
I can't override the default AuthorizationCodeResourceDetails that gets injected into the RestTemplate
Dave Syer
@dsyer
Jan 19 2017 13:16
Create a different instance, and simply return that one from postProcessAfterInitialization() when the bean name is "oauth2RemoteResource"
Bryan Perino
@bryantp
Jan 19 2017 13:17
So I am intercepting the default AuthorizationCodeResourceDetails and replacing it with my own instance that is scoped to request?
In this case, the default AuthorizationCodeResourceDetails is named oauth2RemoteResource
I'm assuming that will replace the instance inside the rest template with my bean, and it will be updated on a per request basis.
Dave Syer
@dsyer
Jan 19 2017 13:29
You are replacing the primary bean instance. So yes. That's what should happen.
Bryan Perino
@bryantp
Jan 19 2017 18:53
When I do the replacement, should I grab an instance of the bean manually or can I rely on the auto wiring?
Dave Syer
@dsyer
Jan 19 2017 21:45
you need to get it from the BeanFactory manually
Or find a way to autowire it
I suspect it's cleaner to look it up