Search in sources :

Example 1 with ValidationResult

use of com.vaadin.data.ValidationResult in project cuba by cuba-platform.

the class CubaEditorImpl method getValidationErrors.

protected Map<Component, ValidationResult> getValidationErrors() {
    Map<Component, ValidationResult> errors = new HashMap<>();
    columnFields.values().forEach(field -> {
        ValidationResult validationResult = ((CubaEditorField<?>) field).validate();
        if (validationResult.isError()) {
            errors.put(field, validationResult);
        }
    });
    return errors;
}
Also used : Component(com.vaadin.ui.Component) ValidationResult(com.vaadin.data.ValidationResult)

Example 2 with ValidationResult

use of com.vaadin.data.ValidationResult in project jmix by jmix-framework.

the class JmixEditorImpl method getValidationErrors.

protected Map<Component, ValidationResult> getValidationErrors() {
    Map<Component, ValidationResult> errors = new HashMap<>();
    columnFields.values().forEach(field -> {
        ValidationResult validationResult = ((JmixEditorField<?>) field).validate();
        if (validationResult.isError()) {
            errors.put(field, validationResult);
        }
    });
    return errors;
}
Also used : Component(com.vaadin.ui.Component) ValidationResult(com.vaadin.data.ValidationResult)

Example 3 with ValidationResult

use of com.vaadin.data.ValidationResult in project unity by unity-idm.

the class AttributeStatementComponent method initUI.

private void initUI() {
    extraAttributesGroupCB = new CheckBox(msg.getMessage("AttributeStatementComponent.extraGroupCB"));
    extraAttributesGroupCB.addValueChangeListener((e) -> {
        extraAttributesGroupCombo.setEnabled(extraAttributesGroupCB.getValue());
        extraAttributesGroupCombo.setRequiredIndicatorVisible(extraAttributesGroupCB.getValue());
        if (extraAttributesGroupCB.getValue() && extraAttributesGroupCombo.getValue() == null && !groups.isEmpty())
            extraAttributesGroupCombo.setValue(extraAttributesGroupCombo.getAllGroups().get(0));
    });
    extraAttributesGroupCB.setDescription(msg.getMessage("AttributeStatementComponent.extraGroupCBDesc"));
    extraAttributesGroupCombo = new GroupComboBox(msg.getMessage("AttributeStatementComponent.extraGroupSelect"), groups);
    extraAttributesGroupCombo.setEnabled(false);
    extraAttributesGroupCombo.setInput(group, false);
    extraAttributesGroupCombo.setEmptySelectionAllowed(false);
    extraAttributesGroupCombo.setRequiredIndicatorVisible(false);
    if (groups.isEmpty())
        extraAttributesGroupCB.setEnabled(false);
    condition = new MVELExpressionField(msg, msg.getMessage("AttributeStatementComponent.condition"), msg.getMessage("MVELExpressionField.conditionDesc"), MVELExpressionContext.builder().withTitleKey("AttributeStatementComponent.conditionTitle").withEvalToKey("MVELExpressionField.evalToBoolean").withVars(AttributeStatementMVELContextKey.toMap()).build());
    condition.setDescription(msg.getMessage("AttributeStatementComponent.conditionDesc"));
    condition.setValue("true");
    assignMode = new RadioButtonGroup<>();
    Map<String, String> captions = ImmutableMap.of(MODE_DYNAMIC, msg.getMessage("AttributeStatementComponent.dynamicMode"), MODE_FIXED, msg.getMessage("AttributeStatementComponent.fixedMode"));
    assignMode.setItems(captions.keySet());
    assignMode.setItemCaptionGenerator(i -> captions.get(i));
    assignMode.addValueChangeListener((e) -> {
        boolean fixed = assignMode.getValue().equals(MODE_FIXED);
        fixedAttribute.setVisible(fixed);
        dynamicAttributeName.setVisible(!fixed);
        dynamicAttributeValue.setVisible(!fixed);
    });
    dynamicAttributeName = new AttributeSelectionComboBox(msg.getMessage("AttributeStatementComponent.dynamicAttrName"), attributeTypes);
    dynamicAttributeValue = new MVELExpressionField(msg, msg.getMessage("AttributeStatementComponent.dynamicAttrValue"), msg.getMessage("AttributeStatementComponent.dynamicAttrValueDesc"), MVELExpressionContext.builder().withTitleKey("AttributeStatementComponent.dynamicAttrValueTitle").withEvalToKey("AttributeStatementComponent.evalToListOfAttributeValues").withVars(AttributeStatementMVELContextKey.toMap()).build());
    fixedAttribute = new AttributeFieldWithEdit(msg, msg.getMessage("AttributeStatementComponent.fixedAttr"), attrHandlerRegistry, attributeTypes, group, null, true);
    assignMode.setValue(MODE_DYNAMIC);
    conflictResolution = new ComboBox<AttributeStatement.ConflictResolution>(msg.getMessage("AttributeStatementEditDialog.conflictResolution"));
    conflictResolution.setItems(AttributeStatement.ConflictResolution.values());
    conflictResolution.setItemCaptionGenerator(item -> msg.getMessage("AttributeStatement.conflictResolution." + item.toString()));
    conflictResolution.setValue(AttributeStatement.ConflictResolution.skip);
    conflictResolution.setEmptySelectionAllowed(false);
    FormLayout main = new CompactFormLayout();
    setCompositionRoot(main);
    main.addComponents(extraAttributesGroupCB, extraAttributesGroupCombo, condition, assignMode, dynamicAttributeName, dynamicAttributeValue, fixedAttribute, conflictResolution);
    binder = new Binder<>(AttributeStatement.class);
    binder.forField(extraAttributesGroupCombo).asRequired(msg.getMessage("fieldRequired")).bind("extraAttributesGroup");
    condition.configureBinding(binder, "condition", true);
    binder.forField(fixedAttribute).asRequired(msg.getMessage("fieldRequired")).bind("fixedAttribute");
    Map<String, AttributeType> typesMap = attributeTypes.stream().collect(Collectors.toMap(t -> t.getName(), t -> t));
    binder.forField(dynamicAttributeName).withConverter(d -> d != null ? d.getName() : "", d -> typesMap.get(d), "FOO").asRequired(new Validator<String>() {

        @Override
        public ValidationResult apply(String value, ValueContext context) {
            if (StringUtils.isBlank(value) && assignMode.getValue().equals(MODE_DYNAMIC))
                return ValidationResult.error(msg.getMessage("fieldRequired"));
            else
                return ValidationResult.ok();
        }
    }).bind("dynamicAttributeType");
    dynamicAttributeValue.configureBinding(binder, "dynamicAttributeExpression", true);
    binder.forField(conflictResolution).asRequired(msg.getMessage("fieldRequired")).bind("conflictResolution");
    AttributeStatement attrStatment = new AttributeStatement();
    attrStatment.setCondition(condition.getValue());
    attrStatment.setConflictResolution(ConflictResolution.skip);
    attrStatment.setExtraAttributesGroup(extraAttributesGroupCombo.getValue());
    attrStatment.setDynamicAttributeType(dynamicAttributeName.getValue().getName());
    binder.setBean(attrStatment);
}
Also used : CompactFormLayout(pl.edu.icm.unity.webui.common.CompactFormLayout) FormLayout(com.vaadin.ui.FormLayout) CustomComponent(com.vaadin.ui.CustomComponent) CompactFormLayout(pl.edu.icm.unity.webui.common.CompactFormLayout) AttributeHandlerRegistry(pl.edu.icm.unity.webui.common.attributes.AttributeHandlerRegistry) ComboBox(com.vaadin.ui.ComboBox) Log(pl.edu.icm.unity.base.utils.Log) ValidationResult(com.vaadin.data.ValidationResult) StringUtils(org.apache.commons.lang3.StringUtils) Validator(com.vaadin.data.Validator) HashSet(java.util.HashSet) CheckBox(com.vaadin.ui.CheckBox) MVELExpressionField(pl.edu.icm.unity.webui.common.mvel.MVELExpressionField) Map(java.util.Map) ValueContext(com.vaadin.data.ValueContext) MessageSource(pl.edu.icm.unity.MessageSource) AttributeFieldWithEdit(io.imunity.webconsole.attribute.AttributeFieldWithEdit) ImmutableMap(com.google.common.collect.ImmutableMap) Collection(java.util.Collection) AttributeSelectionComboBox(pl.edu.icm.unity.webui.common.attributes.AttributeSelectionComboBox) Set(java.util.Set) Collectors(java.util.stream.Collectors) Binder(com.vaadin.data.Binder) GroupsManagement(pl.edu.icm.unity.engine.api.GroupsManagement) AttributeType(pl.edu.icm.unity.types.basic.AttributeType) EngineException(pl.edu.icm.unity.exceptions.EngineException) AttributeStatementMVELContextKey(pl.edu.icm.unity.engine.api.attributes.AttributeStatementMVELContextKey) Logger(org.apache.logging.log4j.Logger) MVELExpressionContext(pl.edu.icm.unity.engine.api.mvel.MVELExpressionContext) FormLayout(com.vaadin.ui.FormLayout) RadioButtonGroup(com.vaadin.ui.RadioButtonGroup) FormValidationException(pl.edu.icm.unity.webui.common.FormValidationException) ConflictResolution(pl.edu.icm.unity.types.basic.AttributeStatement.ConflictResolution) GroupComboBox(pl.edu.icm.unity.webui.common.GroupComboBox) AttributeStatement(pl.edu.icm.unity.types.basic.AttributeStatement) ValueContext(com.vaadin.data.ValueContext) AttributeFieldWithEdit(io.imunity.webconsole.attribute.AttributeFieldWithEdit) CompactFormLayout(pl.edu.icm.unity.webui.common.CompactFormLayout) GroupComboBox(pl.edu.icm.unity.webui.common.GroupComboBox) AttributeSelectionComboBox(pl.edu.icm.unity.webui.common.attributes.AttributeSelectionComboBox) MVELExpressionField(pl.edu.icm.unity.webui.common.mvel.MVELExpressionField) CheckBox(com.vaadin.ui.CheckBox) AttributeStatement(pl.edu.icm.unity.types.basic.AttributeStatement) AttributeType(pl.edu.icm.unity.types.basic.AttributeType) ConflictResolution(pl.edu.icm.unity.types.basic.AttributeStatement.ConflictResolution) Validator(com.vaadin.data.Validator)

Example 4 with ValidationResult

use of com.vaadin.data.ValidationResult in project unity by unity-idm.

the class SAMLEditorGeneralTab method buildHeaderSection.

private Component buildHeaderSection() {
    HorizontalLayout main = new HorizontalLayout();
    main.setMargin(new MarginInfo(true, false));
    FormLayoutWithFixedCaptionWidth mainGeneralLayout = new FormLayoutWithFixedCaptionWidth();
    main.addComponent(mainGeneralLayout);
    metaLinkButton = new Button();
    metaOffInfo = new Label();
    metaOffInfo.setCaption(msg.getMessage("SAMLEditorGeneralTab.metadataOff"));
    infoLayout = new HorizontalLayout();
    infoLayout.setMargin(new MarginInfo(false, true, false, true));
    infoLayout.setStyleName("u-marginLeftMinus30");
    infoLayout.addStyleName("u-border");
    VerticalLayout wrapper = new VerticalLayout();
    wrapper.setMargin(false);
    infoLayout.addComponent(wrapper);
    wrapper.addComponent(new Label(msg.getMessage("SAMLEditorGeneralTab.importantURLs")));
    FormLayout infoLayoutWrapper = new FormLayout();
    infoLayoutWrapper.setSpacing(false);
    infoLayoutWrapper.setMargin(false);
    wrapper.addComponent(infoLayoutWrapper);
    metaLinkButtonWrapper = new HorizontalLayout();
    metaLinkButtonWrapper.setCaption(msg.getMessage("SAMLEditorGeneralTab.metadataLink"));
    metaLinkButton.setStyleName(Styles.vButtonLink.toString());
    metaLinkButtonWrapper.addComponent(metaLinkButton);
    infoLayoutWrapper.addComponent(metaLinkButtonWrapper);
    infoLayoutWrapper.addComponent(metaOffInfo);
    metaOffInfo.setVisible(false);
    metaLinkButton.addClickListener(e -> {
        Page.getCurrent().open(metaLinkButton.getCaption(), "_blank", false);
    });
    main.addComponent(infoLayout);
    refreshMetaButton(false);
    TextField name = new TextField();
    name.setCaption(msg.getMessage("ServiceEditorBase.name"));
    name.setReadOnly(editMode);
    samlServiceBinder.forField(name).asRequired().bind("name");
    mainGeneralLayout.addComponent(name);
    TextField contextPath = new TextField();
    contextPath.setPlaceholder("/saml-idp");
    contextPath.setRequiredIndicatorVisible(true);
    contextPath.setCaption(msg.getMessage("SAMLEditorGeneralTab.contextPath"));
    contextPath.setReadOnly(editMode);
    samlServiceBinder.forField(contextPath).withValidator((v, c) -> {
        ValidationResult r;
        if (editMode) {
            r = validatePathForEdit(v);
        } else {
            r = validatePathForAdd(v);
        }
        if (!r.isError()) {
            metaLinkButton.setCaption(serverPrefix + v + "/metadata");
        }
        return r;
    }).bind("address");
    mainGeneralLayout.addComponent(contextPath);
    I18nTextField displayedName = new I18nTextField(msg);
    displayedName.setCaption(msg.getMessage("ServiceEditorBase.displayedName"));
    samlServiceBinder.forField(displayedName).bind("displayedName");
    mainGeneralLayout.addComponent(displayedName);
    TextField description = new DescriptionTextField(msg);
    samlServiceBinder.forField(description).bind("description");
    mainGeneralLayout.addComponent(description);
    TextField issuerURI = new TextField();
    issuerURI.setWidth(FieldSizeConstans.LINK_FIELD_WIDTH, FieldSizeConstans.LINK_FIELD_WIDTH_UNIT);
    issuerURI.setCaption(msg.getMessage("SAMLEditorGeneralTab.issuerURI"));
    configBinder.forField(issuerURI).asRequired().bind("issuerURI");
    mainGeneralLayout.addComponent(issuerURI);
    ComboBox<AssertionSigningPolicy> signAssertionPolicy = new ComboBox<>();
    signAssertionPolicy.setItems(AssertionSigningPolicy.values());
    signAssertionPolicy.setEmptySelectionAllowed(false);
    signAssertionPolicy.setCaption(msg.getMessage("SAMLEditorGeneralTab.signAssertionPolicy"));
    configBinder.forField(signAssertionPolicy).asRequired().bind("signAssertionPolicy");
    mainGeneralLayout.addComponent(signAssertionPolicy);
    ComboBox<ResponseSigningPolicy> signResponcePolicy = new ComboBox<>();
    signResponcePolicy.setItems(ResponseSigningPolicy.values());
    signResponcePolicy.setEmptySelectionAllowed(false);
    signResponcePolicy.setCaption(msg.getMessage("SAMLEditorGeneralTab.signResponcePolicy"));
    configBinder.forField(signResponcePolicy).asRequired().bind("signResponcePolicy");
    mainGeneralLayout.addComponent(signResponcePolicy);
    ComboBox<String> signResponseCredential = new ComboBox<>();
    signResponseCredential.setCaption(msg.getMessage("SAMLEditorGeneralTab.signResponseCredential"));
    signResponseCredential.setItems(credentials);
    configBinder.forField(signResponseCredential).asRequired((v, c) -> ((v == null || v.isEmpty())) ? ValidationResult.error(msg.getMessage("fieldRequired")) : ValidationResult.ok()).bind("signResponseCredential");
    mainGeneralLayout.addComponent(signResponseCredential);
    ComboBox<String> httpsTruststore = new ComboBox<>(msg.getMessage("SAMLEditorGeneralTab.httpsTruststore"));
    httpsTruststore.setItems(truststores);
    configBinder.forField(httpsTruststore).bind("httpsTruststore");
    mainGeneralLayout.addComponent(httpsTruststore);
    CheckBox skipConsentScreen = new CheckBox(msg.getMessage("SAMLEditorGeneralTab.skipConsentScreen"));
    configBinder.forField(skipConsentScreen).bind("skipConsentScreen");
    mainGeneralLayout.addComponent(skipConsentScreen);
    CheckBox editableConsentScreen = new CheckBox(msg.getMessage("SAMLEditorGeneralTab.editableConsentScreen"));
    configBinder.forField(editableConsentScreen).bind("editableConsentScreen");
    mainGeneralLayout.addComponent(editableConsentScreen);
    skipConsentScreen.addValueChangeListener(e -> editableConsentScreen.setEnabled(!e.getValue()));
    ComboBox<RequestAcceptancePolicy> acceptPolicy = new ComboBox<>();
    acceptPolicy.setItems(RequestAcceptancePolicy.values());
    acceptPolicy.setEmptySelectionAllowed(false);
    acceptPolicy.setCaption(msg.getMessage("SAMLEditorGeneralTab.acceptPolicy"));
    configBinder.forField(acceptPolicy).asRequired().bind("requestAcceptancePolicy");
    mainGeneralLayout.addComponent(acceptPolicy);
    return main;
}
Also used : FormLayout(com.vaadin.ui.FormLayout) 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) DescriptionTextField(pl.edu.icm.unity.webui.common.widgets.DescriptionTextField) ComboBox(com.vaadin.ui.ComboBox) Label(com.vaadin.ui.Label) I18nTextField(pl.edu.icm.unity.webui.common.i18n.I18nTextField) ValidationResult(com.vaadin.data.ValidationResult) AssertionSigningPolicy(pl.edu.icm.unity.saml.idp.SamlIdpProperties.AssertionSigningPolicy) HorizontalLayout(com.vaadin.ui.HorizontalLayout) FormLayoutWithFixedCaptionWidth(pl.edu.icm.unity.webui.common.FormLayoutWithFixedCaptionWidth) Button(com.vaadin.ui.Button) MarginInfo(com.vaadin.shared.ui.MarginInfo) CheckBox(com.vaadin.ui.CheckBox) VerticalLayout(com.vaadin.ui.VerticalLayout) TextField(com.vaadin.ui.TextField) DescriptionTextField(pl.edu.icm.unity.webui.common.widgets.DescriptionTextField) I18nTextField(pl.edu.icm.unity.webui.common.i18n.I18nTextField) ResponseSigningPolicy(pl.edu.icm.unity.saml.idp.SamlIdpProperties.ResponseSigningPolicy) RequestAcceptancePolicy(pl.edu.icm.unity.saml.idp.SamlIdpProperties.RequestAcceptancePolicy)

Example 5 with ValidationResult

use of com.vaadin.data.ValidationResult in project unity by unity-idm.

the class OAuthEditorGeneralTab method buildHeaderSection.

private Component buildHeaderSection() {
    HorizontalLayout main = new HorizontalLayout();
    main.setMargin(new MarginInfo(true, false));
    FormLayoutWithFixedCaptionWidth mainGeneralLayout = new FormLayoutWithFixedCaptionWidth();
    main.addComponent(mainGeneralLayout);
    HorizontalLayout infoLayout = new HorizontalLayout();
    infoLayout.setMargin(new MarginInfo(false, true, false, true));
    infoLayout.setStyleName("u-marginLeftMinus30");
    infoLayout.addStyleName("u-border");
    VerticalLayout wrapper = new VerticalLayout();
    wrapper.setMargin(false);
    infoLayout.addComponent(wrapper);
    wrapper.addComponent(new Label(msg.getMessage("OAuthEditorGeneralTab.importantURLs")));
    FormLayout infoLayoutWrapper = new FormLayout();
    infoLayoutWrapper.setSpacing(false);
    infoLayoutWrapper.setMargin(false);
    wrapper.addComponent(infoLayoutWrapper);
    Label userAuthnEndpointPath = new Label();
    userAuthnEndpointPath.setCaption(msg.getMessage("OAuthEditorGeneralTab.userAuthnEndpointPath"));
    infoLayoutWrapper.addComponent(userAuthnEndpointPath);
    main.addComponent(infoLayout);
    Label tokenEndpointPath = new Label();
    tokenEndpointPath.setCaption(msg.getMessage("OAuthEditorGeneralTab.tokenEndpointPath"));
    infoLayoutWrapper.addComponent(tokenEndpointPath);
    Button metaPath = new Button();
    if (editMode) {
        HorizontalLayout l = new HorizontalLayout();
        l.setCaption(msg.getMessage("OAuthEditorGeneralTab.metadataLink"));
        metaPath.setStyleName(Styles.vButtonLink.toString());
        l.addComponent(metaPath);
        infoLayoutWrapper.addComponent(l);
        metaPath.addClickListener(e -> Page.getCurrent().open(metaPath.getCaption(), "_blank", false));
    }
    name = new TextField();
    name.setCaption(msg.getMessage("ServiceEditorBase.name"));
    name.setReadOnly(editMode);
    oauthWebAuthzBinder.forField(name).asRequired().bind("name");
    mainGeneralLayout.addComponent(name);
    TextField tokenContextPath = new TextField();
    TextField webAuthzContextPath = new TextField();
    webAuthzContextPath.setRequiredIndicatorVisible(true);
    webAuthzContextPath.setCaption(msg.getMessage("OAuthEditorGeneralTab.usersAuthnPath"));
    webAuthzContextPath.setReadOnly(editMode);
    webAuthzContextPath.setPlaceholder("/oauth");
    oauthWebAuthzBinder.forField(webAuthzContextPath).withValidator((v, c) -> {
        ValidationResult r;
        if (editMode) {
            r = validatePathForEdit(v);
        } else {
            r = validatePathForAdd(v, tokenContextPath.getValue());
        }
        if (r.isError()) {
            userAuthnEndpointPath.setValue("");
        } else {
            userAuthnEndpointPath.setValue(serverPrefix + v + OAuthAuthzWebEndpoint.OAUTH_CONSUMER_SERVLET_PATH);
        }
        return r;
    }).bind("address");
    mainGeneralLayout.addComponent(webAuthzContextPath);
    tokenContextPath.setRequiredIndicatorVisible(true);
    tokenContextPath.setCaption(msg.getMessage("OAuthEditorGeneralTab.clientTokenPath"));
    tokenContextPath.setPlaceholder("/oauth-token");
    tokenContextPath.setReadOnly(editMode);
    oauthTokenBinder.forField(tokenContextPath).withValidator((v, c) -> {
        ValidationResult r;
        if (editMode) {
            r = validatePathForEdit(v);
        } else {
            r = validatePathForAdd(v, webAuthzContextPath.getValue());
        }
        if (r.isError()) {
            tokenEndpointPath.setValue("");
        } else {
            tokenEndpointPath.setValue(serverPrefix + v + OAuthTokenEndpoint.TOKEN_PATH);
            metaPath.setCaption(serverPrefix + v + "/.well-known/openid-configuration");
        }
        return r;
    }).bind("address");
    mainGeneralLayout.addComponent(tokenContextPath);
    I18nTextField displayedName = new I18nTextField(msg);
    displayedName.setCaption(msg.getMessage("ServiceEditorBase.displayedName"));
    oauthWebAuthzBinder.forField(displayedName).bind("displayedName");
    mainGeneralLayout.addComponent(displayedName);
    TextField description = new DescriptionTextField(msg);
    oauthWebAuthzBinder.forField(description).bind("description");
    mainGeneralLayout.addComponent(description);
    TextField issuerURI = new TextField();
    issuerURI.setPlaceholder(msg.getMessage("OAuthEditorGeneralTab.issuerURIPlaceholder"));
    issuerURI.setWidth(FieldSizeConstans.LINK_FIELD_WIDTH, FieldSizeConstans.LINK_FIELD_WIDTH_UNIT);
    issuerURI.setCaption(msg.getMessage("OAuthEditorGeneralTab.issuerURI"));
    configBinder.forField(issuerURI).asRequired().bind("issuerURI");
    mainGeneralLayout.addComponent(issuerURI);
    IntStepper idTokenExp = new IntStepper();
    idTokenExp.setWidth(5, Unit.EM);
    idTokenExp.setCaption(msg.getMessage("OAuthEditorGeneralTab.idTokenExpiration"));
    configBinder.forField(idTokenExp).asRequired(msg.getMessage("notAPositiveNumber")).withValidator(new IntegerRangeValidator(msg.getMessage("notAPositiveNumber"), 1, null)).bind("idTokenExpiration");
    mainGeneralLayout.addComponent(idTokenExp);
    IntStepper codeTokenExp = new IntStepper();
    codeTokenExp.setWidth(5, Unit.EM);
    codeTokenExp.setCaption(msg.getMessage("OAuthEditorGeneralTab.codeTokenExpiration"));
    configBinder.forField(codeTokenExp).asRequired(msg.getMessage("notAPositiveNumber")).withValidator(new IntegerRangeValidator(msg.getMessage("notAPositiveNumber"), 1, null)).bind("codeTokenExpiration");
    mainGeneralLayout.addComponent(codeTokenExp);
    IntStepper accessTokenExp = new IntStepper();
    accessTokenExp.setWidth(5, Unit.EM);
    accessTokenExp.setCaption(msg.getMessage("OAuthEditorGeneralTab.accessTokenExpiration"));
    configBinder.forField(accessTokenExp).asRequired(msg.getMessage("notAPositiveNumber")).withValidator(new IntegerRangeValidator(msg.getMessage("notAPositiveNumber"), 1, null)).bind("accessTokenExpiration");
    mainGeneralLayout.addComponent(accessTokenExp);
    IntStepper refreshTokenExp = new IntStepper();
    EnumComboBox<RefreshTokenIssuePolicy> refreshTokenIssuePolicy = new EnumComboBox<>(msg, "OAuthEditorGeneralTab.refreshTokenIssuePolicy.", RefreshTokenIssuePolicy.class, RefreshTokenIssuePolicy.NEVER);
    refreshTokenExp.setDescription(msg.getMessage("OAuthEditorGeneralTab.refreshTokenExpirationDescription"));
    TooltipExtension.tooltip(refreshTokenExp);
    refreshTokenIssuePolicy.setCaption(msg.getMessage("OAuthEditorGeneralTab.refreshTokenIssuePolicy"));
    refreshTokenIssuePolicy.setEmptySelectionAllowed(false);
    configBinder.forField(refreshTokenIssuePolicy).bind("refreshTokenIssuePolicy");
    mainGeneralLayout.addComponent(refreshTokenIssuePolicy);
    refreshTokenIssuePolicy.addValueChangeListener(e -> {
        refreshTokenExp.setEnabled(!e.getValue().equals(RefreshTokenIssuePolicy.NEVER));
        refreshScope(e.getValue().equals(RefreshTokenIssuePolicy.OFFLINE_SCOPE_BASED), OIDCScopeValue.OFFLINE_ACCESS, msg.getMessage("OAuthEditorGeneralTab.defaultOfflineAccessScopeDesc"));
    });
    refreshTokenExp.setWidth(5, Unit.EM);
    refreshTokenExp.setCaption(msg.getMessage("OAuthEditorGeneralTab.refreshTokenExpiration"));
    configBinder.forField(refreshTokenExp).asRequired(msg.getMessage("notAPositiveNumber")).withValidator(new IntegerRangeValidator(msg.getMessage("notAPositiveNumber"), 0, null)).bind("refreshTokenExpiration");
    refreshTokenExp.setEnabled(false);
    mainGeneralLayout.addComponent(refreshTokenExp);
    IntStepper extendAccessTokenValidity = new IntStepper();
    CheckBox supportExtendAccessTokenValidity = new CheckBox(msg.getMessage("OAuthEditorGeneralTab.supportExtendTokenValidity"));
    configBinder.forField(supportExtendAccessTokenValidity).bind("supportExtendTokenValidity");
    mainGeneralLayout.addComponent(supportExtendAccessTokenValidity);
    supportExtendAccessTokenValidity.addValueChangeListener(e -> extendAccessTokenValidity.setEnabled(e.getValue()));
    extendAccessTokenValidity.setWidth(5, Unit.EM);
    extendAccessTokenValidity.setCaption(msg.getMessage("OAuthEditorGeneralTab.maxExtendAccessTokenValidity"));
    configBinder.forField(extendAccessTokenValidity).asRequired((v, c) -> {
        if (supportExtendAccessTokenValidity.getValue()) {
            return new IntegerRangeValidator(msg.getMessage("notAPositiveNumber"), 1, null).apply(v, c);
        }
        return ValidationResult.ok();
    }).bind("maxExtendAccessTokenValidity");
    extendAccessTokenValidity.setEnabled(false);
    mainGeneralLayout.addComponent(extendAccessTokenValidity);
    CheckBox skipConsentScreen = new CheckBox(msg.getMessage("OAuthEditorGeneralTab.skipConsentScreen"));
    configBinder.forField(skipConsentScreen).bind("skipConsentScreen");
    mainGeneralLayout.addComponent(skipConsentScreen);
    accessTokenFormat = createAccessTokenFormatCombo();
    mainGeneralLayout.addComponent(accessTokenFormat);
    openIDConnect = new CheckBox(msg.getMessage("OAuthEditorGeneralTab.openIDConnect"));
    configBinder.forField(openIDConnect).bind("openIDConnect");
    mainGeneralLayout.addComponent(openIDConnect);
    signingAlg = new ComboBox<>();
    signingAlg.setCaption(msg.getMessage("OAuthEditorGeneralTab.signingAlgorithm"));
    signingAlg.setEmptySelectionAllowed(false);
    signingAlg.setItems(SigningAlgorithms.values());
    configBinder.forField(signingAlg).bind("signingAlg");
    mainGeneralLayout.addComponent(signingAlg);
    signingAlg.addValueChangeListener(e -> refreshSigningControls());
    credential = new ComboBox<>();
    credential.setCaption(msg.getMessage("OAuthEditorGeneralTab.signingCredential"));
    credential.setEmptySelectionAllowed(false);
    credential.setItems(credentials);
    configBinder.forField(credential).asRequired((v, c) -> {
        if (credential.isEnabled() && (v == null || v.isEmpty()) && !Family.HMAC_SHA.contains(JWSAlgorithm.parse(signingAlg.getValue().toString()))) {
            return ValidationResult.error(msg.getMessage("fieldRequired"));
        }
        return ValidationResult.ok();
    }).bind("credential");
    credential.setEnabled(false);
    mainGeneralLayout.addComponent(credential);
    signingSecret = new TextField();
    signingSecret.setWidth(FieldSizeConstans.WIDE_FIELD_WIDTH, FieldSizeConstans.WIDE_FIELD_WIDTH_UNIT);
    signingSecret.setCaption(msg.getMessage("OAuthEditorGeneralTab.signingSecret"));
    configBinder.forField(signingSecret).asRequired((v, c) -> {
        JWSAlgorithm alg = JWSAlgorithm.parse(signingAlg.getValue().toString());
        if (signingSecret.isEnabled() && Family.HMAC_SHA.contains(alg)) {
            if (v == null || v.isEmpty()) {
                return ValidationResult.error(msg.getMessage("fieldRequired"));
            } else {
                if (v.getBytes(StandardCharsets.UTF_8).length * 8 < getBitsLenghtForAlg(alg)) {
                    return ValidationResult.error(msg.getMessage("toShortValue"));
                }
            }
        }
        return ValidationResult.ok();
    }).bind("signingSecret");
    signingSecret.setEnabled(false);
    mainGeneralLayout.addComponent(signingSecret);
    openIDConnect.addValueChangeListener(e -> {
        refreshSigningControls();
        refreshScope(e.getValue(), OIDCScopeValue.OPENID, msg.getMessage("OAuthEditorGeneralTab.defaultOpenidScopeDesc"));
    });
    return main;
}
Also used : FormLayout(com.vaadin.ui.FormLayout) CustomComponent(com.vaadin.ui.CustomComponent) TextField(com.vaadin.ui.TextField) NoSpaceValidator(pl.edu.icm.unity.webui.common.validators.NoSpaceValidator) OutputTranslationProfileFieldFactory(io.imunity.webconsole.utils.tprofile.OutputTranslationProfileFieldFactory) GridWithEditorInDetails(pl.edu.icm.unity.webui.common.GridWithEditorInDetails) CheckBox(com.vaadin.ui.CheckBox) EditorTab(pl.edu.icm.unity.webui.console.services.ServiceEditorBase.EditorTab) Page(com.vaadin.server.Page) DefaultServiceDefinition(pl.edu.icm.unity.webui.console.services.DefaultServiceDefinition) MessageSource(pl.edu.icm.unity.MessageSource) IntegerRangeValidator(com.vaadin.data.validator.IntegerRangeValidator) ServiceEditorTab(pl.edu.icm.unity.webui.console.services.ServiceEditorComponent.ServiceEditorTab) ImmutableSet(com.google.common.collect.ImmutableSet) Family(com.nimbusds.jose.JWSAlgorithm.Family) OAuthTokenEndpoint(pl.edu.icm.unity.oauth.as.token.OAuthTokenEndpoint) RefreshTokenIssuePolicy(pl.edu.icm.unity.oauth.as.OAuthASProperties.RefreshTokenIssuePolicy) Collection(java.util.Collection) Set(java.util.Set) JWSAlgorithm(com.nimbusds.jose.JWSAlgorithm) OIDCScopeValue(com.nimbusds.openid.connect.sdk.OIDCScopeValue) EnumComboBox(pl.edu.icm.unity.webui.common.EnumComboBox) FormLayoutWithFixedCaptionWidth(pl.edu.icm.unity.webui.common.FormLayoutWithFixedCaptionWidth) Collectors(java.util.stream.Collectors) Binder(com.vaadin.data.Binder) StandardCharsets(java.nio.charset.StandardCharsets) MarginInfo(com.vaadin.shared.ui.MarginInfo) SigningAlgorithms(pl.edu.icm.unity.oauth.as.OAuthASProperties.SigningAlgorithms) Images(pl.edu.icm.unity.webui.common.Images) List(java.util.List) ChipsWithFreeText(pl.edu.icm.unity.webui.common.chips.ChipsWithFreeText) Styles(pl.edu.icm.unity.webui.common.Styles) IntStepper(org.vaadin.risto.stepper.IntStepper) FieldSizeConstans(pl.edu.icm.unity.webui.common.FieldSizeConstans) VerticalLayout(com.vaadin.ui.VerticalLayout) ComboBox(com.vaadin.ui.ComboBox) ValidationResult(com.vaadin.data.ValidationResult) DescriptionTextField(pl.edu.icm.unity.webui.common.widgets.DescriptionTextField) IdentityType(pl.edu.icm.unity.types.basic.IdentityType) Label(com.vaadin.ui.Label) AccessTokenFormat(pl.edu.icm.unity.oauth.as.OAuthASProperties.AccessTokenFormat) EmbeddedEditor(pl.edu.icm.unity.webui.common.GridWithEditorInDetails.EmbeddedEditor) OAuthAuthzWebEndpoint(pl.edu.icm.unity.oauth.as.webauthz.OAuthAuthzWebEndpoint) TooltipExtension(io.imunity.tooltip.TooltipExtension) CollapsibleLayout(pl.edu.icm.unity.webui.common.CollapsibleLayout) WrongArgumentException(pl.edu.icm.unity.exceptions.WrongArgumentException) ValueChangeListener(com.vaadin.data.HasValue.ValueChangeListener) EndpointPathValidator(pl.edu.icm.unity.engine.api.endpoint.EndpointPathValidator) Button(com.vaadin.ui.Button) SubViewSwitcher(pl.edu.icm.unity.webui.common.webElements.SubViewSwitcher) I18nTextField(pl.edu.icm.unity.webui.common.i18n.I18nTextField) HorizontalLayout(com.vaadin.ui.HorizontalLayout) FormLayout(com.vaadin.ui.FormLayout) FormValidationException(pl.edu.icm.unity.webui.common.FormValidationException) Component(com.vaadin.ui.Component) IntegerRangeValidator(com.vaadin.data.validator.IntegerRangeValidator) DescriptionTextField(pl.edu.icm.unity.webui.common.widgets.DescriptionTextField) RefreshTokenIssuePolicy(pl.edu.icm.unity.oauth.as.OAuthASProperties.RefreshTokenIssuePolicy) Label(com.vaadin.ui.Label) I18nTextField(pl.edu.icm.unity.webui.common.i18n.I18nTextField) EnumComboBox(pl.edu.icm.unity.webui.common.EnumComboBox) ValidationResult(com.vaadin.data.ValidationResult) JWSAlgorithm(com.nimbusds.jose.JWSAlgorithm) HorizontalLayout(com.vaadin.ui.HorizontalLayout) FormLayoutWithFixedCaptionWidth(pl.edu.icm.unity.webui.common.FormLayoutWithFixedCaptionWidth) Button(com.vaadin.ui.Button) MarginInfo(com.vaadin.shared.ui.MarginInfo) CheckBox(com.vaadin.ui.CheckBox) VerticalLayout(com.vaadin.ui.VerticalLayout) TextField(com.vaadin.ui.TextField) DescriptionTextField(pl.edu.icm.unity.webui.common.widgets.DescriptionTextField) I18nTextField(pl.edu.icm.unity.webui.common.i18n.I18nTextField) IntStepper(org.vaadin.risto.stepper.IntStepper)

Aggregations

ValidationResult (com.vaadin.data.ValidationResult)5 Component (com.vaadin.ui.Component)4 Binder (com.vaadin.data.Binder)3 CheckBox (com.vaadin.ui.CheckBox)3 ComboBox (com.vaadin.ui.ComboBox)3 CustomComponent (com.vaadin.ui.CustomComponent)3 FormLayout (com.vaadin.ui.FormLayout)3 Collection (java.util.Collection)3 Set (java.util.Set)3 Collectors (java.util.stream.Collectors)3 MessageSource (pl.edu.icm.unity.MessageSource)3 IntegerRangeValidator (com.vaadin.data.validator.IntegerRangeValidator)2 Page (com.vaadin.server.Page)2 MarginInfo (com.vaadin.shared.ui.MarginInfo)2 Button (com.vaadin.ui.Button)2 HorizontalLayout (com.vaadin.ui.HorizontalLayout)2 Label (com.vaadin.ui.Label)2 TextField (com.vaadin.ui.TextField)2 VerticalLayout (com.vaadin.ui.VerticalLayout)2 OutputTranslationProfileFieldFactory (io.imunity.webconsole.utils.tprofile.OutputTranslationProfileFieldFactory)2