Skip to content

Commit

Permalink
Merge pull request #981 from michpetrov/hal-1936
Browse files Browse the repository at this point in the history
HAL-1936: fix cred-ref handling in app security domain
  • Loading branch information
hpehl authored Oct 18, 2023
2 parents a62fe11 + 32eec2b commit 89af919
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,16 @@ public CredentialReference(EventBus eventBus, Dispatcher dispatcher, ComplexAttr
public Form<ModelNode> form(String baseId, Metadata metadata, String alternativeName,
Supplier<String> alternativeValue, Supplier<ResourceAddress> 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<ModelNode> form(String baseId, Metadata metadata, String crName, String alternativeName,
Supplier<String> alternativeValue, Supplier<ResourceAddress> address, Callback callback) {
return form(baseId, metadata, crName, alternativeName, alternativeValue, null, address, null, callback);
}

/**
Expand All @@ -98,12 +107,15 @@ public Form<ModelNode> 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<ModelNode> form(String baseId, Metadata metadata, String crName, String alternativeName,
Supplier<String> alternativeValue, Supplier<ResourceAddress> address, Callback callback) {
Supplier<String> alternativeValue, Supplier<Operation> ping, Supplier<ResourceAddress> address,
Callback emptyAction, Callback callback) {

String credentialReferenceName = crName == null ? CREDENTIAL_REFERENCE : crName;
Metadata crMetadata = metadata.forComplexAttribute(credentialReferenceName);
Expand All @@ -112,46 +124,48 @@ public Form<ModelNode> 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 {
emptyStateBuilder.description(resources.constants().restricted());
}
EmptyState noCredentialReference = emptyStateBuilder.build();

Supplier<Operation> 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<ModelNode> 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) {
Expand Down

0 comments on commit 89af919

Please sign in to comment.