Skip to content

Commit ab9e50b

Browse files
authored
feat: [IAS] Harden IAS Subdomain Resolution in OAuth2Service (#753)
1 parent bb85654 commit ab9e50b

3 files changed

Lines changed: 14 additions & 4 deletions

File tree

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

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -229,12 +229,16 @@ private String getTenantSubdomainOrNull( @Nullable final Tenant tenant )
229229
return null;
230230
}
231231

232-
if( !(tenant instanceof TenantWithSubdomain) ) {
232+
if( !(tenant instanceof TenantWithSubdomain tenantWithSubdomain) ) {
233233
final String msg = "Unable to get subdomain of tenant '%s' because the instance is not an instance of %s.";
234234
throw new DestinationAccessException(msg.formatted(tenant, TenantWithSubdomain.class.getSimpleName()));
235235
}
236-
237-
return ((TenantWithSubdomain) tenant).getSubdomain();
236+
final var subdomain = tenantWithSubdomain.getSubdomain();
237+
if( subdomain == null ) {
238+
throw new DestinationAccessException(
239+
"The given tenant '%s' does not have a subdomain defined.".formatted(tenant));
240+
}
241+
return subdomain;
238242
}
239243

240244
@Nullable

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,11 @@ void testSubdomainTenantStrategy()
175175
TenantAccessor.executeWithTenant(new DefaultTenant("t1", "localhost"), service::retrieveAccessToken);
176176
TenantAccessor.executeWithTenant(new DefaultTenant("t2", "localhost"), service::retrieveAccessToken);
177177

178+
// if a tenant is explicitly defined, the subdomain is mandatory for the subdomain strategy
179+
assertThatThrownBy(
180+
() -> TenantAccessor.executeWithTenant(new DefaultTenant("t3"), service::retrieveAccessToken))
181+
.hasMessageContaining("does not have a subdomain");
182+
178183
SERVER_1
179184
.verify(
180185
1,

release_notes.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@
88

99
### 🔧 Compatibility Notes
1010

11-
-
11+
- Changed a behavior details when obtaining tokens from IAS with the default strategy `CURRENT_TENANT`.
12+
In case the current tenant is the provider tenant, and `TenantAccessor.getCurrentTenant()` is returning a `Tenant` object, this object is now required to have a subdomain != null.
1213

1314
### ✨ New Functionality
1415

0 commit comments

Comments
 (0)