@Override public OAuthAccessToken load(SubscriptionName subscriptionName) throws Exception { Subscription subscription = subscriptionRepository.getSubscriptionDetails(subscriptionName); SubscriptionOAuthPolicy oAuthPolicy = subscription.getOAuthPolicy(); String providerName = oAuthPolicy.getProviderName(); OAuthProvider oAuthProvider = oAuthProviderRepository.getOAuthProviderDetails(providerName); OAuthTokenRequest request; if (USERNAME_PASSWORD.equals(oAuthPolicy.getGrantType())) { request = getOAuthUsernamePasswordGrantTokenRequest(oAuthPolicy, oAuthProvider); } else { request = getOAuthClientCredentialsGrantTokenRequest(oAuthPolicy, oAuthProvider); } metrics.oAuthSubscriptionTokenRequestMeter(subscription, providerName).mark(); try (Timer.Context timer = metrics.oAuthProviderLatencyTimer(providerName).time()) { return oAuthClient.getToken(request); } }
@Test public void shouldApplyPatchChangingSubscriptionOAuthPolicyGrantType() { // given Subscription subscription = subscription("group.topic", "subscription") .withOAuthPolicy(new SubscriptionOAuthPolicy(CLIENT_CREDENTIALS, "myProvider", "repo", null, null)) .build(); PatchData oAuthPolicyPatchData = patchData() .set("grantType", SubscriptionOAuthPolicy.GrantType.USERNAME_PASSWORD.getName()) .set("username", "user1") .set("password", "abc123") .build(); PatchData patch = patchData() .set("oAuthPolicy", oAuthPolicyPatchData) .build(); // when Subscription updated = Patch.apply(subscription, patch); // then SubscriptionOAuthPolicy updatedPolicy = updated.getOAuthPolicy(); assertThat(updatedPolicy.getGrantType()).isEqualTo(USERNAME_PASSWORD); assertThat(updatedPolicy.getUsername()).isEqualTo("user1"); } }
@Override public OAuthAccessToken load(SubscriptionName subscriptionName) throws Exception { Subscription subscription = subscriptionRepository.getSubscriptionDetails(subscriptionName); SubscriptionOAuthPolicy oAuthPolicy = subscription.getOAuthPolicy(); String providerName = oAuthPolicy.getProviderName(); OAuthProvider oAuthProvider = oAuthProviderRepository.getOAuthProviderDetails(providerName); OAuthTokenRequest request; if (USERNAME_PASSWORD.equals(oAuthPolicy.getGrantType())) { request = getOAuthUsernamePasswordGrantTokenRequest(oAuthPolicy, oAuthProvider); } else { request = getOAuthClientCredentialsGrantTokenRequest(oAuthPolicy, oAuthProvider); } metrics.oAuthSubscriptionTokenRequestMeter(subscription, providerName).mark(); try (Timer.Context timer = metrics.oAuthProviderLatencyTimer(providerName).time()) { return oAuthClient.getToken(request); } }
public SubscriptionOAuthPolicy anonymize() { if (GrantType.USERNAME_PASSWORD.equals(grantType)) { return new SubscriptionOAuthPolicy(grantType, providerName, scope, username, ANONYMIZED_PASSWORD); } return this; }