Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Story #12422: return the access contrat of the actual tenant #1666

Merged
merged 1 commit into from
Mar 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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));
}

}