use of io.imunity.furms.api.validation.exceptions.UserWithoutSitesError in project furms by unity-idm.
the class SSHKeyFormView method setParameter.
@Override
public void setParameter(BeforeEvent event, @OptionalParameter String parameter) {
try {
sshKeyService.assertIsEligibleToManageKeys();
} catch (UserWithoutFenixIdValidationError e) {
LOG.debug(e.getMessage(), e);
showErrorNotification(getTranslation("user.without.fenixid.error.message"));
setVisible(false);
return;
} catch (UserWithoutSitesError e) {
LOG.debug(e.getMessage(), e);
showErrorNotification(getTranslation("view.user-settings.ssh-keys.user.without.sites.error.message"));
return;
} catch (AccessDeniedException e) {
LOG.debug(e.getMessage(), e);
showErrorNotification(getTranslation("view.user-settings.ssh-keys.access.denied.error.message"));
setVisible(false);
return;
}
SSHKeyUpdateModel serviceViewModel = ofNullable(parameter).flatMap(id -> handleExceptions(() -> sshKeyService.findById(id))).flatMap(Function.identity()).map(k -> SSHKeyViewModelMapper.mapToUpdate(k, zoneId)).orElseGet(() -> new SSHKeyUpdateModel(authzService.getCurrentUserId()));
String trans = parameter == null ? "view.user-settings.ssh-keys.form.parameter.new" : "view.user-settings.ssh-keys.form.parameter.update";
breadCrumbParameter = new BreadCrumbParameter(parameter, getTranslation(trans));
sshKeyComponent.setFormPools(serviceViewModel);
}
use of io.imunity.furms.api.validation.exceptions.UserWithoutSitesError in project furms by unity-idm.
the class SSHKeyServiceValidator method assertIsEligibleToManageKeys.
void assertIsEligibleToManageKeys() {
PersistentId userId = authzService.getCurrentAuthNUser().id.get();
FenixUserId fenixId = validateFenixId(userId);
assertTrue(siteRepository.findAll().stream().anyMatch(site -> userOperationRepository.isUserAdded(site.getId(), fenixId.id)), () -> new UserWithoutSitesError("User with id" + userId.id + " don't have access to any site to install SSH keys"));
}
Aggregations