Search in sources :

Example 1 with UserWithoutSitesError

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);
}
Also used : VaadinExceptionHandler.handleExceptions(io.imunity.furms.ui.utils.VaadinExceptionHandler.handleExceptions) SSHKeyHistoryException(io.imunity.furms.api.ssh_keys.SSHKeyHistoryException) NotificationUtils.showErrorNotification(io.imunity.furms.ui.utils.NotificationUtils.showErrorNotification) ZonedDateTime(java.time.ZonedDateTime) Binder(com.vaadin.flow.data.binder.Binder) LoggerFactory(org.slf4j.LoggerFactory) SSHKeyService(io.imunity.furms.api.ssh_keys.SSHKeyService) PageTitle(io.imunity.furms.ui.components.PageTitle) Function(java.util.function.Function) BeforeEvent(com.vaadin.flow.router.BeforeEvent) Route(com.vaadin.flow.router.Route) FurmsViewComponent(io.imunity.furms.ui.components.FurmsViewComponent) BeanValidationBinder(com.vaadin.flow.data.binder.BeanValidationBinder) Key(com.vaadin.flow.component.Key) SiteService(io.imunity.furms.api.sites.SiteService) UserSettingsMenu(io.imunity.furms.ui.views.user_settings.UserSettingsMenu) UI(com.vaadin.flow.component.UI) FormButtons(io.imunity.furms.ui.components.FormButtons) Logger(org.slf4j.Logger) UIContext(io.imunity.furms.ui.user_context.UIContext) ButtonVariant(com.vaadin.flow.component.button.ButtonVariant) Optional.ofNullable(java.util.Optional.ofNullable) MethodHandles(java.lang.invoke.MethodHandles) Set(java.util.Set) AccessDeniedException(org.springframework.security.access.AccessDeniedException) Site(io.imunity.furms.domain.sites.Site) UninstalledUserError(io.imunity.furms.api.validation.exceptions.UninstalledUserError) ZoneId(java.time.ZoneId) BreadCrumbParameter(io.imunity.furms.ui.components.layout.BreadCrumbParameter) OptionalParameter(com.vaadin.flow.router.OptionalParameter) UserWithoutSitesError(io.imunity.furms.api.validation.exceptions.UserWithoutSitesError) Button(com.vaadin.flow.component.button.Button) AuthzService(io.imunity.furms.api.authz.AuthzService) Optional(java.util.Optional) UserWithoutFenixIdValidationError(io.imunity.furms.api.validation.exceptions.UserWithoutFenixIdValidationError) Collections(java.util.Collections) BreadCrumbParameter(io.imunity.furms.ui.components.layout.BreadCrumbParameter) AccessDeniedException(org.springframework.security.access.AccessDeniedException) UserWithoutFenixIdValidationError(io.imunity.furms.api.validation.exceptions.UserWithoutFenixIdValidationError) UserWithoutSitesError(io.imunity.furms.api.validation.exceptions.UserWithoutSitesError)

Example 2 with UserWithoutSitesError

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"));
}
Also used : SSHKeyHistoryException(io.imunity.furms.api.ssh_keys.SSHKeyHistoryException) DuplicatedNameValidationError(io.imunity.furms.api.validation.exceptions.DuplicatedNameValidationError) UserOperationRepository(io.imunity.furms.spi.user_operation.UserOperationRepository) SSHKeyOperationRepository(io.imunity.furms.spi.ssh_key_operation.SSHKeyOperationRepository) UsersDAO(io.imunity.furms.spi.users.UsersDAO) ValidationUtils.assertTrue(io.imunity.furms.utils.ValidationUtils.assertTrue) SSHKeyHistoryRepository(io.imunity.furms.spi.ssh_key_history.SSHKeyHistoryRepository) SSHKey(io.imunity.furms.domain.ssh_keys.SSHKey) SSHKeyAuthzException(io.imunity.furms.api.ssh_keys.SSHKeyAuthzException) SSHKeyRepository(io.imunity.furms.spi.ssh_keys.SSHKeyRepository) Assert.notNull(org.springframework.util.Assert.notNull) PersistentId(io.imunity.furms.domain.users.PersistentId) Assert.hasText(org.springframework.util.Assert.hasText) IdNotFoundValidationError(io.imunity.furms.api.validation.exceptions.IdNotFoundValidationError) SiteRepository(io.imunity.furms.spi.sites.SiteRepository) Set(java.util.Set) Site(io.imunity.furms.domain.sites.Site) UninstalledUserError(io.imunity.furms.api.validation.exceptions.UninstalledUserError) Collectors(java.util.stream.Collectors) FenixUserId(io.imunity.furms.domain.users.FenixUserId) UserWithoutSitesError(io.imunity.furms.api.validation.exceptions.UserWithoutSitesError) Component(org.springframework.stereotype.Component) AuthzService(io.imunity.furms.api.authz.AuthzService) Optional(java.util.Optional) UserWithoutFenixIdValidationError(io.imunity.furms.api.validation.exceptions.UserWithoutFenixIdValidationError) FenixUserId(io.imunity.furms.domain.users.FenixUserId) UserWithoutSitesError(io.imunity.furms.api.validation.exceptions.UserWithoutSitesError) PersistentId(io.imunity.furms.domain.users.PersistentId)

Aggregations

AuthzService (io.imunity.furms.api.authz.AuthzService)2 SSHKeyHistoryException (io.imunity.furms.api.ssh_keys.SSHKeyHistoryException)2 UninstalledUserError (io.imunity.furms.api.validation.exceptions.UninstalledUserError)2 UserWithoutFenixIdValidationError (io.imunity.furms.api.validation.exceptions.UserWithoutFenixIdValidationError)2 UserWithoutSitesError (io.imunity.furms.api.validation.exceptions.UserWithoutSitesError)2 Site (io.imunity.furms.domain.sites.Site)2 Optional (java.util.Optional)2 Set (java.util.Set)2 Key (com.vaadin.flow.component.Key)1 UI (com.vaadin.flow.component.UI)1 Button (com.vaadin.flow.component.button.Button)1 ButtonVariant (com.vaadin.flow.component.button.ButtonVariant)1 BeanValidationBinder (com.vaadin.flow.data.binder.BeanValidationBinder)1 Binder (com.vaadin.flow.data.binder.Binder)1 BeforeEvent (com.vaadin.flow.router.BeforeEvent)1 OptionalParameter (com.vaadin.flow.router.OptionalParameter)1 Route (com.vaadin.flow.router.Route)1 SiteService (io.imunity.furms.api.sites.SiteService)1 SSHKeyAuthzException (io.imunity.furms.api.ssh_keys.SSHKeyAuthzException)1 SSHKeyService (io.imunity.furms.api.ssh_keys.SSHKeyService)1