Skip to content

Commit

Permalink
VIC-1918: Tenant data in authorised context
Browse files Browse the repository at this point in the history
  • Loading branch information
adnanalicic committed Nov 1, 2022
1 parent 36c1d11 commit 8e1dac0
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ public Optional<RestrictedTenantDTO> findTenantBySubdomain(String subdomain, Lon

Optional<Long> tenant = authorisationService.resolveTenantFromRequest(tenantId);
if (multitenancyWithSingleDomain && tenant.isPresent()) {
return getSingleDomainSpecificTenantData(tenantById, tenantId);
return getSingleDomainSpecificTenantData(tenantById, tenant.get());
}

return tenantById.isEmpty() ? Optional.empty()
Expand All @@ -103,16 +103,6 @@ public Optional<RestrictedTenantDTO> findTenantBySubdomain(String subdomain, Lon
public Optional<RestrictedTenantDTO> getSingleDomainSpecificTenantData(
Optional<TenantEntity> tenant, Long tenantId) {

if (tenantId == null) {
Optional<Long> accessTokenTenantId = authorisationService.findTenantIdInAccessToken();
if (accessTokenTenantId.isEmpty()) {
if (accessTokenTenantId.isEmpty()) {
throw new BadRequestException("tenantId not found in access token");
}
}
tenantId = accessTokenTenantId.get();
}

Optional<TenantEntity> tenantFromAuthorisedContext = tenantService.findTenantById(tenantId);
if (tenantFromAuthorisedContext.isEmpty()) {
throw new BadRequestException("Tenant not found for id " + tenantId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,6 @@ void findTenantBySubdomain_Should_returnTenantAwareData_When_RequestIsTenantAwar

when(tenantService.findTenantBySubdomain(subdomain)).thenReturn(defaultTenant);
when(authorisationService.resolveTenantFromRequest(null)).thenReturn(Optional.of(2L));
when(authorisationService.findTenantIdInAccessToken()).thenReturn(Optional.of(2L));
when(tenantService.findTenantById(2L)).thenReturn(accessTokenTenantData);

Optional<RestrictedTenantDTO> tenantDTO = tenantServiceFacade.findTenantBySubdomain(subdomain, null);
Expand Down

0 comments on commit 8e1dac0

Please sign in to comment.