@Test public void shouldSetRefreshOAuth2Token() throws Exception { wiremock.givenThat(post("/oauth/authorize") .withRequestBody(equalTo("refresh_token=refresh-token&grant_type=refresh_token")) .willReturn(ok() .withBody("{\"access_token\":\"new-access-token\"}"))); final AuthenticationCustomizer customizer = new AuthenticationCustomizer(); final Map<String, Object> options = new HashMap<>(); options.put("authenticationType", AuthenticationType.oauth2); options.put("accessToken", "{{accessToken}}"); options.put("refreshToken", "{{refreshToken}}"); final String authorizationEndpoint = "http: options.put("authorizationEndpoint", authorizationEndpoint); final ComponentProxyComponent component = new SwaggerProxyComponent("dataset-test", "dataset-test"); final CamelContext context = mock(CamelContext.class); component.setCamelContext(context); when(context.resolvePropertyPlaceholders("{{accessToken}}")).thenReturn("access-token"); when(context.resolvePropertyPlaceholders("{{refreshToken}}")).thenReturn("refresh-token"); when(context.resolvePropertyPlaceholders(authorizationEndpoint)).thenReturn(authorizationEndpoint); final TypeConverter typeConverter = mock(TypeConverter.class); when(context.getTypeConverter()).thenReturn(typeConverter); customizer.customize(component, options); assertThat(options).doesNotContainKeys("authenticationType", "accessToken", "refreshToken", "authorizationEndpoint"); assertAuthorizationHeaderSetTo(component, "Bearer new-access-token"); }
@Override public void customize(final ComponentProxyComponent proxyComponent, final Map<String, Object> options) { consumeOption(options, "authenticationType", authenticationTypeObject -> { final String authenticationTypeAsString = String.valueOf(authenticationTypeObject); final AuthenticationType authenticationType = AuthenticationType.fromString(authenticationTypeAsString); if (authenticationType == AuthenticationType.none) { return; } final SwaggerProxyComponent component = (SwaggerProxyComponent) proxyComponent; final CamelContext context = component.getCamelContext(); final Configuration configuration = new Configuration(this, context, options); switch (authenticationType) { case oauth2: OAuth.setup(component, configuration); break; case basic: Basic.setup(component, configuration); break; case apiKey: ApiKey.setup(component, configuration); break; default: throw new IllegalStateException("Unsupported authentication type: " + authenticationType); } }); }
AuthenticationCustomizer implements ComponentProxyCustomizer { @Override public void customize(final ComponentProxyComponent proxyComponent, final Map<String, Object> options) { consumeOption(options, "authenticationType", authenticationTypeObject -> { final String authenticationTypeAsString = String.valueOf(authenticationTypeObject); final AuthenticationType authenticationType = AuthenticationType.fromString(authenticationTypeAsString); if (authenticationType == AuthenticationType.none) { return; } final SwaggerProxyComponent component = (SwaggerProxyComponent) proxyComponent; final CamelContext context = component.getCamelContext(); final Configuration configuration = new Configuration(this, context, options); switch (authenticationType) { case oauth2: OAuth.setup(component, configuration); break; case basic: Basic.setup(component, configuration); break; case apiKey: ApiKey.setup(component, configuration); break; default: throw new IllegalStateException("Unsupported authentication type: " + authenticationType); } }); } }
AuthenticationCustomizer implements ComponentProxyCustomizer { @Override public void customize(final ComponentProxyComponent proxyComponent, final Map<String, Object> options) { consumeOption(options, "authenticationType", authenticationTypeObject -> { final String authenticationTypeAsString = String.valueOf(authenticationTypeObject); final AuthenticationType authenticationType = AuthenticationType.fromString(authenticationTypeAsString); if (authenticationType == AuthenticationType.none) { return; } final SwaggerProxyComponent component = (SwaggerProxyComponent) proxyComponent; final CamelContext context = component.getCamelContext(); final Configuration configuration = new Configuration(this, context, options); switch (authenticationType) { case oauth2: OAuth.setup(component, configuration); break; case basic: Basic.setup(component, configuration); break; case apiKey: ApiKey.setup(component, configuration); break; default: throw new IllegalStateException("Unsupported authentication type: " + authenticationType); } }); }  }
AuthenticationCustomizer implements ComponentProxyCustomizer { @Override public void customize(final ComponentProxyComponent proxyComponent, final Map<String, Object> options) { consumeOption(options, "authenticationType", authenticationTypeObject -> { final String authenticationTypeAsString = String.valueOf(authenticationTypeObject); final AuthenticationType authenticationType = AuthenticationType.fromString(authenticationTypeAsString); if (authenticationType == AuthenticationType.none) { return; } final SwaggerProxyComponent component = (SwaggerProxyComponent) proxyComponent; final CamelContext context = component.getCamelContext(); final Configuration configuration = new Configuration(this, context, options); switch (authenticationType) { case oauth2: OAuth.setup(component, configuration); break; case basic: Basic.setup(component, configuration); break; case apiKey: ApiKey.setup(component, configuration); break; default: throw new IllegalStateException("Unsupported authentication type: " + authenticationType); } }); }  @Override void customize(final ComponentProxyComponent proxyComponent, final Map<String, Object> options); }
AuthenticationCustomizer implements ComponentProxyCustomizer { @Override public void customize(final ComponentProxyComponent proxyComponent, final Map<String, Object> options) { consumeOption(options, "authenticationType", authenticationTypeObject -> { final String authenticationTypeAsString = String.valueOf(authenticationTypeObject); final AuthenticationType authenticationType = AuthenticationType.fromString(authenticationTypeAsString); if (authenticationType == AuthenticationType.none) { return; } final SwaggerProxyComponent component = (SwaggerProxyComponent) proxyComponent; final CamelContext context = component.getCamelContext(); final Configuration configuration = new Configuration(this, context, options); switch (authenticationType) { case oauth2: OAuth.setup(component, configuration); break; case basic: Basic.setup(component, configuration); break; case apiKey: ApiKey.setup(component, configuration); break; default: throw new IllegalStateException("Unsupported authentication type: " + authenticationType); } }); }  @Override void customize(final ComponentProxyComponent proxyComponent, final Map<String, Object> options);  }