Skip to content

Commit

Permalink
Merge pull request #982 from hpehl/HAL-1914
Browse files Browse the repository at this point in the history
HAL-1914: Fix create/edit mapped role mappers
  • Loading branch information
hpehl committed Oct 18, 2023
2 parents fc2f08c + a9fb265 commit 8380cd5
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -82,11 +82,13 @@
import static org.jboss.hal.client.configuration.subsystem.elytron.AddressTemplates.X500_ATTRIBUTE_PRINCIPAL_DECODER_ADDRESS;
import static org.jboss.hal.client.configuration.subsystem.elytron.AddressTemplates.X500_SUBJECT_EVIDENCE_DECODER_ADDRESS;
import static org.jboss.hal.client.configuration.subsystem.elytron.AddressTemplates.X509_SUBJECT_ALT_NAME_EVIDENCE_DECODER_ADDRESS;
import static org.jboss.hal.dmr.ModelDescriptionConstants.FROM;
import static org.jboss.hal.dmr.ModelDescriptionConstants.MAPPED_ROLE_MAPPER;
import static org.jboss.hal.dmr.ModelDescriptionConstants.PERMISSIONS;
import static org.jboss.hal.dmr.ModelDescriptionConstants.PERMISSION_MAPPINGS;
import static org.jboss.hal.dmr.ModelDescriptionConstants.RESULT;
import static org.jboss.hal.dmr.ModelDescriptionConstants.ROLE_MAP;
import static org.jboss.hal.dmr.ModelDescriptionConstants.TO;
import static org.jboss.hal.dmr.ModelNodeHelper.asNamedNodes;

public class MapperDecoderPresenter extends MbuiPresenter<MapperDecoderPresenter.MyView, MapperDecoderPresenter.MyProxy>
Expand Down Expand Up @@ -273,7 +275,8 @@ void addMappedRoleMapper() {
String id = Ids.build(Ids.ELYTRON_MAPPED_ROLE_MAPPER, Ids.ADD);
Form<ModelNode> form = new ModelNodeForm.Builder<>(id, metadata)
.unboundFormItem(new NameItem(), 0)
.customFormItem(ROLE_MAP, desc -> new RoleMapListItem(ROLE_MAP, new LabelBuilder().label(ROLE_MAP)))
// .customFormItem(ROLE_MAP, desc -> new RoleMapListItem(ROLE_MAP, new LabelBuilder().label(ROLE_MAP)))
.customFormItem(ROLE_MAP, (desc) -> new MultiValueListItem(ROLE_MAP, FROM, TO))
.addOnly()
.build();
String title = new LabelBuilder().label(MAPPED_ROLE_MAPPER);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,16 @@
import static org.jboss.elemento.Elements.section;
import static org.jboss.hal.client.configuration.subsystem.elytron.AddressTemplates.CONSTANT_PERMISSION_MAPPER_TEMPLATE;
import static org.jboss.hal.client.configuration.subsystem.elytron.AddressTemplates.MAPPED_ROLE_MAPPER_TEMPLATE;
import static org.jboss.hal.dmr.ModelDescriptionConstants.*;
import static org.jboss.hal.dmr.ModelDescriptionConstants.CLASS_NAME;
import static org.jboss.hal.dmr.ModelDescriptionConstants.CONSTANT_PERMISSION_MAPPER;
import static org.jboss.hal.dmr.ModelDescriptionConstants.FROM;
import static org.jboss.hal.dmr.ModelDescriptionConstants.MAPPED_ROLE_MAPPER;
import static org.jboss.hal.dmr.ModelDescriptionConstants.MODULE;
import static org.jboss.hal.dmr.ModelDescriptionConstants.NAME;
import static org.jboss.hal.dmr.ModelDescriptionConstants.PERMISSIONS;
import static org.jboss.hal.dmr.ModelDescriptionConstants.ROLE_MAP;
import static org.jboss.hal.dmr.ModelDescriptionConstants.TABLE;
import static org.jboss.hal.dmr.ModelDescriptionConstants.TO;
import static org.jboss.hal.resources.Ids.FORM;
import static org.jboss.hal.resources.Ids.ITEM;
import static org.jboss.hal.resources.Ids.build;
Expand Down Expand Up @@ -143,7 +152,8 @@ void init() {
.build();

mappedRoleMapperForm = new ModelNodeForm.Builder<NamedNode>(build(mappedId, FORM), mappedMetadata)
.customFormItem(ROLE_MAP, desc -> new RoleMapListItem(ROLE_MAP, labelBuilder.label(ROLE_MAP)))
.customFormItem(ROLE_MAP, (desc) -> new MultiValueListItem(ROLE_MAP, FROM, TO))
// .customFormItem(ROLE_MAP, desc -> new RoleMapListItem(ROLE_MAP, labelBuilder.label(ROLE_MAP)))
.onSave((form, changedValues) -> {
String name = form.getModel().getName();
ResourceAddress address = MAPPED_ROLE_MAPPER_TEMPLATE.resolve(mbuiContext.statementContext(), name);
Expand All @@ -152,8 +162,8 @@ void init() {
.build();

HTMLElement mappedSection = section()
.add(h(1).textContent(Names.SIMPLE_PERMISSION_MAPPER))
.add(p().textContent(metadata.getDescription().getDescription()))
.add(h(1).textContent(Names.MAPPED_ROLE_MAPPER))
.add(p().textContent(mappedMetadata.getDescription().getDescription()))
.add(mappedRoleMapperTable)
.add(mappedRoleMapperForm).element();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,12 @@ class MultiValueListItem extends TagsItem<ModelNode> implements ModelNodeItem {
private static final Messages MESSAGES = GWT.create(Messages.class);

MultiValueListItem(String attribute) {
this(attribute, NAME, VALUE);
}

MultiValueListItem(String attribute, String name, String value) {
super(attribute, new LabelBuilder().label(attribute), MESSAGES.multiValueListHint(),
EnumSet.of(DEFAULT, DEPRECATED, ENABLED, INVALID, REQUIRED, RESTRICTED), new MapMapping());
EnumSet.of(DEFAULT, DEPRECATED, ENABLED, INVALID, REQUIRED, RESTRICTED), new MapMapping(name, value));
}

@Override
Expand Down Expand Up @@ -113,6 +117,14 @@ private static class MapMapping implements TagsMapping<ModelNode> {
private static final RegExp REGEX = RegExp.compile(
"^([\\w\\-\\.\\/]+)=([\\w\\-\\.\\/" + VALUE_SEPARATOR + "]+)$"); // NON-NLS

private final String name;
private final String value;

private MapMapping(String name, String value) {
this.name = name;
this.value = value;
}

@Override
public Validator validator() {
return REGEX::test;
Expand All @@ -122,9 +134,9 @@ public Validator validator() {
public ModelNode parseTag(final String tag) {
String[] parts = tag.split("=");
ModelNode kv = new ModelNode();
kv.get(NAME).set(parts[0]);
kv.get(name).set(parts[0]);
for (String v : parts[1].split(VALUE_SEPARATOR)) {
kv.get(VALUE).add(v);
kv.get(value).add(v);
}

ModelNode node = new ModelNode();
Expand All @@ -138,7 +150,7 @@ public List<String> tags(final ModelNode value) {
return emptyList();
}
return value.asList().stream()
.map(kv -> kv.get(NAME).asString() + "=" + kv.get(VALUE).asList().stream()
.map(kv -> kv.get(name).asString() + "=" + kv.get(this.value).asList().stream()
.map(ModelNode::asString)
.collect(joining(VALUE_SEPARATOR)))
.collect(toList());
Expand All @@ -150,7 +162,7 @@ public String asString(final ModelNode value) {
return "";
}
return value.asList().stream()
.map(kv -> kv.get(NAME).asString() + " \u21D2 " + kv.get(VALUE).asList().stream()
.map(kv -> kv.get(name).asString() + " \u21D2 " + kv.get(this.value).asList().stream()
.map(ModelNode::asString)
.collect(joining(VALUE_SEPARATOR)))
.collect(joining("\n"));
Expand Down
1 change: 1 addition & 0 deletions resources/src/main/java/org/jboss/hal/resources/Names.java
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,7 @@ public interface Names {
String MANAGEMENT_MODEL = "Management Model";
String MANAGEMENT_OPERATIONS = "Management Operations";
String MANIFEST = "Manifest";
String MAPPED_ROLE_MAPPER = "Mapped Role Mapper";
String MAPPERS_DECODERS = "Mappers / Decoders";
String MAPPING_MODULE = "Mapping Module";
String PRIMARY = "Primary";
Expand Down

0 comments on commit 8380cd5

Please sign in to comment.