From 32eec2b347561f2be2006ce96365023c8cd2232a Mon Sep 17 00:00:00 2001 From: Michal Petrov Date: Wed, 18 Oct 2023 14:48:11 +0200 Subject: [PATCH] HAL-1936: fix cred-ref handling in app security domain --- .../ApplicationSecurityDomainPresenter.java | 2 +- .../ApplicationSecurityDomainView.java | 4 +- .../hal/core/elytron/CredentialReference.java | 74 +++++++++++-------- 3 files changed, 48 insertions(+), 32 deletions(-) diff --git a/app/src/main/java/org/jboss/hal/client/configuration/subsystem/undertow/ApplicationSecurityDomainPresenter.java b/app/src/main/java/org/jboss/hal/client/configuration/subsystem/undertow/ApplicationSecurityDomainPresenter.java index 889c9e9319..8cd86315f2 100644 --- a/app/src/main/java/org/jboss/hal/client/configuration/subsystem/undertow/ApplicationSecurityDomainPresenter.java +++ b/app/src/main/java/org/jboss/hal/client/configuration/subsystem/undertow/ApplicationSecurityDomainPresenter.java @@ -187,7 +187,7 @@ Operation checkSingleSignOn() { } ResourceAddress resolveSingleSignOn() { - return SELECTED_SINGLE_SIGN_ON_TEMPLATE.resolve(statementContext); + return SELECTED_APPLICATION_SECURITY_DOMAIN_TEMPLATE.resolve(statementContext); } void addSingleSignOn() { diff --git a/app/src/main/java/org/jboss/hal/client/configuration/subsystem/undertow/ApplicationSecurityDomainView.java b/app/src/main/java/org/jboss/hal/client/configuration/subsystem/undertow/ApplicationSecurityDomainView.java index 4fcae00725..40ff323c1e 100644 --- a/app/src/main/java/org/jboss/hal/client/configuration/subsystem/undertow/ApplicationSecurityDomainView.java +++ b/app/src/main/java/org/jboss/hal/client/configuration/subsystem/undertow/ApplicationSecurityDomainView.java @@ -72,8 +72,10 @@ public ApplicationSecurityDomainView(MetadataRegistry metadataRegistry, Resource // ------------------------------------------------------ credential reference - crForm = cr.form(Ids.UNDERTOW_APP_SECURITY_DOMAIN, ssoMetadata, null, null, + crForm = cr.form(Ids.UNDERTOW_APP_SECURITY_DOMAIN, ssoMetadata, CREDENTIAL_REFERENCE, null, null, + () -> presenter.checkSingleSignOn(), () -> presenter.resolveSingleSignOn(), + () -> presenter.addSingleSignOn(), () -> presenter.reload()); Tabs tabs = new Tabs(Ids.UNDERTOW_APP_SECURITY_DOMAIN_TAB_CONTAINER); diff --git a/core/src/main/java/org/jboss/hal/core/elytron/CredentialReference.java b/core/src/main/java/org/jboss/hal/core/elytron/CredentialReference.java index ba9344b059..cef8c25584 100644 --- a/core/src/main/java/org/jboss/hal/core/elytron/CredentialReference.java +++ b/core/src/main/java/org/jboss/hal/core/elytron/CredentialReference.java @@ -86,7 +86,16 @@ public CredentialReference(EventBus eventBus, Dispatcher dispatcher, ComplexAttr public Form form(String baseId, Metadata metadata, String alternativeName, Supplier alternativeValue, Supplier address, Callback callback) { - return form(baseId, metadata, CREDENTIAL_REFERENCE, alternativeName, alternativeValue, address, callback); + return form(baseId, metadata, CREDENTIAL_REFERENCE, alternativeName, alternativeValue, null, address, null, callback); + } + + /** + * @see CredentialReference#form(String, Metadata, String, String, Supplier, Supplier, Supplier, Callback, Callback) + */ + + public Form form(String baseId, Metadata metadata, String crName, String alternativeName, + Supplier alternativeValue, Supplier address, Callback callback) { + return form(baseId, metadata, crName, alternativeName, alternativeValue, null, address, null, callback); } /** @@ -98,12 +107,15 @@ public Form form(String baseId, Metadata metadata, String alternative * @param crName the name of the credential-reference complex attribute * @param alternativeName the name of the alternative attribute * @param alternativeValue the value of the alternative attribute + * @param ping the operation to check the presence of the credential reference * @param address the fully qualified address of the resource used for the CRUD actions + * @param emptyAction the action to perform to add a credential reference from an empty state * @param callback the callback executed after the {@code credential-reference} attributes has been added, saved, reset or * removed */ public Form form(String baseId, Metadata metadata, String crName, String alternativeName, - Supplier alternativeValue, Supplier address, Callback callback) { + Supplier alternativeValue, Supplier ping, Supplier address, + Callback emptyAction, Callback callback) { String credentialReferenceName = crName == null ? CREDENTIAL_REFERENCE : crName; Metadata crMetadata = metadata.forComplexAttribute(credentialReferenceName); @@ -112,24 +124,26 @@ public Form form(String baseId, Metadata metadata, String crName, Str Ids.build(baseId, credentialReferenceName, Ids.FORM, Ids.EMPTY), resources.constants().noResource()); + Callback defaultEmptyAction = () -> { + if (alternativeName != null && alternativeValue != null && + !Strings.isNullOrEmpty(alternativeValue.get())) { + String alternativeLabel = new LabelBuilder().label(alternativeName); + DialogFactory.showConfirmation( + resources.messages().addResourceTitle(Names.CREDENTIAL_REFERENCE), + resources.messages().credentialReferenceAddConfirmation(alternativeLabel), + () -> setTimeout( + o -> addCredentialReference(baseId, crMetadata, credentialReferenceName, + alternativeName, + address, callback), + SHORT_TIMEOUT)); + } else { + addCredentialReference(baseId, crMetadata, credentialReferenceName, null, address, + callback); + } + }; + if (crMetadata.getSecurityContext().isWritable()) { - emptyStateBuilder.primaryAction(resources.constants().add(), () -> { - if (alternativeName != null && alternativeValue != null && - !Strings.isNullOrEmpty(alternativeValue.get())) { - String alternativeLabel = new LabelBuilder().label(alternativeName); - DialogFactory.showConfirmation( - resources.messages().addResourceTitle(Names.CREDENTIAL_REFERENCE), - resources.messages().credentialReferenceAddConfirmation(alternativeLabel), - () -> setTimeout( - o -> addCredentialReference(baseId, crMetadata, credentialReferenceName, - alternativeName, - address, callback), - SHORT_TIMEOUT)); - } else { - addCredentialReference(baseId, crMetadata, credentialReferenceName, null, address, - callback); - } - }, + emptyStateBuilder.primaryAction(resources.constants().add(), emptyAction == null ? defaultEmptyAction : emptyAction, Constraint.executable(metadata.getTemplate(), ADD)) .description(resources.messages().noResource()); } else { @@ -137,21 +151,21 @@ public Form form(String baseId, Metadata metadata, String crName, Str } EmptyState noCredentialReference = emptyStateBuilder.build(); + Supplier defaultPing = () -> { + ResourceAddress fqAddress = address.get(); + Operation operation = null; + if (fqAddress != null && crMetadata.getSecurityContext().isReadable()) { + operation = new Operation.Builder(address.get(), READ_ATTRIBUTE_OPERATION) + .param(NAME, credentialReferenceName).build(); + } + return operation; + }; + ModelNodeForm.Builder formBuilder = new ModelNodeForm.Builder<>( Ids.build(baseId, credentialReferenceName, Ids.FORM), crMetadata) .include(STORE, ALIAS, CLEAR_TEXT, TYPE) .unsorted() - .singleton( - () -> { - ResourceAddress fqAddress = address.get(); - Operation operation = null; - if (fqAddress != null && crMetadata.getSecurityContext().isReadable()) { - operation = new Operation.Builder(address.get(), READ_ATTRIBUTE_OPERATION) - .param(NAME, credentialReferenceName).build(); - } - return operation; - }, - noCredentialReference) + .singleton(ping == null ? defaultPing : ping, noCredentialReference) .onSave(((f, changedValues) -> { ResourceAddress fqa = address.get(); if (fqa != null) {