Java Code Examples for org.jboss.as.controller.registry.Resource#getChildrenNames()

The following examples show how to use org.jboss.as.controller.registry.Resource#getChildrenNames() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: RbacSanityCheckOperation.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
boolean doRoleMappingsExist() throws OperationFailedException {
    Resource authorizationResource = managementResource.getChild(PathElement.pathElement(ACCESS, AUTHORIZATION));
    Set<String> roleNames = authorizationResource.getChildrenNames(ROLE_MAPPING);
    for (String current : roleNames) {
        Resource roleResource = authorizationResource.getChild(PathElement.pathElement(ROLE_MAPPING, current));
        ModelNode roleModel = roleResource.getModel();
        if (roleModel.get(INCLUDE_ALL).isDefined() && roleModel.require(INCLUDE_ALL).asBoolean()) {
            return true;
        }

        if (roleResource.getChildren(INCLUDE).size() > 0) {
            return true;
        }
    }

    return false;
}
 
Example 2
Source File: GlobalInstallationReportHandler.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
public static OperationStepHandler createDomainOperation() {
    return new OperationStepHandler() {
        @Override
        public void execute(OperationContext context, ModelNode operation) throws OperationFailedException {
            Resource res = context.readResourceFromRoot(PathAddress.EMPTY_ADDRESS,false);
            Set<String> hosts = res.getChildrenNames(HOST);
            String hostName = hosts.iterator().next();
            PathAddress address = PathAddress.pathAddress(PathElement.pathElement(HOST));
            //Hacky part we are getting the handler from a real host and calling the operation on /host=*
            OperationEntry entry = context.getRootResourceRegistration().getOperationEntry(PathAddress.pathAddress(PathElement.pathElement(HOST, hostName)), OPERATION_NAME);
            ModelNode reportOperation = Util.getEmptyOperation(OPERATION_NAME, address.toModelNode());
            if (operation.hasDefined(CREATE_REPORT_DEFINITION.getName())) {
                reportOperation.get(CREATE_REPORT_DEFINITION.getName()).set(operation.get(CREATE_REPORT_DEFINITION.getName()));
                if (operation.hasDefined(FILE_FORMAT_DEFINITION.getName())) {
                    reportOperation.get(FILE_FORMAT_DEFINITION.getName()).set(operation.get(FILE_FORMAT_DEFINITION.getName()));
                }
            }
            if (entry != null) {
                OperationStepHandler osh = entry.getOperationHandler();
                context.addStep(reportOperation, osh, OperationContext.Stage.MODEL);
            }
        }
    };
}
 
Example 3
Source File: AuthenticationValidatingHandler.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Override
public void execute(OperationContext context, ModelNode operation) throws OperationFailedException {
    String realmName = PathAddress.pathAddress(operation.require(ModelDescriptionConstants.OP_ADDR)).getLastElement().getValue();
    if(!hasResource(context)) {//realm has been deleted, who cares :)
        return;
    }
    final Resource resource = context.readResource(PathAddress.EMPTY_ADDRESS);
    Set<String> children = resource.getChildrenNames(ModelDescriptionConstants.AUTHENTICATION);

    if (children.contains(KERBEROS)) {
        Resource kerberosIdentity = resource.getChild(PathElement.pathElement(SERVER_IDENTITY, KERBEROS));
        if (kerberosIdentity == null || kerberosIdentity.getChildrenNames(KEYTAB).size() < 1) {
            throw DomainManagementLogger.ROOT_LOGGER.kerberosWithoutKeytab(realmName);
        }
    }

    /*
     * Truststore, Local, and Kerberos can be defined in addition to the username/password mechanism so exclude these from the
     * validation check.
     */
    children.remove(ModelDescriptionConstants.TRUSTSTORE);
    children.remove(ModelDescriptionConstants.LOCAL);
    children.remove(KERBEROS);
    if (children.size() > 1) {
        Set<String> invalid = new HashSet<String>(children);
        invalid.remove(ModelDescriptionConstants.TRUSTSTORE);
        throw DomainManagementLogger.ROOT_LOGGER.multipleAuthenticationMechanismsDefined(realmName, invalid);
    }
    context.completeStep(OperationContext.RollbackHandler.NOOP_ROLLBACK_HANDLER);
}
 
Example 4
Source File: LdapCacheResourceDefinition.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Override
public void execute(OperationContext context, ModelNode operation) throws OperationFailedException {
    final Resource resource = context.readResource(PathAddress.EMPTY_ADDRESS);
    Set<String> children = resource.getChildrenNames(ModelDescriptionConstants.CACHE);
    if (children.size() > 1) {
        String realmName = ManagementUtil.getSecurityRealmName(operation);
        throw DomainManagementLogger.ROOT_LOGGER.multipleCacheConfigurationsDefined(realmName);
    }

}
 
Example 5
Source File: AuthorizationValidatingHandler.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Override
public void execute(OperationContext context, ModelNode operation) throws OperationFailedException {
    final Resource resource = context.readResource(PathAddress.EMPTY_ADDRESS);
    Set<String> children = resource.getChildrenNames(ModelDescriptionConstants.AUTHORIZATION);
    if (children.size() > 1) {
        String realmName = PathAddress.pathAddress(operation.require(ModelDescriptionConstants.OP_ADDR)).getLastElement().getValue();
        Set<String> invalid = new HashSet<String>(children);
        throw DomainManagementLogger.ROOT_LOGGER.multipleAuthorizationConfigurationsDefined(realmName, invalid);
    }
}
 
Example 6
Source File: ScopedRoleRequiredHandler.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Override
public void execute(OperationContext context, ModelNode operation) throws OperationFailedException {
    Resource resource = context.readResource(PathAddress.EMPTY_ADDRESS);
    Set<String> hostScopedRoles = resource.getChildrenNames(HOST_SCOPED_ROLE);
    Set<String> serverGroupScopedRoles = resource.getChildrenNames(SERVER_GROUP_SCOPED_ROLE);

    if (hostScopedRoles.contains(roleName) == false && serverGroupScopedRoles.contains(roleName) == false) {
        throw DomainManagementLogger.ROOT_LOGGER.invalidRoleNameDomain(roleName);
    }
}
 
Example 7
Source File: RoleMappingNotRequiredHandler.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Override
public void execute(OperationContext context, ModelNode operation) throws OperationFailedException {
    Resource resource = context.readResource(PathAddress.EMPTY_ADDRESS);
    Set<String> roleMappings = resource.getChildrenNames(ROLE_MAPPING);

    if (roleMappings.contains(roleName)) {
        throw DomainManagementLogger.ROOT_LOGGER.roleMappingRemaining(roleName);
    }
}
 
Example 8
Source File: GenericSubsystemDescribeHandler.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
protected void describe(final OrderedChildTypesAttachment orderedChildTypesAttachment, final Resource resource,
                        final ModelNode address, ModelNode result, final ImmutableManagementResourceRegistration registration) {
    if(resource == null || registration.isRemote() || registration.isRuntimeOnly() || resource.isProxy() || resource.isRuntime() || registration.isAlias()) {
        return;
    }

    final Set<PathElement> children;
    final Set<PathElement> defaultChildren = new LinkedHashSet<>();
    for (String type : resource.getChildTypes()) {
        for (String value : resource.getChildrenNames(type)) {
            defaultChildren.add(PathElement.pathElement(type, value));
        }
    }
    if (comparator == null) {
        children = defaultChildren;
    } else {
        children = new TreeSet<PathElement>(comparator);
        children.addAll(defaultChildren);
    }
    result.add(createAddOperation(orderedChildTypesAttachment, address, resource, children));
    for(final PathElement element : children) {
        final Resource child = resource.getChild(element);
        final ImmutableManagementResourceRegistration childRegistration = registration.getSubModel(PathAddress.pathAddress(element));
        if (childRegistration == null) {
            ControllerLogger.ROOT_LOGGER.debugf("No MRR exists for %s", registration.getPathAddress().append(element));
        } else {
            final ModelNode childAddress = address.clone();
            childAddress.add(element.getKey(), element.getValue());
            describe(orderedChildTypesAttachment, child, childAddress, result, childRegistration);
        }
    }
}
 
Example 9
Source File: AliasContextTestCase.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Override
public PathAddress convertToTargetAddress(PathAddress addr, AliasContext aliasContext) {
    final ModelNode op = aliasContext.getOperation();
    if (op.get(OP).asString().equals(ADD)) {
        return PathAddress.pathAddress(MAIN, op.get(TYPE.getName()).asString());
    }
    Resource root = aliasContext.readResourceFromRoot(PathAddress.EMPTY_ADDRESS);
    Set<String> names = root.getChildrenNames(MAIN);
    if (names.size() > 1) {
        throw new AssertionError("There should be at most one child");
    } else if (names.size() == 0) {
        return PathAddress.pathAddress(MAIN, "*");
    }
    return PathAddress.pathAddress(MAIN, names.iterator().next());
}
 
Example 10
Source File: AffectedDeploymentOverlay.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * Returns all the deployment runtime names associated with an overlay.
 *
 * @param context the current OperationContext.
 * @param overlayAddress the address for the averlay.
 * @return all the deployment runtime names associated with an overlay.
 */
public static Set<String> listLinks(OperationContext context, PathAddress overlayAddress) {
    Resource overlayResource = context.readResourceFromRoot(overlayAddress);
    if (overlayResource.hasChildren(DEPLOYMENT)) {
        return overlayResource.getChildrenNames(DEPLOYMENT);
    }
    return Collections.emptySet();
}
 
Example 11
Source File: AffectedDeploymentOverlay.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
private static Set<String> listServerGroupsReferencingOverlay(Resource rootResource, String overlayName) {
    final PathElement overlayPath = PathElement.pathElement(DEPLOYMENT_OVERLAY, overlayName);
    if (rootResource.hasChildren(SERVER_GROUP)) {
        Set<String> set = new HashSet<>();
        for (String serverGroupName : rootResource.getChildrenNames(SERVER_GROUP)) {
            if (rootResource.getChild(PathElement.pathElement(SERVER_GROUP, serverGroupName)).hasChild(overlayPath)) {
                set.add(serverGroupName);
            }
        }
        return set;
    }
    return Collections.emptySet();
}