Skip to content

Commit

Permalink
Story #12422: return the access contrat of the actual tenant
Browse files Browse the repository at this point in the history
  • Loading branch information
laedanrex committed Mar 5, 2024
1 parent 7935323 commit 3bef23e
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -100,43 +100,33 @@ public ExternalParametersInternalService(
public ExternalParametersDto getMyExternalParameters() {
LOGGER.debug("GetMyExternalParameters");
final AuthUserDto authUserDto = internalSecurityService.getUser();

if (authUserDto == null) {
LOGGER.warn("AuthUser is null");

return null;
}
if (authUserDto.getProfileGroup() == null) {
LOGGER.warn("AuthUser has no profile group");

return null;
}
if (authUserDto.getProfileGroup().getProfiles() == null) {
LOGGER.warn("AuthUser profile group has no profiles");

return null;
}

Integer tenant = internalSecurityService.getTenantIdentifier();
final Optional<ProfileDto> optionalExternalParamsProfileDto =
authUserDto.getProfileGroup().getProfiles().stream()
.filter(p -> Application.EXTERNAL_PARAMS.toString().equalsIgnoreCase(p.getApplicationName()))
.filter(p -> p.getTenantIdentifier().equals(tenant))
.findFirst();


if (optionalExternalParamsProfileDto.isEmpty()) {
LOGGER.warn("External parameter profile not found");

return null;
}

final ProfileDto externalParametersProfile = optionalExternalParamsProfileDto.orElseThrow();

final ProfileDto externalParametersProfile = optionalExternalParamsProfileDto.get();
if (externalParametersProfile.getExternalParamId() == null) {
LOGGER.warn("External parameter profile have no external parameter id");

return null;
}

return this.getOne(externalParametersProfile.getExternalParamId());
}

Expand Down Expand Up @@ -197,4 +187,5 @@ protected String getObjectName() {
protected Converter<ExternalParametersDto, ExternalParameters> getConverter() {
return externalParametersConverter;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -76,15 +76,17 @@ public void testGetOne() {
final AuthUserDto user = IamServerUtilsTest.buildAuthUserDto();
user.getProfileGroup().getProfiles().get(0).setApplicationName(Application.EXTERNAL_PARAMS.toString());
user.getProfileGroup().getProfiles().get(0).setExternalParamId(ANY_EXTERNAL_PARAM_ID);
user.getProfileGroup().getProfiles().get(0).setTenantIdentifier(1);
ExternalParameters externalParameters = new ExternalParameters();
externalParameters.setId(ID);

when(externalParametersRepository.findOne(ArgumentMatchers.any(Query.class))).thenReturn(
Optional.of(externalParameters));
when(externalParametersRepository.findOne(ArgumentMatchers.any(Query.class))).thenReturn(Optional.of(externalParameters));
when(internalSecurityService.getUser()).thenReturn(user);
when(internalSecurityService.getTenantIdentifier()).thenReturn(1);

ExternalParametersDto res = this.service.getMyExternalParameters();
Assert.assertNotNull("ExternalParameters should be returned.", res);
Assert.assertTrue(res.getId().equals(ID));
}

}

0 comments on commit 3bef23e

Please sign in to comment.