Skip to content

Commit ebbef88

Browse files
committed
Reviews
1 parent 1034152 commit ebbef88

2 files changed

Lines changed: 10 additions & 5 deletions

File tree

cloudplatform/connectivity-oauth/src/main/java/com/sap/cloud/sdk/cloudplatform/connectivity/OAuth2Service.java

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
import com.sap.cloud.security.config.ClientIdentity;
3737
import com.sap.cloud.security.token.Token;
3838
import com.sap.cloud.security.xsuaa.client.DefaultOAuth2TokenService;
39+
import com.sap.cloud.security.xsuaa.client.OAuth2ServiceException;
3940
import com.sap.cloud.security.xsuaa.client.OAuth2TokenResponse;
4041
import com.sap.cloud.security.xsuaa.client.OAuth2TokenService;
4142

@@ -193,12 +194,16 @@ private OAuth2TokenResponse executeClientCredentialsFlow( @Nullable final Tenant
193194
.getOrElseThrow(e -> buildException(e, tenant));
194195
}
195196

196-
private TokenRequestFailedException buildException(@Nonnull final Throwable e, @Nullable final Tenant tenant )
197+
private TokenRequestFailedException buildException( @Nonnull final Throwable e, @Nullable final Tenant tenant )
197198
{
198199
String msg = "Failed to resolve access token.";
199-
// In case where tenant is subscriber, and we get 401 error, add hint to error message.
200-
if( e.getMessage().contains("Http status code 401") && tenant != null ) {
201-
msg += " This might be due to missing or wrongly set up dependencies in your SaaS registry.";
200+
// In case where tenant is not the provider tenant, and we get 401 error, add hint to error message.
201+
if( e instanceof OAuth2ServiceException
202+
&& ((OAuth2ServiceException) e).getHttpStatusCode().equals(401)
203+
&& tenant != null ) {
204+
msg +=
205+
" In case you are accessing a multi-tenant BTP service, ensure that the service instance is declared as dependency "
206+
+ "to SaaS Provisioning Service or Subscription Manager (SMS) and subscribed for the current tenant.";
202207
}
203208
return new TokenRequestFailedException(msg, e);
204209
}

cloudplatform/connectivity-oauth/src/test/java/com/sap/cloud/sdk/cloudplatform/connectivity/OAuth2IntegrationTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ void testExtended401ErrorMessage()
191191
TenantAccessor.executeWithTenant(new DefaultTenant("subscriber", "subscriber"), () -> {
192192
assertThatCode(destination::getHeaders)
193193
.isInstanceOf(DestinationAccessException.class)
194-
.hasMessageEndingWith("wrongly set up dependencies in your SaaS registry.")
194+
.hasMessageEndingWith("subscribed for the current tenant.")
195195
.hasRootCauseInstanceOf(OAuth2ServiceException.class);
196196
});
197197
}

0 commit comments

Comments
 (0)