Java Code Examples for org.jboss.dmr.Property#getName()

The following examples show how to use org.jboss.dmr.Property#getName() . 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: Address.java    From hawkular-agent with Apache License 2.0 6 votes vote down vote up
/**
 * Obtains the address from the given ModelNode which is assumed to be a property list that
 * contains all the address parts and only the address parts.
 *
 * @param node address node
 * @return the address
 */
public static Address fromModelNode(ModelNode node) {
    // Rather than just store node as this.addressNode, we want to make sure it can be used as a valid address.
    // This also builds our own instance of ModelNode rather than use the one the caller gave us.
    Address address = Address.root();

    // if the node is not defined, this simply represents the root address
    if (!node.isDefined()) {
        return address;
    }

    try {
        List<Property> addressList = node.asPropertyList();
        for (Property addressProperty : addressList) {
            String resourceType = addressProperty.getName();
            String resourceName = addressProperty.getValue().asString();
            address.add(resourceType, resourceName);
        }
        return address;
    } catch (Exception e) {
        throw new IllegalArgumentException("Node cannot be used as an address: " + node.toJSONString(true));
    }
}
 
Example 2
Source File: DomainServerUtils.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
public static Set<ServerIdentity> getServersForGroup(String groupName, ModelNode hostModel, final String localHostName, final Map<String, ProxyController> serverProxies) {
    Set<ServerIdentity> result;
    if (hostModel.hasDefined(SERVER_CONFIG)) {
        result = new HashSet<ServerIdentity>();
        for (Property prop : hostModel.get(SERVER_CONFIG).asPropertyList()) {
            String serverName = prop.getName();
            if (serverProxies.get(serverName) == null) {
                continue;
            }
            ModelNode server = prop.getValue();
            String serverGroupName = server.require(GROUP).asString();
            if (groupName != null && !groupName.equals(serverGroupName)) {
                continue;
            }
            ServerIdentity groupedServer = new ServerIdentity(localHostName, serverGroupName, serverName);
            result.add(groupedServer);
        }
    } else {
        result = Collections.emptySet();
    }
    return result;
}
 
Example 3
Source File: HostControllerRegistrationHandler.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
/**
 * Create the transformers. This will remotely resolve the subsystem versions.
 *
 * @param extensions the extensions
 * @throws OperationFailedException
 */
private void processSubsystems(final Transformers transformers, final ModelNode extensions) throws OperationFailedException {
    this.transformers = transformers;
    final ModelNode subsystems = executeBlocking(new IOTask<ModelNode>() {
        @Override
        void sendMessage(FlushableDataOutput output) throws IOException {
            sendResponse(output, DomainControllerProtocol.PARAM_OK, extensions);
        }
    });
    if(failed) {
        throw new OperationFailedException("failed to setup transformers");
    }
    final TransformationTarget target = transformers.getTarget();
    for(final Property subsystem : subsystems.asPropertyList()) {
        final String subsystemName = subsystem.getName();
        final ModelNode version = subsystem.getValue();
        target.addSubsystemVersion(subsystemName, ModelVersion.fromString(version.asString()));
    }
}
 
Example 4
Source File: ServerOperationResolver.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
private Map<Set<ServerIdentity>, ModelNode> getJVMRestartOperations(final PathAddress address, final ModelNode hostModel) {
    // See which servers are affected by this JVM change
    final String pathName = address.getElement(0).getValue();
    final Map<Set<ServerIdentity>, ModelNode> result;
    if (hostModel.hasDefined(SERVER_CONFIG)) {
        final Set<ServerIdentity> servers = new HashSet<ServerIdentity>();
        for (Property prop : hostModel.get(SERVER_CONFIG).asPropertyList()) {
            final String serverName = prop.getName();
            if (serverProxies.get(serverName) == null) {
                // No running server
                continue;
            }
            final ModelNode server = prop.getValue();
            if (server.hasDefined(JVM) && server.get(JVM).keys().contains(pathName)) {
                final String serverGroupName = server.require(GROUP).asString();
                final ServerIdentity groupedServer = new ServerIdentity(localHostName, serverGroupName, serverName);
                servers.add(groupedServer);
            }
        }
        result = getServerRestartRequiredOperations(servers);
    } else {
        result = Collections.emptyMap();
    }
    return result;
}
 
Example 5
Source File: CoreJBossASClient.java    From hawkular-agent with Apache License 2.0 6 votes vote down vote up
/**
 * This returns the system properties that are set in the AS JVM. This is not the system properties
 * in the JVM of this client object - it is actually the system properties in the remote
 * JVM of the AS instance that the client is talking to.
 *
 * @return the AS JVM's system properties
 * @throws Exception any error
 */
public Properties getSystemProperties() throws Exception {
    final String[] address = { CORE_SERVICE, PLATFORM_MBEAN, "type", "runtime" };
    final ModelNode op = createReadAttributeRequest(true, "system-properties", Address.root().add(address));
    final ModelNode results = execute(op);
    if (isSuccess(results)) {
        // extract the DMR representation into a java Properties object
        final Properties sysprops = new Properties();
        final ModelNode node = getResults(results);
        final List<Property> propertyList = node.asPropertyList();
        for (Property property : propertyList) {
            final String name = property.getName();
            final ModelNode value = property.getValue();
            if (name != null) {
                sysprops.put(name, value != null ? value.asString() : "");
            }
        }
        return sysprops;
    } else {
        throw new FailureException(results, "Failed to get system properties");
    }
}
 
Example 6
Source File: ReadFeatureDescriptionTestCase.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
private static int validateFeature(ModelNode feature, String expectedName, int maxChildDepth, int featureDepth) {
    int highestDepth = featureDepth;
    for (Property prop : feature.asPropertyList()) {
        switch (prop.getName()) {
            case NAME:
                if (expectedName != null) {
                    Assert.assertEquals(feature.toString(), expectedName, prop.getValue().asString());
                }
                break;
            case CHILDREN:
                if (prop.getValue().isDefined()) {
                    Assert.assertTrue(feature.toString(), maxChildDepth > 0);
                    for (Property child : prop.getValue().asPropertyList()) {
                        int treeDepth = validateFeature(child.getValue(), child.getName(),
                                maxChildDepth - 1, featureDepth + 1);
                        highestDepth = Math.max(highestDepth, treeDepth);
                    }
                }
                break;
            case ANNOTATION:
            case "params":
            case "refs":
            case "provides":
            case "requires":
            case "packages":
                // all ok; no other validation right now
                break;
            default:
                Assert.fail("Unknown key " + prop.getName() + " in " + feature.toString());
        }
    }
    return highestDepth;
}
 
Example 7
Source File: ParsedInterfaceCriteria.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
private static InterfaceCriteria parseNested(final ModelNode subModel, final boolean any,
                                             final ExpressionResolver expressionResolver) throws OperationFailedException {
    if(!subModel.isDefined() || subModel.asInt() == 0) {
        return null;
    }
    final Set<InterfaceCriteria> criteriaSet = new LinkedHashSet<InterfaceCriteria>();
    for(final Property nestedProperty :  subModel.asPropertyList()) {
        final Element element = Element.forName(nestedProperty.getName());
        switch (element) {
            case INET_ADDRESS:
            case NIC :
            case NIC_MATCH:
            case SUBNET_MATCH: {
                if (nestedProperty.getValue().getType() == ModelType.LIST) {
                    for (ModelNode item : nestedProperty.getValue().asList()) {
                        Property prop = new Property(nestedProperty.getName(), item);
                        InterfaceCriteria itemCriteria = parseCriteria(prop, true, expressionResolver);
                        if(itemCriteria != null) {
                            criteriaSet.add(itemCriteria);
                        }
                    }
                    break;
                } // else drop down into default: block
            }
            default: {
                final InterfaceCriteria criteria = parseCriteria(nestedProperty, true, expressionResolver);
                if(criteria != null) {
                    criteriaSet.add(criteria);
                }
            }
        }
    }
    if(criteriaSet.isEmpty()) {
        return null;
    }
    return any ? new AnyInterfaceCriteria(criteriaSet) : new NotInterfaceCriteria(criteriaSet);
}
 
Example 8
Source File: TransformerRegistry.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
public static Map<PathAddress, ModelVersion> resolveVersions(final ModelNode subsystems) {
    final PathAddress base = PathAddress.EMPTY_ADDRESS;
    final Map<PathAddress, ModelVersion> versions = new HashMap<PathAddress, ModelVersion>();
    for(final Property property : subsystems.asPropertyList()) {
        final String name = property.getName();
        final PathAddress address = base.append(PathElement.pathElement(ModelDescriptionConstants.SUBSYSTEM, name));
        versions.put(address, ModelVersion.fromString(property.getValue().asString()));
    }
    return versions;
}
 
Example 9
Source File: LoggingSubsystemWriter.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Override
public void writeContent(final XMLExtendedStreamWriter writer, final SubsystemMarshallingContext context) throws XMLStreamException {
    context.startSubsystemElement(Namespace.CURRENT.getUriString(), false);

    ModelNode model = context.getModelNode();

    // Marshall attributes
    for (AttributeDefinition attribute : LoggingResourceDefinition.ATTRIBUTES) {
        attribute.marshallAsElement(model, false, writer);
    }

    writeContent(writer, model);

    if (model.hasDefined(LOGGING_PROFILE)) {
        final List<Property> profiles = model.get(LOGGING_PROFILE).asPropertyList();
        if (!profiles.isEmpty()) {
            writer.writeStartElement(LOGGING_PROFILES);
            for (Property profile : profiles) {
                final String name = profile.getName();
                writer.writeStartElement(LOGGING_PROFILE);
                writer.writeAttribute(Attribute.NAME.getLocalName(), name);
                writeContent(writer, profile.getValue());
                writer.writeEndElement();
            }
            writer.writeEndElement();
        }
    }
    writer.writeEndElement();
}
 
Example 10
Source File: OperationCancellationTestCase.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
private String findActiveOperation(DomainClient client, PathAddress address, String opName) throws Exception {
    ModelNode op = Util.createEmptyOperation(READ_CHILDREN_RESOURCES_OPERATION, address);
    op.get(CHILD_TYPE).set(ACTIVE_OPERATION);
    ModelNode result = executeForResult(op, client);
    if (result.isDefined()) {
        assertEquals(result.asString(), ModelType.OBJECT, result.getType());
        for (Property prop : result.asPropertyList()) {
            if (prop.getValue().get(OP).asString().equals(opName)) {
                return prop.getName();
            }
        }
    }
    return null;
}
 
Example 11
Source File: ServerOperationResolver.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
private Map<Set<ServerIdentity>, ModelNode> getServerInterfaceOperations(ModelNode operation, PathAddress address,
                                                                         ModelNode hostModel, boolean forDomain) {
    String pathName = address.getElement(0).getValue();
    Map<Set<ServerIdentity>, ModelNode> result;
    if (forDomain && hostModel.hasDefined(INTERFACE) && hostModel.get(INTERFACE).keys().contains(pathName)) {
        // Host will take precedence; ignore the domain
        result = Collections.emptyMap();
    } else if (forDomain && ADD.equals(operation.get(OP).asString()) && !InterfaceDefinition.isOperationDefined(operation)) {
        // don't create named interfaces
        result = Collections.emptyMap();
    } else if (hostModel.hasDefined(SERVER_CONFIG)) {
        Set<ServerIdentity> servers = new HashSet<ServerIdentity>();
        for (Property prop : hostModel.get(SERVER_CONFIG).asPropertyList()) {

            String serverName = prop.getName();
            if (serverProxies.get(serverName) == null) {
                continue;
            }

            ModelNode server = prop.getValue();

            String serverGroupName = server.require(GROUP).asString();

            if (server.hasDefined(INTERFACE) && server.get(INTERFACE).keys().contains(pathName)) {
                // Server takes precedence; ignore domain
                continue;
            }

            ServerIdentity groupedServer = new ServerIdentity(localHostName, serverGroupName, serverName);
            servers.add(groupedServer);
        }

        ModelNode serverOp = operation.clone();
        serverOp.get(OP_ADDR).setEmptyList().add(INTERFACE, pathName);
        result = Collections.singletonMap(servers, serverOp);
    } else {
        result = Collections.emptyMap();
    }
    return result;
}
 
Example 12
Source File: OperationErrorTestCase.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
private String findActiveOperation(DomainClient client, PathAddress address, String opName) throws Exception {
    ModelNode op = Util.createEmptyOperation(READ_CHILDREN_RESOURCES_OPERATION, address);
    op.get(CHILD_TYPE).set(ACTIVE_OPERATION);
    ModelNode result = executeForResponse(op, client).get(RESULT);
    if (result.isDefined()) {
        assertEquals(result.asString(), ModelType.OBJECT, result.getType());
        for (Property prop : result.asPropertyList()) {
            if (prop.getValue().get(OP).asString().equals(opName)) {
                return prop.getName();
            }
        }
    }
    return null;
}
 
Example 13
Source File: SecurityRealmAddHandler.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
private Map<String, ExceptionSupplier<CredentialSource, Exception>> unmaskUsersCredentials(OperationContext context, ServiceBuilder<?> serviceBuilder, ModelNode users) throws OperationFailedException {
    Map<String, ExceptionSupplier<CredentialSource, Exception>> suppliers = new HashMap<>();
    for (Property property : users.get(USER).asPropertyList()) {
        // Don't use the value from property as it is a clone and does not update the returned users ModelNode.
        ModelNode user = users.get(USER, property.getName());
        if (user.hasDefined(CredentialReference.CREDENTIAL_REFERENCE)) {
            String keySuffix = AUTHENTICATION + KEY_DELIMITER + USERS + KEY_DELIMITER + USER + KEY_DELIMITER + property.getName();
            suppliers.put(property.getName(), CredentialReference.getCredentialSourceSupplier(context, UserResourceDefinition.CREDENTIAL_REFERENCE, user, serviceBuilder, keySuffix));
        }
    }
    return suppliers;
}
 
Example 14
Source File: ResourceCompositeOperationHandler.java    From wildfly-core with GNU Lesser General Public License v2.1 4 votes vote down vote up
protected Map<String, ArgumentWithValue> getOperationArguments(CommandContext ctx, String opName) throws CommandLineException {
    Map<String, ArgumentWithValue> args = opArgs.get(opName);
    if(args != null) {
        return args;
    }

    final ModelNode descr = getOperationDescription(ctx, opName);
    if(descr.has(Util.REQUEST_PROPERTIES)) {
        args = new HashMap<String,ArgumentWithValue>();
        final List<Property> propList = descr.get(Util.REQUEST_PROPERTIES).asPropertyList();
        for (Property prop : propList) {
            CommandLineCompleter valueCompleter = null;
            ArgumentValueConverter valueConverter = null;
            if(propConverters != null) {
                valueConverter = propConverters.get(prop.getName());
            }
            if(valueCompleters != null) {
                valueCompleter = valueCompleters.get(prop.getName());
            }
            if(valueConverter == null) {
                valueConverter = ArgumentValueConverter.DEFAULT;
                final ModelType propType = getType(prop.getValue());
                if(propType != null) {
                    if(ModelType.BOOLEAN == propType) {
                        if(valueCompleter == null) {
                            valueCompleter = SimpleTabCompleter.BOOLEAN;
                        }
                    } else if(ModelType.STRING == propType) {
                        valueConverter = ArgumentValueConverter.NON_OBJECT;
                    } else if(prop.getName().endsWith("properties")) { // TODO this is bad but can't rely on proper descriptions
                        valueConverter = ArgumentValueConverter.PROPERTIES;
                    } else if(ModelType.LIST == propType) {
                        if(asType(descr.get(Util.VALUE_TYPE)) == ModelType.PROPERTY) {
                            valueConverter = ArgumentValueConverter.PROPERTIES;
                        } else {
                            valueConverter = ArgumentValueConverter.LIST;
                        }
                    }
                }
            }
            final ArgumentWithValue arg = new ArgumentWithValue(ResourceCompositeOperationHandler.this, valueCompleter, valueConverter, "--" + prop.getName());
            args.put(arg.getFullName(), arg);
        }
    } else {
        args = Collections.emptyMap();
    }
    opArgs.put(opName, args);
    return args;
}
 
Example 15
Source File: QueryOperationHandler.java    From wildfly-core with GNU Lesser General Public License v2.1 4 votes vote down vote up
private static boolean matchesFilter(final ModelNode resource, final ModelNode filter, final Operator operator) throws OperationFailedException {
    boolean isMatching = false;
    List<Property> filterProperties = filter.asPropertyList();
    List<Boolean> matches = new ArrayList<>(filterProperties.size());

    for (Property property : filterProperties) {

        final String filterName = property.getName();
        final ModelNode filterValue = property.getValue();

        boolean isEqual = false;

        if(!filterValue.isDefined() || filterValue.asString().equals(UNDEFINED))  {
            // query for undefined attributes
            isEqual = !resource.get(filterName).isDefined();
        }  else {

            final ModelType targetValueType = resource.get(filterName).getType();

            try {
                // query for attribute values (throws exception when types don't match)
                switch (targetValueType) {
                    case BOOLEAN:
                        isEqual = filterValue.asBoolean() == resource.get(filterName).asBoolean();
                        break;
                    case LONG:
                        isEqual = filterValue.asLong() == resource.get(filterName).asLong();
                        break;
                    case INT:
                        isEqual = filterValue.asInt() == resource.get(filterName).asInt();
                        break;
                    case DOUBLE:
                        isEqual = filterValue.asDouble() == resource.get(filterName).asDouble();
                        break;
                    default:
                        isEqual = filterValue.equals(resource.get(filterName));
                }
            } catch (IllegalArgumentException e) {
                throw ControllerLogger.MGMT_OP_LOGGER.selectFailedCouldNotConvertAttributeToType(filterName, targetValueType);
            }

        }

        if(isEqual) {
            matches.add(resource.get(filterName).equals(filterValue));
        }

    }

    if (Operator.AND.equals(operator)) {
        // all matches must be true
        isMatching = matches.size() == filterProperties.size();

    } else if(Operator.OR.equals(operator)){
        // at least one match must be true
        for (Boolean match : matches) {
            if (match) {
                isMatching = true;
                break;
            }
        }
    }
    else {
        // This is just to catch programming errors where a new case isn't added above
        throw new IllegalArgumentException(
                ControllerLogger.MGMT_OP_LOGGER.invalidValue(
                        operator.toString(),
                        OPERATOR,
                        Arrays.asList(Operator.values())
                )
        );
    }


    return isMatching;
}
 
Example 16
Source File: OperationCancellationTestCase.java    From wildfly-core with GNU Lesser General Public License v2.1 4 votes vote down vote up
private String findActiveOperation(DomainClient client, PathAddress address, String opName, OperationContext.ExecutionStatus targetStatus, long executionStart, boolean serverOpOnly) throws Exception {
    ModelNode op = Util.createEmptyOperation(READ_CHILDREN_RESOURCES_OPERATION, address);
    op.get(CHILD_TYPE).set(ACTIVE_OPERATION);
    long maxTime = TimeoutUtil.adjust(5000);
    long timeout = executionStart + maxTime;
    List<String> activeOps = new ArrayList<String>();
    String opToCancel = null;
    do {
        activeOps.clear();
        ModelNode result = executeForResult(op, client);
        if (result.isDefined()) {
            assertEquals(result.asString(), ModelType.OBJECT, result.getType());
            for (Property prop : result.asPropertyList()) {
                if (prop.getValue().get(OP).asString().equals(opName)) {
                    PathAddress pa = PathAddress.pathAddress(prop.getValue().get(OP_ADDR));
                    if (!serverOpOnly || pa.size() > 2 && pa.getElement(1).getKey().equals(SERVER)) {
                        if (targetStatus == null || prop.getValue().get(EXECUTION_STATUS).asString().equals(targetStatus.toString())) {
                            if (targetStatus != null && opToCancel == null) {
                                // Ignore the fact there were other ops with a different status
                                activeOps.clear();
                            }
                            opToCancel = prop.getName();
                        } else {
                            // Ignore the fact there were other ops with a different status
                            activeOps.clear();
                        }
                        activeOps.add(prop.getName() + " -- " + prop.getValue().toString());
                    }
                }
            }
        }
        if (opToCancel == null) {
            Thread.sleep(50);
        }

    } while ((opToCancel == null || activeOps.size() > 1) && System.currentTimeMillis() <= timeout);

    assertTrue(opName + " not present after " + maxTime + " ms", activeOps.size() > 0);
    assertEquals("Multiple instances of " + opName + " present: " + activeOps, 1, activeOps.size());
    assertNotNull(opName + " not in status " + targetStatus + " after " + maxTime + " ms", opToCancel);

    return opToCancel;
}
 
Example 17
Source File: ManagedServerOperationsFactory.java    From wildfly-core with GNU Lesser General Public License v2.1 4 votes vote down vote up
private void addDeployments(List<ModelNode> updates) {
    if (serverGroup.hasDefined(DEPLOYMENT)) {

        HostFileRepository remoteRepository = null;
        if (!domainController.getLocalHostInfo().isMasterDomainController()) {
            remoteRepository = domainController.getRemoteFileRepository();
        }

        for (Property deployment : serverGroup.get(DEPLOYMENT).asPropertyList()) {
            String name = deployment.getName();
            ModelNode details = deployment.getValue();

            ModelNode domainDeployment = domainModel.require(DEPLOYMENT).require(name);
            ModelNode deploymentContent = domainDeployment.require(CONTENT).clone();
            PathAddress addr = PathAddress.pathAddress(PathElement.pathElement(DEPLOYMENT, name));
            if (remoteRepository != null) {
                // Make sure we have a copy of the deployment in the local repo
                for (ModelNode content : deploymentContent.asList()) {
                    if ((content.hasDefined(HASH))) {
                        byte[] hash = content.require(HASH).asBytes();
                        ContentReference reference = ModelContentReference.fromModelAddress(addr, hash);
                        File[] files = domainController.getLocalFileRepository().getDeploymentFiles(reference);
                        if (files == null || files.length == 0) {
                            remoteRepository.getDeploymentFiles(reference);
                        }
                    }
                }
            }

            ModelNode addOp = Util.getEmptyOperation(ADD, addr.toModelNode());
            addOp.get(RUNTIME_NAME).set(details.get(RUNTIME_NAME));
            addOp.get(CONTENT).set(deploymentContent);
            if (!details.hasDefined(ENABLED)) {
                addOp.get(ENABLED).set(true);  // TODO this seems wrong
            } else {
                addOp.get(ENABLED).set(details.get(ENABLED));
            }

            updates.add(addOp);
        }
    }
}
 
Example 18
Source File: CompositeOperationTestCase.java    From wildfly-core with GNU Lesser General Public License v2.1 4 votes vote down vote up
private static void validateRRDResponse(ModelNode response, int stepCount) {

        String responseString = response.toString();
        assertEquals(responseString, SUCCESS, response.get(OUTCOME).asString());
        assertTrue(responseString, response.hasDefined(RESULT));
        ModelNode result = response.get(RESULT);
        assertEquals(responseString, ModelType.OBJECT, result.getType());
        List<Property> list = result.asPropertyList();
        assertEquals(responseString, stepCount, list.size());
        for (Property prop : list) {
            ModelNode stepResp = prop.getValue();
            assertEquals(responseString, SUCCESS, stepResp.get(OUTCOME).asString());
            assertTrue(responseString, stepResp.hasDefined(RESULT, ATTRIBUTES));
            ModelNode stepResult = stepResp.get(RESULT);
            Set<String> keys = stepResult.get(ATTRIBUTES).keys();
            assertTrue(responseString, keys.contains("launch-type"));
            assertTrue(responseString, keys.contains("server-state"));
            assertTrue(responseString, keys.contains("runtime-configuration-state"));
            assertTrue(responseString, stepResult.hasDefined(ACCESS_CONTROL, "default", ATTRIBUTES));
            Set<String> accessKeys = stepResult.get(ACCESS_CONTROL, "default", ATTRIBUTES).keys();
            assertTrue(responseString, accessKeys.contains("launch-type"));
            assertTrue(responseString, accessKeys.contains("server-state"));
            assertTrue(responseString, accessKeys.contains("runtime-configuration-state"));

            assertTrue(responseString, stepResult.hasDefined(ACCESS_CONTROL, EXCEPTIONS));
            assertEquals(responseString, 0, stepResult.get(ACCESS_CONTROL, EXCEPTIONS).asInt());

            switch (prop.getName()) {
                case "step-1":
                case "step-2":
                    assertEquals(responseString, 3, keys.size());
                    assertEquals(responseString, 3, accessKeys.size());
                    break;
                case "step-3":
                case "step-4":
                    assertTrue(responseString, keys.size() > 2);
                    assertEquals(responseString, keys.size(), accessKeys.size());
                    break;
                default:
                    fail(responseString);
            }
        }

    }
 
Example 19
Source File: SecurityRealmAddHandler.java    From wildfly-core with GNU Lesser General Public License v2.1 4 votes vote down vote up
private Supplier<KeytabIdentityFactoryService> addKerberosIdentityServices(OperationContext context, ModelNode kerberos, String realmName, ServiceTarget serviceTarget,
    ServiceBuilder<?> realmBuilder) throws OperationFailedException {
    ServiceName keyIdentityName = KeytabIdentityFactoryService.ServiceUtil.createServiceName(realmName);
    final ServiceBuilder<?> kifsBuilder = serviceTarget.addService(keyIdentityName);
    final Consumer<KeytabIdentityFactoryService> kifsConsumer = kifsBuilder.provides(keyIdentityName);
    final KeytabIdentityFactoryService kifs = new KeytabIdentityFactoryService(kifsConsumer);
    kifsBuilder.setInstance(kifs);
    kifsBuilder.setInitialMode(ON_DEMAND);

    if (kerberos.hasDefined(KEYTAB)) {
        List<Property> keytabList = kerberos.get(KEYTAB).asPropertyList();
        for (Property current : keytabList) {
            String principal = current.getName();
            ModelNode keytab = current.getValue();
            String path = KeytabResourceDefinition.PATH.resolveModelAttribute(context, keytab).asString();
            ModelNode relativeToNode = KeytabResourceDefinition.RELATIVE_TO.resolveModelAttribute(context, keytab);
            String relativeTo = relativeToNode.isDefined() ? relativeToNode.asString() : null;
            boolean debug = KeytabResourceDefinition.DEBUG.resolveModelAttribute(context, keytab).asBoolean();
            final String[] forHostsValues;
            ModelNode forHosts = KeytabResourceDefinition.FOR_HOSTS.resolveModelAttribute(context, keytab);
            if (forHosts.isDefined()) {
                List<ModelNode> list = forHosts.asList();
                forHostsValues = new String[list.size()];
                for (int i=0;i<list.size();i++) {
                    forHostsValues[i] = list.get(i).asString();
                }
            } else {
                forHostsValues = new String[0];
            }

            ServiceName keytabName = KeytabService.ServiceUtil.createServiceName(realmName, principal);

            final ServiceBuilder<?> keytabBuilder = serviceTarget.addService(keytabName);
            final Consumer<KeytabService> ksConsumer = keytabBuilder.provides(keytabName);
            Supplier<PathManager> pathManagerSupplier = null;

            if (relativeTo != null) {
                pathManagerSupplier = keytabBuilder.requires(context.getCapabilityServiceName(PATH_MANAGER_CAPABILITY, PathManager.class));
                keytabBuilder.requires(pathName(relativeTo));
            }
            keytabBuilder.setInstance(new KeytabService(ksConsumer, pathManagerSupplier, principal, path, relativeTo, forHostsValues, debug));
            keytabBuilder.setInitialMode(ON_DEMAND);
            keytabBuilder.install();
            kifs.addKeytabSupplier(KeytabService.ServiceUtil.requires(kifsBuilder, realmName, principal));
         }
     }

     kifsBuilder.install();

     return KeytabIdentityFactoryService.ServiceUtil.requires(realmBuilder, realmName);
}
 
Example 20
Source File: Address.java    From hawkular-agent with Apache License 2.0 3 votes vote down vote up
/**
 * Returns the address as a flattened string that is compatible with
 * the DMR CLI address paths.
 *
 * For example, an Address whose ModelNode representation is:
 *
 *    [
 *     ("one" =&gt; "two"),
 *     ("three" =&gt; "four")
 *    ]
 *
 * will have a flat string of
 *
 *    /one=two/three=four
 *
 * @return flattened address path string
 */
public String toAddressPathString() {
    if (isRoot()) {
        return "/";
    }

    StringBuilder str = new StringBuilder();
    List<Property> parts = addressNode.asPropertyList();
    for (Property part : parts) {
        String name = part.getName();
        String value = part.getValue().asString();
        str.append("/").append(name).append("=").append(value);
    }
    return str.toString();
}