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);
}
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);
}
Aggregations