Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HAL-2003: consolidate credential-reference handling #1273

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -33,22 +33,18 @@

import static java.util.Arrays.asList;

import static org.jboss.hal.dmr.ModelDescriptionConstants.ALIAS;
import static org.jboss.hal.dmr.ModelDescriptionConstants.AUTHENTICATION_CONTEXT;
import static org.jboss.hal.dmr.ModelDescriptionConstants.CLEAR_TEXT;
import static org.jboss.hal.dmr.ModelDescriptionConstants.CONNECTION_URL;
import static org.jboss.hal.dmr.ModelDescriptionConstants.CREDENTIAL_REFERENCE;
import static org.jboss.hal.dmr.ModelDescriptionConstants.PASSWORD;
import static org.jboss.hal.dmr.ModelDescriptionConstants.STORE;
import static org.jboss.hal.dmr.ModelDescriptionConstants.TYPE;
import static org.jboss.hal.dmr.ModelDescriptionConstants.USER_NAME;
import static org.jboss.hal.dmr.ModelNodeHelper.move;

class ConnectionStep extends WizardStep<Context, State> {

private final ModelNodeForm<ModelNode> form;

private List<String> credRefAttrs = asList(STORE, ALIAS, CLEAR_TEXT, TYPE);
private List<String> credRefAttrs = asList(CredentialReference.ATTRIBUTES);
private List<String> otherAttrs = asList(USER_NAME, PASSWORD, AUTHENTICATION_CONTEXT);

@SuppressWarnings({ "unchecked", "rawtypes" })
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@
import org.jboss.hal.core.mbui.dialog.AddResourceDialog;
import org.jboss.hal.core.mbui.dialog.NameItem;
import org.jboss.hal.core.mbui.form.ModelNodeForm;
import org.jboss.hal.core.mbui.form.RequireAtLeastOneAttributeValidation;
import org.jboss.hal.core.mvp.SupportsExpertMode;
import org.jboss.hal.dmr.ModelDescriptionConstants;
import org.jboss.hal.dmr.ModelNode;
Expand Down Expand Up @@ -114,9 +113,7 @@
import static org.jboss.hal.dmr.ModelDescriptionConstants.CAPABILITY_REFERENCE;
import static org.jboss.hal.dmr.ModelDescriptionConstants.CHILD_TYPE;
import static org.jboss.hal.dmr.ModelDescriptionConstants.CLASS_NAME;
import static org.jboss.hal.dmr.ModelDescriptionConstants.CLEAR_TEXT;
import static org.jboss.hal.dmr.ModelDescriptionConstants.CREATE;
import static org.jboss.hal.dmr.ModelDescriptionConstants.CREDENTIAL_REFERENCE;
import static org.jboss.hal.dmr.ModelDescriptionConstants.CREDENTIAL_STORE;
import static org.jboss.hal.dmr.ModelDescriptionConstants.DEFAULT_REALM;
import static org.jboss.hal.dmr.ModelDescriptionConstants.EXPRESSION;
Expand Down Expand Up @@ -148,7 +145,6 @@
import static org.jboss.hal.dmr.ModelDescriptionConstants.SECURITY_DOMAIN;
import static org.jboss.hal.dmr.ModelDescriptionConstants.SERVER_AUTH_MODULES;
import static org.jboss.hal.dmr.ModelDescriptionConstants.SERVER_SSL_SNI_CONTEXT;
import static org.jboss.hal.dmr.ModelDescriptionConstants.STORE;
import static org.jboss.hal.dmr.ModelDescriptionConstants.TYPE;
import static org.jboss.hal.dmr.ModelDescriptionConstants.VALUE;
import static org.jboss.hal.dmr.ModelDescriptionConstants.VALUE_TYPE;
Expand Down Expand Up @@ -324,8 +320,7 @@ void addCredentialStore() {
.unsorted()
.build();
form.getFormItem(RELATIVE_TO).registerSuggestHandler(new PathsAutoComplete());
form.addFormValidation(new RequireAtLeastOneAttributeValidation<>(
asList(CREDENTIAL_REFERENCE + "." + STORE, CREDENTIAL_REFERENCE + "." + CLEAR_TEXT), resources));
form.addFormValidation(new CredentialReference.CrFormValuesValidation(resources, true));
form.addFormValidation(form1 -> {
ValidationResult result = ValidationResult.OK;
String typeValue = form1.<String> getFormItem(TYPE).getValue();
Expand Down Expand Up @@ -421,8 +416,7 @@ void addKeyStore() {
.unsorted()
.build();
form.getFormItem(RELATIVE_TO).registerSuggestHandler(new PathsAutoComplete());
form.addFormValidation(new RequireAtLeastOneAttributeValidation<>(
asList(CREDENTIAL_REFERENCE + "." + STORE, CREDENTIAL_REFERENCE + "." + CLEAR_TEXT), resources));
form.addFormValidation(new CredentialReference.CrFormValuesValidation(resources, true));

new AddResourceDialog(resources.messages().addResourceTitle(Names.KEY_STORE), form, (name, model) -> {
ResourceAddress address = KEY_STORE_TEMPLATE.resolve(statementContext, nameItem.getValue());
Expand All @@ -444,8 +438,7 @@ void addKeyManager() {
.include(CredentialReference.ATTRIBUTES_PREFIXED)
.unsorted()
.build();
form.addFormValidation(new RequireAtLeastOneAttributeValidation<>(
asList(CREDENTIAL_REFERENCE + "." + STORE, CREDENTIAL_REFERENCE + "." + CLEAR_TEXT), resources));
form.addFormValidation(new CredentialReference.CrFormValuesValidation(resources, true));

new AddResourceDialog(resources.messages().addResourceTitle(Names.KEY_MANAGER), form, (name, model) -> {
ResourceAddress address = KEY_MANAGER_TEMPLATE.resolve(statementContext, nameItem.getValue());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
import org.jboss.hal.core.finder.FinderPathFactory;
import org.jboss.hal.core.mbui.dialog.AddResourceDialog;
import org.jboss.hal.core.mbui.form.ModelNodeForm;
import org.jboss.hal.core.mbui.form.RequireAtLeastOneAttributeValidation;
import org.jboss.hal.core.mvp.ApplicationFinderPresenter;
import org.jboss.hal.core.mvp.HalView;
import org.jboss.hal.core.mvp.HasPresenter;
Expand All @@ -56,21 +55,16 @@
import com.gwtplatform.mvp.client.proxy.ProxyPlace;
import com.gwtplatform.mvp.shared.proxy.PlaceRequest;

import static java.util.Arrays.asList;

import static org.jboss.hal.client.configuration.subsystem.undertow.AddressTemplates.APPLICATION_SECURITY_DOMAIN_ADDRESS;
import static org.jboss.hal.client.configuration.subsystem.undertow.AddressTemplates.APPLICATION_SECURITY_DOMAIN_TEMPLATE;
import static org.jboss.hal.client.configuration.subsystem.undertow.AddressTemplates.SELECTED_APPLICATION_SECURITY_DOMAIN_TEMPLATE;
import static org.jboss.hal.client.configuration.subsystem.undertow.AddressTemplates.SELECTED_SINGLE_SIGN_ON_TEMPLATE;
import static org.jboss.hal.dmr.ModelDescriptionConstants.CHILD_TYPE;
import static org.jboss.hal.dmr.ModelDescriptionConstants.CLEAR_TEXT;
import static org.jboss.hal.dmr.ModelDescriptionConstants.CREDENTIAL_REFERENCE;
import static org.jboss.hal.dmr.ModelDescriptionConstants.KEY_ALIAS;
import static org.jboss.hal.dmr.ModelDescriptionConstants.KEY_STORE;
import static org.jboss.hal.dmr.ModelDescriptionConstants.NAME;
import static org.jboss.hal.dmr.ModelDescriptionConstants.READ_CHILDREN_RESOURCES_OPERATION;
import static org.jboss.hal.dmr.ModelDescriptionConstants.SETTING;
import static org.jboss.hal.dmr.ModelDescriptionConstants.STORE;
import static org.jboss.hal.dmr.ModelDescriptionConstants.UNDERTOW;
import static org.jboss.hal.meta.SelectionAwareStatementContext.SELECTION_KEY;

Expand Down Expand Up @@ -198,8 +192,7 @@ void addSingleSignOn() {
.include(CredentialReference.ATTRIBUTES_PREFIXED)
.unsorted()
.build();
form.addFormValidation(new RequireAtLeastOneAttributeValidation<>(
asList(CREDENTIAL_REFERENCE + "." + STORE, CREDENTIAL_REFERENCE + "." + CLEAR_TEXT), resources));
form.addFormValidation(new CredentialReference.CrFormValuesValidation(resources, true));

AddResourceDialog dialog = new AddResourceDialog(resources.messages().addResourceTitle(Names.SINGLE_SIGN_ON),
form, (name, model) -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,17 @@ public class CredentialReference {
CLEAR_TEXT
};

private static final String DOT = ".";
private static final String STORE_PREFIXED = CREDENTIAL_REFERENCE + DOT + STORE;
private static final String ALIAS_PREFIXED = CREDENTIAL_REFERENCE + DOT + ALIAS;
private static final String TYPE_PREFIXED = CREDENTIAL_REFERENCE + DOT + TYPE;
private static final String CLEAR_TEXT_PREFIXED = CREDENTIAL_REFERENCE + DOT + CLEAR_TEXT;

public static final String[] ATTRIBUTES_PREFIXED = new String[] {
CREDENTIAL_REFERENCE + "." + STORE,
CREDENTIAL_REFERENCE + "." + ALIAS,
CREDENTIAL_REFERENCE + "." + TYPE,
CREDENTIAL_REFERENCE + "." + CLEAR_TEXT
STORE_PREFIXED,
ALIAS_PREFIXED,
TYPE_PREFIXED,
CLEAR_TEXT_PREFIXED
};

@Inject
Expand Down Expand Up @@ -177,7 +183,7 @@ public Form<ModelNode> form(String baseId, Metadata metadata, String crName, Str

ModelNodeForm.Builder<ModelNode> formBuilder = new ModelNodeForm.Builder<>(
Ids.build(baseId, credentialReferenceName, Ids.FORM), crMetadata)
.include(STORE, ALIAS, CLEAR_TEXT, TYPE)
.include(ATTRIBUTES)
.unsorted()
.singleton(ping == null ? defaultPing : ping, noCredentialReference)
.onSave(((f, changedValues) -> {
Expand Down Expand Up @@ -302,19 +308,25 @@ public ValidationResult validate(Form<T> form) {
* </ul>
* See also https://docs.wildfly.org/25/WildFly_Elytron_Security.html#automatic-updates-of-credential-stores
*/
private static class CrFormValuesValidation implements FormValidation<ModelNode> {
public static class CrFormValuesValidation implements FormValidation<ModelNode> {

private final Resources resources;
private final boolean prefixed;

public CrFormValuesValidation(Resources resources) {
this(resources, false);
}

private CrFormValuesValidation(Resources resources) {
public CrFormValuesValidation(Resources resources, boolean prefixed) {
this.resources = resources;
this.prefixed = prefixed;
}

@Override
public ValidationResult validate(Form<ModelNode> form) {
FormItem<Object> storeItem = form.getFormItem(STORE);
FormItem<Object> aliasItem = form.getFormItem(ALIAS);
FormItem<Object> clearTextItem = form.getFormItem(CLEAR_TEXT);
FormItem<Object> storeItem = form.getFormItem(prefixed ? STORE_PREFIXED : STORE);
FormItem<Object> aliasItem = form.getFormItem(prefixed ? ALIAS_PREFIXED : ALIAS);
FormItem<Object> clearTextItem = form.getFormItem(prefixed ? CLEAR_TEXT_PREFIXED : CLEAR_TEXT);
if (!clearTextItem.isEmpty() && storeItem.isEmpty() && aliasItem.isEmpty()) {
// clear-text only not recommended mode
return ValidationResult.OK;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,10 @@
*/
package org.jboss.hal.meta.description;

import java.util.List;
import java.util.Map;
import java.util.TreeMap;
import java.util.stream.Collectors;

import org.jboss.hal.config.StabilityLevel;
import org.jboss.hal.dmr.ModelNode;
Expand All @@ -29,6 +31,7 @@

import static org.jboss.hal.dmr.ModelDescriptionConstants.ACCESS_TYPE;
import static org.jboss.hal.dmr.ModelDescriptionConstants.ADD;
import static org.jboss.hal.dmr.ModelDescriptionConstants.ALTERNATIVES;
import static org.jboss.hal.dmr.ModelDescriptionConstants.ATTRIBUTES;
import static org.jboss.hal.dmr.ModelDescriptionConstants.ATTRIBUTE_GROUP;
import static org.jboss.hal.dmr.ModelDescriptionConstants.CHILDREN;
Expand All @@ -38,6 +41,7 @@
import static org.jboss.hal.dmr.ModelDescriptionConstants.OPERATIONS;
import static org.jboss.hal.dmr.ModelDescriptionConstants.REQUEST_PROPERTIES;
import static org.jboss.hal.dmr.ModelDescriptionConstants.REQUIRED;
import static org.jboss.hal.dmr.ModelDescriptionConstants.REQUIRES;
import static org.jboss.hal.dmr.ModelDescriptionConstants.STABILITY;
import static org.jboss.hal.dmr.ModelDescriptionConstants.STORAGE;
import static org.jboss.hal.dmr.ModelDescriptionConstants.STRING;
Expand All @@ -48,6 +52,8 @@

public class ResourceDescription extends ModelNode {

private static final String DOT = ".";

private Map<String, AttributeCollection> map = new TreeMap<>();

public ResourceDescription(ModelNode payload) {
Expand Down Expand Up @@ -84,6 +90,7 @@ private AttributeCollection getAttributes(String path) {
if (attributes.isDefined()) {
if (!map.containsKey(path)) {
for (Property p : attributes.asPropertyList()) {
String parentName = p.getName();
ModelNode parentValue = p.getValue();
// process also on LIST type if we're in request attributes.
boolean isRequestProperties = path.endsWith(REQUEST_PROPERTIES);
Expand All @@ -109,7 +116,24 @@ private AttributeCollection getAttributes(String path) {
combined = parentValue.get(REQUIRED).asBoolean()
&& nestedValue.get(REQUIRED).asBoolean();
nestedValue.get(REQUIRED).set(combined);
attributes.get(p.getName() + "." + nested.getName()).set(nestedValue);

ModelNode requires = nestedValue.remove(REQUIRES);
if (requires != null) {
List<ModelNode> requiredNames = requires.asList().stream()
.map(node -> new ModelNode().set(parentName + DOT + node.asString()))
.collect(Collectors.toList());
nestedValue.get(REQUIRES).set(requiredNames);
}

ModelNode alternatives = nestedValue.remove(ALTERNATIVES);
if (alternatives != null) {
List<ModelNode> alternativesNames = alternatives.asList().stream()
.map(node -> new ModelNode().set(parentName + DOT + node.asString()))
.collect(Collectors.toList());
nestedValue.get(ALTERNATIVES).set(alternativesNames);
}

attributes.get(parentName + DOT + nested.getName()).set(nestedValue);
}
}
}
Expand Down
Loading