Search in sources :

Example 91 with Property

use of org.jboss.dmr.Property in project wildfly by wildfly.

the class AbstractEntityProviderAddHandler method configureHandler.

protected static void configureHandler(OperationContext context, ModelNode model, EntityProviderService service) throws OperationFailedException {
    if (model.hasDefined(ModelElement.COMMON_HANDLER.getName())) {
        for (Property handlerProperty : model.get(ModelElement.COMMON_HANDLER.getName()).asPropertyList()) {
            ModelNode handler = handlerProperty.getValue();
            Handler newHandler = toHandlerConfig(context, handler);
            if (handler.hasDefined(COMMON_HANDLER_PARAMETER.getName())) {
                for (Property handlerParameter : handler.get(COMMON_HANDLER_PARAMETER.getName()).asPropertyList()) {
                    String paramName = handlerParameter.getName();
                    ModelNode parameterNode = handlerParameter.getValue();
                    KeyValueType kv = toHandlerParameterConfig(context, paramName, parameterNode);
                    newHandler.add(kv);
                }
            }
            service.addHandler(newHandler);
        }
    }
}
Also used : KeyValueType(org.picketlink.config.federation.KeyValueType) AbstractAddStepHandler(org.jboss.as.controller.AbstractAddStepHandler) Handler(org.picketlink.config.federation.handler.Handler) ModelNode(org.jboss.dmr.ModelNode) Property(org.jboss.dmr.Property)

Example 92 with Property

use of org.jboss.dmr.Property in project wildfly by wildfly.

the class LegacyPropertyWriteOperationTransformer method transformOperation.

@Override
public TransformedOperation transformOperation(TransformationContext context, PathAddress address, ModelNode operation) throws OperationFailedException {
    if (operation.get(NAME).asString().equals(PROPERTIES)) {
        InitialAttributeValueOperationContextAttachment attachment = context.getAttachment(InitialAttributeValueOperationContextAttachment.INITIAL_VALUES_ATTACHMENT);
        assert attachment != null;
        // Workaround aliases limitations!
        // we need to painstakingly undo path alias translations, since we need to know the address of the real resource,
        // since the readResourceFromRoot() will not work on the aliased address
        Map<String, String> undoAliases = new HashMap<>();
        undoAliases.put("BINARY_KEYED_JDBC_STORE", "binary-jdbc");
        undoAliases.put("STORE", "custom");
        undoAliases.put("FILE_STORE", "file");
        undoAliases.put("MIXED_KEYED_JDBC_STORE", "mixed-jdbc");
        undoAliases.put("REMOTE_STORE", "remote");
        undoAliases.put("STRING_KEYED_JDBC_STORE", "string-jdbc");
        if (undoAliases.containsKey(address.getLastElement().getValue())) {
            address = address.subAddress(0, address.size() - 1).append("store", undoAliases.get(address.getLastElement().getValue()));
        }
        ModelNode initialValue = attachment.getInitialValue(address, Operations.getAttributeName(operation));
        ModelNode newValue = context.readResourceFromRoot(address).getModel().get(PROPERTIES).clone();
        if (initialValue.equals(newValue) || (initialValue.isDefined() && initialValue.asPropertyList().isEmpty() && !newValue.isDefined())) {
            // There is nothing to do, discard this operation
            return new TransformedOperation(null, DEFAULT_REJECTION_POLICY, SUCCESSFUL_RESULT);
        }
        final Map<String, ModelNode> oldMap = new HashMap<>();
        if (initialValue.isDefined()) {
            for (Property property : initialValue.asPropertyList()) {
                oldMap.put(property.getName(), property.getValue());
            }
        }
        // Transformed address for all operations
        final PathAddress legacyAddress = Operations.getPathAddress(operation);
        // This may result as multiple operations on the legacy node
        final ModelNode composite = new ModelNode();
        composite.get(OP).set(COMPOSITE);
        composite.get(OP_ADDR).setEmptyList();
        if (newValue.isDefined()) {
            for (Property property : newValue.asPropertyList()) {
                String key = property.getName();
                ModelNode value = property.getValue();
                if (!oldMap.containsKey(key)) {
                    // This is a newly added property => :add operation
                    ModelNode addOp = Util.createAddOperation(legacyAddress.append(PathElement.pathElement(PROPERTY, key)));
                    addOp.get(VALUE).set(value);
                    composite.get(STEPS).add(addOp);
                } else {
                    final ModelNode oldPropValue = oldMap.get(key);
                    if (!oldPropValue.equals(value)) {
                        // Property value is different => :write-attribute operation
                        ModelNode writeOp = Util.getWriteAttributeOperation(legacyAddress.append(PathElement.pathElement(PROPERTY, key)), VALUE, value);
                        composite.get(STEPS).add(writeOp);
                    }
                    // Otherwise both property name and value are the same => no operation
                    // Remove this key
                    oldMap.remove(key);
                }
            }
        }
        // Properties that were removed = :remove operation
        for (Map.Entry<String, ModelNode> prop : oldMap.entrySet()) {
            ModelNode removeOperation = Util.createRemoveOperation(legacyAddress.append(PathElement.pathElement(PROPERTY, prop.getKey())));
            composite.get(STEPS).add(removeOperation);
        }
        initialValue.set(newValue.clone());
        return new TransformedOperation(composite, OperationResultTransformer.ORIGINAL_RESULT);
    }
    return new TransformedOperation(operation, OperationResultTransformer.ORIGINAL_RESULT);
}
Also used : HashMap(java.util.HashMap) PathAddress(org.jboss.as.controller.PathAddress) ModelNode(org.jboss.dmr.ModelNode) Property(org.jboss.dmr.Property) HashMap(java.util.HashMap) Map(java.util.Map)

Example 93 with Property

use of org.jboss.dmr.Property in project wildfly by wildfly.

the class SecurityDomainAdd method processIdentityTrust.

private boolean processIdentityTrust(OperationContext context, String securityDomain, ModelNode node, ApplicationPolicy applicationPolicy) throws OperationFailedException {
    node = peek(node, IDENTITY_TRUST, CLASSIC, TRUST_MODULE);
    if (node == null) {
        return false;
    }
    IdentityTrustInfo identityTrustInfo = new IdentityTrustInfo(securityDomain);
    for (Property moduleProperty : node.asPropertyList()) {
        ModelNode module = moduleProperty.getValue();
        String codeName = LoginModuleResourceDefinition.CODE.resolveModelAttribute(context, module).asString();
        String flag = LoginModuleResourceDefinition.FLAG.resolveModelAttribute(context, module).asString();
        ControlFlag controlFlag = ControlFlag.valueOf(flag);
        Map<String, Object> options = extractOptions(context, module);
        IdentityTrustModuleEntry entry = new IdentityTrustModuleEntry(codeName, options);
        entry.setControlFlag(controlFlag);
        identityTrustInfo.add(entry);
        ModelNode moduleName = LoginModuleResourceDefinition.MODULE.resolveModelAttribute(context, module);
        if (moduleName.isDefined() && !moduleName.asString().isEmpty()) {
            identityTrustInfo.addJBossModuleName(moduleName.asString());
        } else {
            identityTrustInfo.addJBossModuleName(DEFAULT_MODULE);
        }
    }
    applicationPolicy.setIdentityTrustInfo(identityTrustInfo);
    return true;
}
Also used : IdentityTrustModuleEntry(org.jboss.security.identitytrust.config.IdentityTrustModuleEntry) IdentityTrustInfo(org.jboss.security.config.IdentityTrustInfo) ModelNode(org.jboss.dmr.ModelNode) Property(org.jboss.dmr.Property) ControlFlag(org.jboss.security.config.ControlFlag) LoginModuleControlFlag(javax.security.auth.login.AppConfigurationEntry.LoginModuleControlFlag)

Example 94 with Property

use of org.jboss.dmr.Property in project wildfly by wildfly.

the class SecurityDomainAdd method processJASPIAuth.

private boolean processJASPIAuth(OperationContext context, String securityDomain, ModelNode node, ApplicationPolicy applicationPolicy) throws OperationFailedException {
    node = peek(node, AUTHENTICATION, JASPI);
    if (node == null) {
        return false;
    }
    JASPIAuthenticationInfo authenticationInfo = new JASPIAuthenticationInfo(securityDomain);
    Map<String, LoginModuleStackHolder> holders = new HashMap<String, LoginModuleStackHolder>();
    if (node.hasDefined(LOGIN_MODULE_STACK)) {
        List<Property> stacks = node.get(LOGIN_MODULE_STACK).asPropertyList();
        for (Property stack : stacks) {
            String name = stack.getName();
            ModelNode stackNode = stack.getValue();
            final LoginModuleStackHolder holder = new LoginModuleStackHolder(name, null);
            holders.put(name, holder);
            authenticationInfo.add(holder);
            if (stackNode.hasDefined(LOGIN_MODULE)) {
                processLoginModules(context, stackNode.get(LOGIN_MODULE), authenticationInfo, new LoginModuleContainer() {

                    public void addAppConfigurationEntry(AppConfigurationEntry entry) {
                        holder.addAppConfigurationEntry(entry);
                    }
                });
            }
        }
    }
    for (Property moduleProperty : node.get(AUTH_MODULE).asPropertyList()) {
        ModelNode authModule = moduleProperty.getValue();
        String code = extractCode(context, authModule, ModulesMap.AUTHENTICATION_MAP);
        String loginStackRef = null;
        if (authModule.hasDefined(LOGIN_MODULE_STACK_REF)) {
            loginStackRef = JASPIMappingModuleDefinition.LOGIN_MODULE_STACK_REF.resolveModelAttribute(context, authModule).asString();
        }
        Map<String, Object> options = extractOptions(context, authModule);
        AuthModuleEntry entry = new AuthModuleEntry(code, options, loginStackRef);
        if (authModule.hasDefined(FLAG)) {
            String flag = LoginModuleResourceDefinition.FLAG.resolveModelAttribute(context, authModule).asString();
            entry.setControlFlag(ControlFlag.valueOf(flag));
        }
        if (loginStackRef != null) {
            if (!holders.containsKey(loginStackRef)) {
                throw SecurityLogger.ROOT_LOGGER.loginModuleStackIllegalArgument(loginStackRef);
            }
            entry.setLoginModuleStackHolder(holders.get(loginStackRef));
        }
        authenticationInfo.add(entry);
        ModelNode moduleName = LoginModuleResourceDefinition.MODULE.resolveModelAttribute(context, authModule);
        if (moduleName.isDefined() && !moduleName.asString().isEmpty()) {
            authenticationInfo.addJBossModuleName(moduleName.asString());
        } else {
            authenticationInfo.addJBossModuleName(DEFAULT_MODULE);
        }
    }
    applicationPolicy.setAuthenticationInfo(authenticationInfo);
    return true;
}
Also used : AuthModuleEntry(org.jboss.security.auth.container.config.AuthModuleEntry) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) JASPIAuthenticationInfo(org.jboss.security.auth.login.JASPIAuthenticationInfo) LoginModuleStackHolder(org.jboss.security.auth.login.LoginModuleStackHolder) AppConfigurationEntry(javax.security.auth.login.AppConfigurationEntry) ModelNode(org.jboss.dmr.ModelNode) Property(org.jboss.dmr.Property)

Example 95 with Property

use of org.jboss.dmr.Property in project wildfly by wildfly.

the class SecurityDomainAdd method processMapping.

private boolean processMapping(OperationContext context, String securityDomain, ModelNode node, ApplicationPolicy applicationPolicy) throws OperationFailedException {
    node = peek(node, MAPPING, CLASSIC, MAPPING_MODULE);
    if (node == null) {
        return false;
    }
    for (Property moduleProperty : node.asPropertyList()) {
        ModelNode module = moduleProperty.getValue();
        MappingInfo mappingInfo = new MappingInfo(securityDomain);
        String codeName = extractCode(context, module, ModulesMap.MAPPING_MAP);
        String mappingType;
        if (module.hasDefined(TYPE)) {
            mappingType = MappingModuleDefinition.TYPE.resolveModelAttribute(context, module).asString();
        } else {
            mappingType = MappingType.ROLE.toString();
        }
        Map<String, Object> options = extractOptions(context, module);
        MappingModuleEntry entry = new MappingModuleEntry(codeName, options, mappingType);
        mappingInfo.add(entry);
        applicationPolicy.setMappingInfo(mappingType, mappingInfo);
        ModelNode moduleName = LoginModuleResourceDefinition.MODULE.resolveModelAttribute(context, module);
        if (moduleName.isDefined() && !moduleName.asString().isEmpty()) {
            mappingInfo.addJBossModuleName(moduleName.asString());
        } else {
            mappingInfo.addJBossModuleName(DEFAULT_MODULE);
        }
    }
    return true;
}
Also used : MappingModuleEntry(org.jboss.security.mapping.config.MappingModuleEntry) ModelNode(org.jboss.dmr.ModelNode) Property(org.jboss.dmr.Property) MappingInfo(org.jboss.security.config.MappingInfo)

Aggregations

Property (org.jboss.dmr.Property)179 ModelNode (org.jboss.dmr.ModelNode)144 HashMap (java.util.HashMap)19 Test (org.junit.Test)19 AttributeDefinition (org.jboss.as.controller.AttributeDefinition)12 PathAddress (org.jboss.as.controller.PathAddress)11 ArrayList (java.util.ArrayList)10 ValueExpression (org.jboss.dmr.ValueExpression)10 ModelType (org.jboss.dmr.ModelType)9 Map (java.util.Map)8 HashSet (java.util.HashSet)7 ArrayDeque (java.util.ArrayDeque)6 OperateOnDeployment (org.jboss.arquillian.container.test.api.OperateOnDeployment)6 OperationFailedException (org.jboss.as.controller.OperationFailedException)6 SimpleAttributeDefinition (org.jboss.as.controller.SimpleAttributeDefinition)6 Properties (java.util.Properties)5 LoginModuleControlFlag (javax.security.auth.login.AppConfigurationEntry.LoginModuleControlFlag)4 SimpleString (org.apache.activemq.artemis.api.core.SimpleString)4 HttpResponse (org.apache.http.HttpResponse)3 HttpGet (org.apache.http.client.methods.HttpGet)3