Skip to content

Commit

Permalink
[WFLY-490] [WFLY-1790] fixed the HostScopedRole* operations
Browse files Browse the repository at this point in the history
  • Loading branch information
Ladicek authored and bstansberry committed Aug 7, 2013
1 parent 64f6fcf commit 3124219
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
package org.jboss.as.domain.management.access;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;

Expand Down Expand Up @@ -68,9 +69,10 @@ protected void performRuntime(OperationContext context, ModelNode operation, Mod

String roleName = PathAddress.pathAddress(operation.require(ModelDescriptionConstants.OP_ADDR)).getLastElement().getValue();

String baseRole = ServerGroupScopedRoleResourceDefinition.BASE_ROLE.resolveModelAttribute(context, model).asString();
String baseRole = HostScopedRolesResourceDefinition.BASE_ROLE.resolveModelAttribute(context, model).asString();

List<ModelNode> nodeList = ServerGroupScopedRoleResourceDefinition.SERVER_GROUPS.resolveModelAttribute(context, model).asList();
ModelNode hostsAttribute = HostScopedRolesResourceDefinition.HOSTS.resolveModelAttribute(context, model);
List<ModelNode> nodeList = hostsAttribute.isDefined() ? hostsAttribute.asList() : Collections.<ModelNode>emptyList();

addScopedRole(roleName, baseRole, nodeList, authorizer, constraintMap);
}
Expand All @@ -86,11 +88,11 @@ protected void rollbackRuntime(OperationContext context, ModelNode operation, Mo
static void addScopedRole(final String roleName, final String baseRole, final List<ModelNode> hostNodes,
final ConfigurableAuthorizer authorizer, final Map<String, HostEffectConstraint> constraintMap) {

List<String> serverGroups = new ArrayList<String>();
for (ModelNode group : hostNodes) {
serverGroups.add(group.asString());
List<String> hosts = new ArrayList<String>();
for (ModelNode host : hostNodes) {
hosts.add(host.asString());
}
HostEffectConstraint constraint = new HostEffectConstraint(serverGroups);
HostEffectConstraint constraint = new HostEffectConstraint(hosts);
authorizer.addScopedRole(roleName, baseRole, constraint);
constraintMap.put(roleName, constraint);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

package org.jboss.as.domain.management.access;

import java.util.Collections;
import java.util.List;
import java.util.Map;

Expand Down Expand Up @@ -63,7 +64,8 @@ public void execute(OperationContext context, ModelNode operation) throws Operat

final String roleName = PathAddress.pathAddress(operation.require(ModelDescriptionConstants.OP_ADDR)).getLastElement().getValue();
final String baseRole = ServerGroupScopedRoleResourceDefinition.BASE_ROLE.resolveModelAttribute(context, model).asString();
final List<ModelNode> hostNodes = HostScopedRolesResourceDefinition.HOSTS.resolveModelAttribute(context, model).asList();
ModelNode hostsAttribute = HostScopedRolesResourceDefinition.HOSTS.resolveModelAttribute(context, model);
final List<ModelNode> hostNodes = hostsAttribute.isDefined() ? hostsAttribute.asList() : Collections.<ModelNode>emptyList();

authorizer.removeScopedRole(roleName);
constraintMap.remove(roleName);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,12 +70,14 @@ private void applyChangeToConstraint(final ModelNode operation, final ModelNode
// null means the resource shouldn't exist and we should have failed in Stage.MODEL
assert constraint != null : "unknown role " + roleName;

List<String> serverGroups = new ArrayList<String>();
for (ModelNode group : resolvedValue.asList()) {
serverGroups.add(group.asString());
List<String> hosts = new ArrayList<String>();
if (resolvedValue.isDefined()) {
for (ModelNode host : resolvedValue.asList()) {
hosts.add(host.asString());
}
}

constraint.setAllowedHosts(serverGroups);
constraint.setAllowedHosts(hosts);
}


Expand Down

0 comments on commit 3124219

Please sign in to comment.