Search in sources :

Example 1 with FileField

use of pl.edu.icm.unity.webui.common.file.FileField in project unity by unity-idm.

the class SAMLEditorGeneralTab method buildMetadataSection.

private CollapsibleLayout buildMetadataSection() {
    FormLayoutWithFixedCaptionWidth metadataPublishing = new FormLayoutWithFixedCaptionWidth();
    metadataPublishing.setMargin(false);
    CheckBox publishMetadata = new CheckBox(msg.getMessage("SAMLEditorGeneralTab.publishMetadata"));
    configBinder.forField(publishMetadata).withValidator((v, c) -> {
        if (!initialValidation) {
            refreshMetaButton(v);
            initialValidation = true;
        }
        if (v) {
            metaLinkButtonWrapper.setVisible(true);
            metaOffInfo.setVisible(false);
        } else {
            metaLinkButtonWrapper.setVisible(false);
            metaOffInfo.setVisible(true);
        }
        return ValidationResult.ok();
    }).bind("publishMetadata");
    metadataPublishing.addComponent(publishMetadata);
    signMetadata = new CheckBox(msg.getMessage("SAMLEditorGeneralTab.signMetadata"));
    configBinder.forField(signMetadata).bind("signMetadata");
    signMetadata.setEnabled(false);
    metadataPublishing.addComponent(signMetadata);
    CheckBox autoGenerateMetadata = new CheckBox(msg.getMessage("SAMLEditorGeneralTab.autoGenerateMetadata"));
    configBinder.forField(autoGenerateMetadata).bind("autoGenerateMetadata");
    autoGenerateMetadata.setEnabled(false);
    metadataPublishing.addComponent(autoGenerateMetadata);
    FileField metadataSource = new FileField(msg, "text/xml", "metadata.xml", serverConfig.getFileSizeLimit());
    metadataSource.setCaption(msg.getMessage("SAMLEditorGeneralTab.metadataFile"));
    metadataSource.configureBinding(configBinder, "metadataSource", Optional.of((value, context) -> {
        if (value != null && value.getLocal() != null) {
            try {
                EntityDescriptorDocument.Factory.parse(new ByteArrayInputStream(value.getLocal()));
            } catch (Exception e) {
                return ValidationResult.error(msg.getMessage("SAMLEditorGeneralTab.invalidMetadataFile"));
            }
        }
        boolean isEmpty = value == null || (value.getLocal() == null && (value.getRemote() == null || value.getRemote().isEmpty()));
        if (publishMetadata.getValue() && (!autoGenerateMetadata.getValue() && isEmpty)) {
            return ValidationResult.error(msg.getMessage("SAMLEditorGeneralTab.idpMetaEmpty"));
        }
        return ValidationResult.ok();
    }));
    metadataSource.setEnabled(false);
    metadataPublishing.addComponent(metadataSource);
    publishMetadata.addValueChangeListener(e -> {
        boolean v = e.getValue();
        signMetadata.setEnabled(v);
        autoGenerateMetadata.setEnabled(v);
        metadataSource.setEnabled(!autoGenerateMetadata.getValue() && v);
    });
    autoGenerateMetadata.addValueChangeListener(e -> {
        metadataSource.setEnabled(!e.getValue() && publishMetadata.getValue());
    });
    return new CollapsibleLayout(msg.getMessage("SAMLEditorGeneralTab.metadata"), metadataPublishing);
}
Also used : FieldSizeConstans(pl.edu.icm.unity.webui.common.FieldSizeConstans) CustomComponent(com.vaadin.ui.CustomComponent) TextField(com.vaadin.ui.TextField) VerticalLayout(com.vaadin.ui.VerticalLayout) ComboBox(com.vaadin.ui.ComboBox) ValidationResult(com.vaadin.data.ValidationResult) DescriptionTextField(pl.edu.icm.unity.webui.common.widgets.DescriptionTextField) OutputTranslationProfileFieldFactory(io.imunity.webconsole.utils.tprofile.OutputTranslationProfileFieldFactory) IdentityType(pl.edu.icm.unity.types.basic.IdentityType) UnityServerConfiguration(pl.edu.icm.unity.engine.api.config.UnityServerConfiguration) ByteArrayInputStream(java.io.ByteArrayInputStream) CheckBox(com.vaadin.ui.CheckBox) EditorTab(pl.edu.icm.unity.webui.console.services.ServiceEditorBase.EditorTab) Page(com.vaadin.server.Page) Label(com.vaadin.ui.Label) DefaultServiceDefinition(pl.edu.icm.unity.webui.console.services.DefaultServiceDefinition) AssertionSigningPolicy(pl.edu.icm.unity.saml.idp.SamlIdpProperties.AssertionSigningPolicy) MessageSource(pl.edu.icm.unity.MessageSource) IntegerRangeValidator(com.vaadin.data.validator.IntegerRangeValidator) RequestAcceptancePolicy(pl.edu.icm.unity.saml.idp.SamlIdpProperties.RequestAcceptancePolicy) ServiceEditorTab(pl.edu.icm.unity.webui.console.services.ServiceEditorComponent.ServiceEditorTab) CollapsibleLayout(pl.edu.icm.unity.webui.common.CollapsibleLayout) ResponseSigningPolicy(pl.edu.icm.unity.saml.idp.SamlIdpProperties.ResponseSigningPolicy) GridWithEditor(pl.edu.icm.unity.webui.common.GridWithEditor) Collection(java.util.Collection) WrongArgumentException(pl.edu.icm.unity.exceptions.WrongArgumentException) Set(java.util.Set) FormLayoutWithFixedCaptionWidth(pl.edu.icm.unity.webui.common.FormLayoutWithFixedCaptionWidth) Collectors(java.util.stream.Collectors) Binder(com.vaadin.data.Binder) MarginInfo(com.vaadin.shared.ui.MarginInfo) EndpointPathValidator(pl.edu.icm.unity.engine.api.endpoint.EndpointPathValidator) Images(pl.edu.icm.unity.webui.common.Images) FileField(pl.edu.icm.unity.webui.common.file.FileField) List(java.util.List) Button(com.vaadin.ui.Button) SAMLIdentityMapping(pl.edu.icm.unity.saml.console.SAMLIdentityMapping) SubViewSwitcher(pl.edu.icm.unity.webui.common.webElements.SubViewSwitcher) I18nTextField(pl.edu.icm.unity.webui.common.i18n.I18nTextField) HorizontalLayout(com.vaadin.ui.HorizontalLayout) EntityDescriptorDocument(xmlbeans.org.oasis.saml2.metadata.EntityDescriptorDocument) FormLayout(com.vaadin.ui.FormLayout) Styles(pl.edu.icm.unity.webui.common.Styles) Optional(java.util.Optional) IntStepper(org.vaadin.risto.stepper.IntStepper) Component(com.vaadin.ui.Component) CollapsibleLayout(pl.edu.icm.unity.webui.common.CollapsibleLayout) FormLayoutWithFixedCaptionWidth(pl.edu.icm.unity.webui.common.FormLayoutWithFixedCaptionWidth) ByteArrayInputStream(java.io.ByteArrayInputStream) CheckBox(com.vaadin.ui.CheckBox) FileField(pl.edu.icm.unity.webui.common.file.FileField) WrongArgumentException(pl.edu.icm.unity.exceptions.WrongArgumentException)

Example 2 with FileField

use of pl.edu.icm.unity.webui.common.file.FileField in project unity by unity-idm.

the class SAMLAuthenticatorEditor method buildSAMLMetadaPublishingSection.

private CollapsibleLayout buildSAMLMetadaPublishingSection() {
    FormLayoutWithFixedCaptionWidth metadataPublishing = new FormLayoutWithFixedCaptionWidth();
    metadataPublishing.setMargin(false);
    CheckBox publishMetadata = new CheckBox(msg.getMessage("SAMLAuthenticatorEditor.publishMetadata"));
    configBinder.forField(publishMetadata).bind("publishMetadata");
    metadataPublishing.addComponent(publishMetadata);
    TextField metadataPath = new TextField(msg.getMessage("SAMLAuthenticatorEditor.metadataPath"));
    metadataPath.setWidth(FieldSizeConstans.LINK_FIELD_WIDTH, FieldSizeConstans.LINK_FIELD_WIDTH_UNIT);
    configBinder.forField(metadataPath).asRequired((v, c) -> ((v == null || v.isEmpty()) && publishMetadata.getValue()) ? ValidationResult.error(msg.getMessage("fieldRequired")) : ValidationResult.ok()).bind("metadataPath");
    metadataPath.setEnabled(false);
    metadataPublishing.addComponent(metadataPath);
    signMetadata = new CheckBox(msg.getMessage("SAMLAuthenticatorEditor.signMetadata"));
    configBinder.forField(signMetadata).bind("signMetadata");
    signMetadata.setEnabled(false);
    metadataPublishing.addComponent(signMetadata);
    CheckBox autoGenerateMetadata = new CheckBox(msg.getMessage("SAMLAuthenticatorEditor.autoGenerateMetadata"));
    configBinder.forField(autoGenerateMetadata).bind("autoGenerateMetadata");
    autoGenerateMetadata.setEnabled(false);
    metadataPublishing.addComponent(autoGenerateMetadata);
    FileField metadataSource = new FileField(msg, "text/xml", "metadata.xml", serverConfig.getFileSizeLimit());
    metadataSource.setCaption(msg.getMessage("SAMLAuthenticatorEditor.metadataFile"));
    metadataSource.configureBinding(configBinder, "metadataSource", Optional.of((value, context) -> {
        if (value != null && value.getLocal() != null) {
            try {
                EntityDescriptorDocument.Factory.parse(new ByteArrayInputStream(value.getLocal()));
            } catch (Exception e) {
                return ValidationResult.error(msg.getMessage("SAMLAuthenticatorEditor.invalidMetadataFile"));
            }
        }
        boolean isEmpty = value == null || (value.getLocal() == null && (value.getRemote() == null || value.getRemote().isEmpty()));
        if (publishMetadata.getValue() && (!autoGenerateMetadata.getValue() && isEmpty)) {
            return ValidationResult.error(msg.getMessage("SAMLAuthenticatorEditor.spMetaEmpty"));
        }
        return ValidationResult.ok();
    }));
    metadataSource.setEnabled(false);
    metadataPublishing.addComponent(metadataSource);
    publishMetadata.addValueChangeListener(e -> {
        boolean v = e.getValue();
        metadataPath.setEnabled(v);
        signMetadata.setEnabled(v);
        autoGenerateMetadata.setEnabled(v);
        metadataSource.setEnabled(!autoGenerateMetadata.getValue() && v);
    });
    autoGenerateMetadata.addValueChangeListener(e -> {
        metadataSource.setEnabled(!e.getValue() && publishMetadata.getValue());
    });
    return new CollapsibleLayout(msg.getMessage("SAMLAuthenticatorEditor.metadataPublishing"), metadataPublishing);
}
Also used : Arrays(java.util.Arrays) TextField(com.vaadin.ui.TextField) Alignment(com.vaadin.ui.Alignment) PKIManagement(pl.edu.icm.unity.engine.api.PKIManagement) IdentityTypesRegistry(pl.edu.icm.unity.engine.api.identity.IdentityTypesRegistry) ByteArrayInputStream(java.io.ByteArrayInputStream) CheckBox(com.vaadin.ui.CheckBox) ImageAccessService(pl.edu.icm.unity.webui.common.file.ImageAccessService) RegistrationsManagement(pl.edu.icm.unity.engine.api.RegistrationsManagement) GridWithActionColumn(pl.edu.icm.unity.webui.common.GridWithActionColumn) MessageSource(pl.edu.icm.unity.MessageSource) GridWithEditor(pl.edu.icm.unity.webui.common.GridWithEditor) SingleActionHandler(pl.edu.icm.unity.webui.common.SingleActionHandler) Set(java.util.Set) FormLayoutWithFixedCaptionWidth(pl.edu.icm.unity.webui.common.FormLayoutWithFixedCaptionWidth) Collectors(java.util.stream.Collectors) Binder(com.vaadin.data.Binder) Images(pl.edu.icm.unity.webui.common.Images) EngineException(pl.edu.icm.unity.exceptions.EngineException) FileField(pl.edu.icm.unity.webui.common.file.FileField) List(java.util.List) SAMLIdentityMapping(pl.edu.icm.unity.saml.console.SAMLIdentityMapping) ChipsWithFreeText(pl.edu.icm.unity.webui.common.chips.ChipsWithFreeText) URIAccessService(pl.edu.icm.unity.engine.api.files.URIAccessService) ConfigurationException(eu.unicore.util.configuration.ConfigurationException) BaseAuthenticatorEditor(pl.edu.icm.unity.webui.authn.authenticators.BaseAuthenticatorEditor) Styles(pl.edu.icm.unity.webui.common.Styles) Optional(java.util.Optional) CustomField(com.vaadin.ui.CustomField) FieldSizeConstans(pl.edu.icm.unity.webui.common.FieldSizeConstans) VerticalLayout(com.vaadin.ui.VerticalLayout) ComboBox(com.vaadin.ui.ComboBox) RealmsManagement(pl.edu.icm.unity.engine.api.RealmsManagement) ValidationResult(com.vaadin.data.ValidationResult) UnityServerConfiguration(pl.edu.icm.unity.engine.api.config.UnityServerConfiguration) SAMLVerificator(pl.edu.icm.unity.saml.sp.SAMLVerificator) AuthenticatorDefinition(pl.edu.icm.unity.types.authn.AuthenticatorDefinition) NotificationPopup(pl.edu.icm.unity.webui.common.NotificationPopup) CollapsibleLayout(pl.edu.icm.unity.webui.common.CollapsibleLayout) InputTranslationProfileFieldFactory(io.imunity.webconsole.utils.tprofile.InputTranslationProfileFieldFactory) StandardButtonsHelper(pl.edu.icm.unity.webui.common.StandardButtonsHelper) Consumer(java.util.function.Consumer) Button(com.vaadin.ui.Button) SubViewSwitcher(pl.edu.icm.unity.webui.common.webElements.SubViewSwitcher) AuthenticatorEditor(pl.edu.icm.unity.webui.authn.authenticators.AuthenticatorEditor) EntityDescriptorDocument(xmlbeans.org.oasis.saml2.metadata.EntityDescriptorDocument) FormValidationException(pl.edu.icm.unity.webui.common.FormValidationException) FileStorageService(pl.edu.icm.unity.engine.api.files.FileStorageService) Component(com.vaadin.ui.Component) CollapsibleLayout(pl.edu.icm.unity.webui.common.CollapsibleLayout) FormLayoutWithFixedCaptionWidth(pl.edu.icm.unity.webui.common.FormLayoutWithFixedCaptionWidth) ByteArrayInputStream(java.io.ByteArrayInputStream) CheckBox(com.vaadin.ui.CheckBox) TextField(com.vaadin.ui.TextField) FileField(pl.edu.icm.unity.webui.common.file.FileField) EngineException(pl.edu.icm.unity.exceptions.EngineException) ConfigurationException(eu.unicore.util.configuration.ConfigurationException) FormValidationException(pl.edu.icm.unity.webui.common.FormValidationException)

Aggregations

Binder (com.vaadin.data.Binder)2 ValidationResult (com.vaadin.data.ValidationResult)2 Button (com.vaadin.ui.Button)2 CheckBox (com.vaadin.ui.CheckBox)2 ComboBox (com.vaadin.ui.ComboBox)2 Component (com.vaadin.ui.Component)2 TextField (com.vaadin.ui.TextField)2 VerticalLayout (com.vaadin.ui.VerticalLayout)2 ByteArrayInputStream (java.io.ByteArrayInputStream)2 List (java.util.List)2 Optional (java.util.Optional)2 Set (java.util.Set)2 Collectors (java.util.stream.Collectors)2 MessageSource (pl.edu.icm.unity.MessageSource)2 UnityServerConfiguration (pl.edu.icm.unity.engine.api.config.UnityServerConfiguration)2 SAMLIdentityMapping (pl.edu.icm.unity.saml.console.SAMLIdentityMapping)2 CollapsibleLayout (pl.edu.icm.unity.webui.common.CollapsibleLayout)2 FieldSizeConstans (pl.edu.icm.unity.webui.common.FieldSizeConstans)2 FormLayoutWithFixedCaptionWidth (pl.edu.icm.unity.webui.common.FormLayoutWithFixedCaptionWidth)2 GridWithEditor (pl.edu.icm.unity.webui.common.GridWithEditor)2