Search in sources :

Example 1 with WorkManagerSecurityImpl

use of org.jboss.as.connector.metadata.resourceadapter.WorkManagerSecurityImpl in project wildfly by wildfly.

the class RaOperationUtil method buildResourceAdaptersObject.

public static ModifiableResourceAdapter buildResourceAdaptersObject(final String id, final OperationContext context, ModelNode operation, String archiveOrModule) throws OperationFailedException {
    Map<String, String> configProperties = new HashMap<>(0);
    List<ConnectionDefinition> connectionDefinitions = new ArrayList<>(0);
    List<AdminObject> adminObjects = new ArrayList<>(0);
    String transactionSupportResolved = ModelNodeUtil.getResolvedStringIfSetOrGetDefault(context, operation, TRANSACTION_SUPPORT);
    TransactionSupportEnum transactionSupport = operation.hasDefined(TRANSACTION_SUPPORT.getName()) ? TransactionSupportEnum.valueOf(ModelNodeUtil.getResolvedStringIfSetOrGetDefault(context, operation, TRANSACTION_SUPPORT)) : null;
    String bootstrapContext = ModelNodeUtil.getResolvedStringIfSetOrGetDefault(context, operation, BOOTSTRAP_CONTEXT);
    List<String> beanValidationGroups = BEANVALIDATION_GROUPS.unwrap(context, operation);
    boolean wmSecurity = ModelNodeUtil.getBooleanIfSetOrGetDefault(context, operation, WM_SECURITY);
    WorkManager workManager = null;
    if (wmSecurity) {
        final boolean mappingRequired = ModelNodeUtil.getBooleanIfSetOrGetDefault(context, operation, WM_SECURITY_MAPPING_REQUIRED);
        String domain;
        final String elytronDomain = ModelNodeUtil.getResolvedStringIfSetOrGetDefault(context, operation, WM_ELYTRON_SECURITY_DOMAIN);
        if (elytronDomain != null) {
            domain = elytronDomain;
        } else {
            domain = ModelNodeUtil.getResolvedStringIfSetOrGetDefault(context, operation, WM_SECURITY_DOMAIN);
        }
        final String defaultPrincipal = ModelNodeUtil.getResolvedStringIfSetOrGetDefault(context, operation, WM_SECURITY_DEFAULT_PRINCIPAL);
        final List<String> defaultGroups = WM_SECURITY_DEFAULT_GROUPS.unwrap(context, operation);
        final Map<String, String> groups = ModelNodeUtil.extractMap(operation, WM_SECURITY_MAPPING_GROUPS, WM_SECURITY_MAPPING_FROM, WM_SECURITY_MAPPING_TO);
        final Map<String, String> users = ModelNodeUtil.extractMap(operation, WM_SECURITY_MAPPING_USERS, WM_SECURITY_MAPPING_FROM, WM_SECURITY_MAPPING_TO);
        workManager = new WorkManagerImpl(new WorkManagerSecurityImpl(mappingRequired, domain, elytronDomain != null, defaultPrincipal, defaultGroups, users, groups));
    }
    ModifiableResourceAdapter ra;
    ra = new ModifiableResourceAdapter(id, archiveOrModule, transactionSupport, connectionDefinitions, adminObjects, configProperties, beanValidationGroups, bootstrapContext, workManager);
    return ra;
}
Also used : ConnectionDefinition(org.jboss.jca.common.api.metadata.resourceadapter.ConnectionDefinition) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) WorkManagerSecurityImpl(org.jboss.as.connector.metadata.resourceadapter.WorkManagerSecurityImpl) WorkManagerImpl(org.jboss.jca.common.metadata.resourceadapter.WorkManagerImpl) WorkManager(org.jboss.jca.common.api.metadata.resourceadapter.WorkManager) TransactionSupportEnum(org.jboss.jca.common.api.metadata.common.TransactionSupportEnum) AdminObject(org.jboss.jca.common.api.metadata.resourceadapter.AdminObject)

Example 2 with WorkManagerSecurityImpl

use of org.jboss.as.connector.metadata.resourceadapter.WorkManagerSecurityImpl in project wildfly by wildfly.

the class ResourceAdapterParser method parseWorkManagerSecurity.

protected WorkManagerSecurity parseWorkManagerSecurity(final ModelNode operation, final XMLStreamReader reader) throws XMLStreamException, ParserException, ValidateException {
    boolean mappingRequired = false;
    String domain = null;
    String defaultPrincipal = null;
    List<String> defaultGroups = null;
    Map<String, String> userMappings = null;
    Map<String, String> groupMappings = null;
    boolean userMappingEnabled = false;
    while (reader.hasNext()) {
        switch(reader.nextTag()) {
            case END_ELEMENT:
                {
                    if (WorkManager.Tag.forName(reader.getLocalName()) == WorkManager.Tag.SECURITY) {
                        return new WorkManagerSecurityImpl(mappingRequired, domain, false, defaultPrincipal, defaultGroups, userMappings, groupMappings);
                    } else {
                        if (WorkManagerSecurity.Tag.forName(reader.getLocalName()) == WorkManagerSecurity.Tag.UNKNOWN) {
                            throw new ParserException(bundle.unexpectedEndTag(reader.getLocalName()));
                        }
                    }
                    break;
                }
            case START_ELEMENT:
                {
                    switch(WorkManagerSecurity.Tag.forName(reader.getLocalName())) {
                        case DEFAULT_GROUPS:
                        case MAPPINGS:
                            {
                                // Skip
                                break;
                            }
                        case MAPPING_REQUIRED:
                            {
                                String value = rawElementText(reader);
                                WM_SECURITY_MAPPING_REQUIRED.parseAndSetParameter(value, operation, reader);
                                break;
                            }
                        case DOMAIN:
                            {
                                String value = domain = rawElementText(reader);
                                WM_SECURITY_DOMAIN.parseAndSetParameter(value, operation, reader);
                                break;
                            }
                        case DEFAULT_PRINCIPAL:
                            {
                                String value = rawElementText(reader);
                                WM_SECURITY_DEFAULT_PRINCIPAL.parseAndSetParameter(value, operation, reader);
                                break;
                            }
                        case GROUP:
                            {
                                String value = rawElementText(reader);
                                operation.get(WM_SECURITY_DEFAULT_GROUPS.getName()).add(WM_SECURITY_DEFAULT_GROUP.parse(value, reader));
                                break;
                            }
                        case USERS:
                            {
                                userMappingEnabled = true;
                                break;
                            }
                        case GROUPS:
                            {
                                userMappingEnabled = false;
                                break;
                            }
                        case MAP:
                            {
                                if (userMappingEnabled) {
                                    String from = rawAttributeText(reader, WorkManagerSecurity.Attribute.FROM.getLocalName());
                                    if (from == null || from.trim().equals(""))
                                        throw new ParserException(bundle.requiredAttributeMissing(WorkManagerSecurity.Attribute.FROM.getLocalName(), reader.getLocalName()));
                                    String to = rawAttributeText(reader, WorkManagerSecurity.Attribute.TO.getLocalName());
                                    if (to == null || to.trim().equals(""))
                                        throw new ParserException(bundle.requiredAttributeMissing(WorkManagerSecurity.Attribute.TO.getLocalName(), reader.getLocalName()));
                                    ModelNode object = new ModelNode();
                                    WM_SECURITY_MAPPING_FROM.parseAndSetParameter(from, object, reader);
                                    WM_SECURITY_MAPPING_TO.parseAndSetParameter(to, object, reader);
                                    operation.get(WM_SECURITY_MAPPING_USERS.getName()).add(object);
                                } else {
                                    String from = rawAttributeText(reader, WorkManagerSecurity.Attribute.FROM.getLocalName());
                                    if (from == null || from.trim().equals(""))
                                        throw new ParserException(bundle.requiredAttributeMissing(WorkManagerSecurity.Attribute.FROM.getLocalName(), reader.getLocalName()));
                                    String to = rawAttributeText(reader, WorkManagerSecurity.Attribute.TO.getLocalName());
                                    if (to == null || to.trim().equals(""))
                                        throw new ParserException(bundle.requiredAttributeMissing(WorkManagerSecurity.Attribute.TO.getLocalName(), reader.getLocalName()));
                                    ModelNode object = new ModelNode();
                                    WM_SECURITY_MAPPING_FROM.parseAndSetParameter(from, object, reader);
                                    WM_SECURITY_MAPPING_TO.parseAndSetParameter(to, object, reader);
                                    operation.get(WM_SECURITY_MAPPING_GROUPS.getName()).add(object);
                                }
                                break;
                            }
                        default:
                            throw new ParserException(bundle.unexpectedElement(reader.getLocalName()));
                    }
                    break;
                }
        }
    }
    throw new ParserException(bundle.unexpectedEndOfDocument());
}
Also used : ParserException(org.jboss.as.connector.util.ParserException) WorkManagerSecurityImpl(org.jboss.as.connector.metadata.resourceadapter.WorkManagerSecurityImpl) ModelNode(org.jboss.dmr.ModelNode)

Example 3 with WorkManagerSecurityImpl

use of org.jboss.as.connector.metadata.resourceadapter.WorkManagerSecurityImpl in project wildfly by wildfly.

the class ResourceAdapterParser method parseWorkManagerSecurity_5_0.

protected WorkManagerSecurity parseWorkManagerSecurity_5_0(final ModelNode operation, final XMLStreamReader reader) throws XMLStreamException, ParserException, ValidateException {
    boolean mappingRequired = false;
    String domain = null;
    boolean elytronEnabled = false;
    String defaultPrincipal = null;
    List<String> defaultGroups = null;
    Map<String, String> userMappings = null;
    Map<String, String> groupMappings = null;
    boolean userMappingEnabled = false;
    while (reader.hasNext()) {
        switch(reader.nextTag()) {
            case END_ELEMENT:
                {
                    if (WorkManager.Tag.forName(reader.getLocalName()) == WorkManager.Tag.SECURITY) {
                        return new WorkManagerSecurityImpl(mappingRequired, domain, elytronEnabled, defaultPrincipal, defaultGroups, userMappings, groupMappings);
                    } else {
                        if (WorkManagerSecurity.Tag.forName(reader.getLocalName()) == WorkManagerSecurity.Tag.UNKNOWN) {
                            throw new ParserException(bundle.unexpectedEndTag(reader.getLocalName()));
                        }
                    }
                    break;
                }
            case START_ELEMENT:
                {
                    switch(WorkManagerSecurity.Tag.forName(reader.getLocalName())) {
                        case DEFAULT_GROUPS:
                        case MAPPINGS:
                            {
                                // Skip
                                break;
                            }
                        case MAPPING_REQUIRED:
                            {
                                String value = rawElementText(reader);
                                WM_SECURITY_MAPPING_REQUIRED.parseAndSetParameter(value, operation, reader);
                                break;
                            }
                        case DOMAIN:
                            {
                                String value = domain = rawElementText(reader);
                                WM_SECURITY_DOMAIN.parseAndSetParameter(value, operation, reader);
                                break;
                            }
                        case ELYTRON_SECURITY_DOMAIN:
                            {
                                elytronEnabled = true;
                                String value = domain = rawElementText(reader);
                                WM_ELYTRON_SECURITY_DOMAIN.parseAndSetParameter(value, operation, reader);
                                break;
                            }
                        case DEFAULT_PRINCIPAL:
                            {
                                String value = rawElementText(reader);
                                WM_SECURITY_DEFAULT_PRINCIPAL.parseAndSetParameter(value, operation, reader);
                                break;
                            }
                        case GROUP:
                            {
                                String value = rawElementText(reader);
                                operation.get(WM_SECURITY_DEFAULT_GROUPS.getName()).add(WM_SECURITY_DEFAULT_GROUP.parse(value, reader));
                                break;
                            }
                        case USERS:
                            {
                                userMappingEnabled = true;
                                break;
                            }
                        case GROUPS:
                            {
                                userMappingEnabled = false;
                                break;
                            }
                        case MAP:
                            {
                                if (userMappingEnabled) {
                                    String from = rawAttributeText(reader, WorkManagerSecurity.Attribute.FROM.getLocalName());
                                    if (from == null || from.trim().equals(""))
                                        throw new ParserException(bundle.requiredAttributeMissing(WorkManagerSecurity.Attribute.FROM.getLocalName(), reader.getLocalName()));
                                    String to = rawAttributeText(reader, WorkManagerSecurity.Attribute.TO.getLocalName());
                                    if (to == null || to.trim().equals(""))
                                        throw new ParserException(bundle.requiredAttributeMissing(WorkManagerSecurity.Attribute.TO.getLocalName(), reader.getLocalName()));
                                    ModelNode object = new ModelNode();
                                    WM_SECURITY_MAPPING_FROM.parseAndSetParameter(from, object, reader);
                                    WM_SECURITY_MAPPING_TO.parseAndSetParameter(to, object, reader);
                                    operation.get(WM_SECURITY_MAPPING_USERS.getName()).add(object);
                                } else {
                                    String from = rawAttributeText(reader, WorkManagerSecurity.Attribute.FROM.getLocalName());
                                    if (from == null || from.trim().equals(""))
                                        throw new ParserException(bundle.requiredAttributeMissing(WorkManagerSecurity.Attribute.FROM.getLocalName(), reader.getLocalName()));
                                    String to = rawAttributeText(reader, WorkManagerSecurity.Attribute.TO.getLocalName());
                                    if (to == null || to.trim().equals(""))
                                        throw new ParserException(bundle.requiredAttributeMissing(WorkManagerSecurity.Attribute.TO.getLocalName(), reader.getLocalName()));
                                    ModelNode object = new ModelNode();
                                    WM_SECURITY_MAPPING_FROM.parseAndSetParameter(from, object, reader);
                                    WM_SECURITY_MAPPING_TO.parseAndSetParameter(to, object, reader);
                                    operation.get(WM_SECURITY_MAPPING_GROUPS.getName()).add(object);
                                }
                                break;
                            }
                        default:
                            throw new ParserException(bundle.unexpectedElement(reader.getLocalName()));
                    }
                    break;
                }
        }
    }
    throw new ParserException(bundle.unexpectedEndOfDocument());
}
Also used : ParserException(org.jboss.as.connector.util.ParserException) WorkManagerSecurityImpl(org.jboss.as.connector.metadata.resourceadapter.WorkManagerSecurityImpl) ModelNode(org.jboss.dmr.ModelNode)

Aggregations

WorkManagerSecurityImpl (org.jboss.as.connector.metadata.resourceadapter.WorkManagerSecurityImpl)3 ParserException (org.jboss.as.connector.util.ParserException)2 ModelNode (org.jboss.dmr.ModelNode)2 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 TransactionSupportEnum (org.jboss.jca.common.api.metadata.common.TransactionSupportEnum)1 AdminObject (org.jboss.jca.common.api.metadata.resourceadapter.AdminObject)1 ConnectionDefinition (org.jboss.jca.common.api.metadata.resourceadapter.ConnectionDefinition)1 WorkManager (org.jboss.jca.common.api.metadata.resourceadapter.WorkManager)1 WorkManagerImpl (org.jboss.jca.common.metadata.resourceadapter.WorkManagerImpl)1