Search in sources :

Example 6 with SecurityMap

use of org.glassfish.connectors.config.SecurityMap in project Payara by payara.

the class ConnectorConnectionPoolDeployer method deployResource.

/**
 * {@inheritDoc}
 */
public void deployResource(Object resource, String applicationName, String moduleName) throws Exception {
    if (_logger.isLoggable(Level.FINE)) {
        _logger.fine("ConnectorConnectionPoolDeployer : deployResource ");
    }
    final org.glassfish.connectors.config.ConnectorConnectionPool domainCcp = (org.glassfish.connectors.config.ConnectorConnectionPool) resource;
    // redirect call to redeployResource
    if (ConnectionPoolObjectsUtils.isPoolSystemPool(domainCcp)) {
        this.redeployResource(resource);
        return;
    }
    PoolInfo poolInfo = new PoolInfo(domainCcp.getName(), applicationName, moduleName);
    final ConnectorConnectionPool ccp = getConnectorConnectionPool(domainCcp, poolInfo);
    String rarName = domainCcp.getResourceAdapterName();
    String connDefName = domainCcp.getConnectionDefinitionName();
    List<Property> props = domainCcp.getProperty();
    List<SecurityMap> securityMaps = domainCcp.getSecurityMap();
    populateConnectorConnectionPool(ccp, connDefName, rarName, props, securityMaps);
    final String defName = domainCcp.getConnectionDefinitionName();
    if (_logger.isLoggable(Level.FINE)) {
        _logger.log(Level.FINE, "Calling backend to add connectorConnectionPool", domainCcp.getResourceAdapterName());
    }
    runtime.createConnectorConnectionPool(ccp, defName, domainCcp.getResourceAdapterName(), domainCcp.getProperty(), domainCcp.getSecurityMap());
    if (_logger.isLoggable(Level.FINE)) {
        _logger.log(Level.FINE, "Added connectorConnectionPool in backend", domainCcp.getResourceAdapterName());
    }
}
Also used : ConnectorConnectionPool(com.sun.enterprise.connectors.ConnectorConnectionPool) SecurityMap(org.glassfish.connectors.config.SecurityMap) PoolInfo(org.glassfish.resourcebase.resources.api.PoolInfo) ConnectorConfigProperty(com.sun.enterprise.deployment.ConnectorConfigProperty) Property(org.jvnet.hk2.config.types.Property)

Example 7 with SecurityMap

use of org.glassfish.connectors.config.SecurityMap in project Payara by payara.

the class DeleteConnectorSecurityMap method execute.

/**
 * Executes the command with the command parameters passed as Properties
 * where the keys are the paramter names and the values the parameter values
 *
 * @param context information
 */
public void execute(AdminCommandContext context) {
    final ActionReport report = context.getActionReport();
    Collection<ConnectorConnectionPool> ccPools = domain.getResources().getResources(ConnectorConnectionPool.class);
    // ensure we already have this resource
    if (!isResourceExists(ccPools)) {
        report.setMessage(localStrings.getLocalString("delete.connector.security.map.notFound", "A security map named {0} for connector connection pool {1} does not exist.", mapName, poolName));
        report.setActionExitCode(ActionReport.ExitCode.FAILURE);
        return;
    }
    try {
        final ConnectorConnectionPool pool = getPool(poolName, ccPools);
        // delete connector-security-map
        ConfigSupport.apply(new SingleConfigCode<ConnectorConnectionPool>() {

            public Object run(ConnectorConnectionPool param) throws PropertyVetoException, TransactionFailure {
                final List<SecurityMap> securityMaps = param.getSecurityMap();
                if (securityMaps != null) {
                    for (SecurityMap map : securityMaps) {
                        if (map.getName().equals(mapName)) {
                            param.getSecurityMap().remove(map);
                            break;
                        }
                    }
                }
                return param;
            }
        }, pool);
    } catch (TransactionFailure tfe) {
        Logger.getLogger(DeleteConnectorSecurityMap.class.getName()).log(Level.SEVERE, "delete-connector-security-map failed", tfe);
        report.setMessage(localStrings.getLocalString("delete.connector.security.map.fail", "Unable to delete security map {0} for connector connection pool {1}", mapName, poolName) + " " + tfe.getLocalizedMessage());
        report.setActionExitCode(ActionReport.ExitCode.FAILURE);
        report.setFailureCause(tfe);
        return;
    }
    report.setActionExitCode(ActionReport.ExitCode.SUCCESS);
}
Also used : PropertyVetoException(java.beans.PropertyVetoException) TransactionFailure(org.jvnet.hk2.config.TransactionFailure) ConnectorConnectionPool(org.glassfish.connectors.config.ConnectorConnectionPool) SecurityMap(org.glassfish.connectors.config.SecurityMap) List(java.util.List) ActionReport(org.glassfish.api.ActionReport)

Example 8 with SecurityMap

use of org.glassfish.connectors.config.SecurityMap in project Payara by payara.

the class UpdateConnectorSecurityMap method execute.

/**
 * Executes the command with the command parameters passed as Properties
 * where the keys are the paramter names and the values the parameter values
 *
 * @param context information
 */
public void execute(AdminCommandContext context) {
    final ActionReport report = context.getActionReport();
    if (securityMapName == null) {
        report.setMessage(localStrings.getLocalString("create.connector.security.map.noSecurityMapName", "No security map name specified"));
        report.setActionExitCode(ActionReport.ExitCode.FAILURE);
        return;
    }
    Collection<ConnectorConnectionPool> ccPools = domain.getResources().getResources(ConnectorConnectionPool.class);
    if (!doesPoolNameExist(poolName, ccPools)) {
        report.setMessage(localStrings.getLocalString("create.connector.security.map.noSuchPoolFound", "Connector connection pool {0} does not exist. Please specify a valid pool name.", poolName));
        report.setActionExitCode(ActionReport.ExitCode.FAILURE);
        return;
    }
    if (!doesMapNameExist(poolName, securityMapName, ccPools)) {
        report.setMessage(localStrings.getLocalString("update.connector.security.map.map_does_not_exist", "Security map {0} does not exist for connector connection pool {1}. Please give a valid map name.", securityMapName, poolName));
        report.setActionExitCode(ActionReport.ExitCode.FAILURE);
        return;
    }
    // get all the security maps for this pool.....
    List<SecurityMap> maps = getAllSecurityMapsForPool(poolName, ccPools);
    // check if addPrincipals and removePrincipals have the same value
    if (addPrincipals != null && removePrincipals != null) {
        for (String ap : addPrincipals) {
            for (String rp : removePrincipals) {
                if (rp.equals(ap)) {
                    report.setMessage(localStrings.getLocalString("update.connector.security.map.same_principal_values", "This value {0} is given in both --addprincipals and --removeprincipals. The same value cannot given for these options.", ap));
                    report.setActionExitCode(ActionReport.ExitCode.FAILURE);
                    return;
                }
            }
        }
    }
    // check if addUserGroups and removeUserGroups have the same value
    if (addUserGroups != null && removeUserGroups != null) {
        for (String aug : addUserGroups) {
            for (String rug : removeUserGroups) {
                if (rug.equals(aug)) {
                    report.setMessage(localStrings.getLocalString("update.connector.security.map.same_usergroup_values", "This value {0} is given in both --addusergroups and --removeusergroups. The same value cannot given for these options.", aug));
                    report.setActionExitCode(ActionReport.ExitCode.FAILURE);
                    return;
                }
            }
        }
    }
    // make sure that the principals to be added are not existing in any map ...
    if (addPrincipals != null) {
        for (String principal : addPrincipals) {
            if (isPrincipalExisting(principal, maps)) {
                report.setMessage(localStrings.getLocalString("create.connector.security.map.principal_exists", "The principal {0} already exists in connector connection pool {1}. Please give a different principal name.", principal, poolName));
                report.setActionExitCode(ActionReport.ExitCode.FAILURE);
                return;
            }
        }
    }
    // make sure that the user groups to be added are not existing in any map ...
    if (addUserGroups != null) {
        for (String userGroup : addUserGroups) {
            if (isUserGroupExisting(userGroup, maps)) {
                report.setMessage(localStrings.getLocalString("create.connector.security.map.usergroup_exists", "The user-group {0} already exists in connector connection pool {1}. Please give a different user-group name.", userGroup, poolName));
                report.setActionExitCode(ActionReport.ExitCode.FAILURE);
                return;
            }
        }
    }
    SecurityMap map = getSecurityMap(securityMapName, poolName, ccPools);
    final List<String> existingPrincipals = new ArrayList(map.getPrincipal());
    final List<String> existingUserGroups = new ArrayList(map.getUserGroup());
    // check if there is any invalid principal in removePrincipals.
    if (removePrincipals != null) {
        boolean principalExists = true;
        String principal = null;
        for (String p : removePrincipals) {
            if (!existingPrincipals.contains(p)) {
                principalExists = false;
                principal = p;
                break;
            }
        }
        if (!principalExists) {
            report.setMessage(localStrings.getLocalString("update.connector.security.map.principal_does_not_exists", "The principal {0} that you want to delete does not exist in connector connection pool {1}. Please give a valid principal name.", principal, poolName));
            report.setActionExitCode(ActionReport.ExitCode.FAILURE);
            return;
        }
    }
    // check if there is any invalid usergroup in removeUserGroups.
    if (removeUserGroups != null) {
        boolean userGroupExists = true;
        String userGroup = null;
        for (String ug : removeUserGroups) {
            if (!existingUserGroups.contains(ug)) {
                userGroupExists = false;
                userGroup = ug;
                break;
            }
        }
        if (!userGroupExists) {
            report.setMessage(localStrings.getLocalString("update.connector.security.map.usergroup_does_not_exists", "The usergroup {0} that you want to delete does not exist in connector connection pool {1}. Please give a valid user-group name.", userGroup, poolName));
            report.setActionExitCode(ActionReport.ExitCode.FAILURE);
            return;
        }
    }
    if (addPrincipals == null && addUserGroups == null) {
        boolean principalsEmpty = false;
        boolean userGroupsEmpty = false;
        if (removePrincipals == null && existingPrincipals.isEmpty()) {
            principalsEmpty = true;
        }
        if (removeUserGroups == null && existingUserGroups.isEmpty()) {
            userGroupsEmpty = true;
        }
        if ((removePrincipals != null) && (removePrincipals.size() == existingPrincipals.size())) {
            principalsEmpty = true;
        }
        if ((removeUserGroups != null) && (removeUserGroups.size() == existingUserGroups.size())) {
            userGroupsEmpty = true;
        }
        if (userGroupsEmpty && principalsEmpty) {
            report.setMessage(localStrings.getLocalString("update.connector.security.map.principals_usergroups_will_be_null", "The values in your command will delete all principals and usergroups. You cannot delete all principals and usergroups. Atleast one of them must exist."));
            report.setActionExitCode(ActionReport.ExitCode.FAILURE);
            return;
        }
    }
    // add principals to the existingPrincipals arraylist.
    if (addPrincipals != null) {
        for (String principal : addPrincipals) {
            if (!existingPrincipals.contains(principal)) {
                existingPrincipals.add(principal);
            } else {
                report.setMessage(localStrings.getLocalString("create.connector.security.map.principal_exists", "The principal {0} already exists in connector connection pool {1}. Please give a different principal name.", principal, poolName));
                report.setActionExitCode(ActionReport.ExitCode.FAILURE);
                return;
            }
        }
    }
    // removing principals from existingPrincipals arraylist.
    if (removePrincipals != null) {
        for (String principal : removePrincipals) {
            existingPrincipals.remove(principal);
        }
    }
    // adding user-groups....
    if (addUserGroups != null) {
        for (String userGroup : addUserGroups) {
            if (!existingUserGroups.contains(userGroup)) {
                existingUserGroups.add(userGroup);
            } else {
                report.setMessage(localStrings.getLocalString("create.connector.security.map.usergroup_exists", "The user-group {0} already exists in connector connection pool {1}. Please give a different user-group name.", userGroup, poolName));
                report.setActionExitCode(ActionReport.ExitCode.FAILURE);
                return;
            }
        }
    }
    // removing user-groups....
    if (removeUserGroups != null) {
        for (String userGroup : removeUserGroups) {
            existingUserGroups.remove(userGroup);
        }
    }
    // the update-connector-security-map command.
    if (!hasOnlyPrincipalsOrOnlyUserGroups(report, existingPrincipals, existingUserGroups)) {
        return;
    }
    BackendPrincipal backendPrincipal = map.getBackendPrincipal();
    try {
        ConfigSupport.apply(new ConfigCode() {

            public Object run(ConfigBeanProxy... params) throws PropertyVetoException, TransactionFailure {
                SecurityMap sm = (SecurityMap) params[0];
                BackendPrincipal bp = (BackendPrincipal) params[1];
                // setting the updated principal user-group arrays....
                if (existingPrincipals != null) {
                    sm.getPrincipal().clear();
                    for (String principal : existingPrincipals) {
                        sm.getPrincipal().add(principal);
                    }
                }
                if (existingUserGroups != null) {
                    sm.getUserGroup().clear();
                    for (String userGroup : existingUserGroups) {
                        sm.getUserGroup().add(userGroup);
                    }
                }
                // get the backend principal for the given security map and pool...
                if (mappedusername != null && !mappedusername.isEmpty()) {
                    bp.setUserName(mappedusername);
                }
                if (mappedpassword != null) {
                    if (mappedpassword.isEmpty()) {
                        bp.setPassword(null);
                    } else {
                        bp.setPassword(mappedpassword);
                    }
                }
                return sm;
            }
        }, map, backendPrincipal);
        report.setActionExitCode(ActionReport.ExitCode.SUCCESS);
    } catch (TransactionFailure tfe) {
        Object[] params = { securityMapName, poolName };
        report.setMessage(localStrings.getLocalString("update.connector.security.map.fail", "Unable to update security map {0} for connector connection pool {1}.", params) + " " + tfe.getLocalizedMessage());
        report.setActionExitCode(ActionReport.ExitCode.FAILURE);
        report.setFailureCause(tfe);
    }
}
Also used : TransactionFailure(org.jvnet.hk2.config.TransactionFailure) ConnectorConnectionPool(org.glassfish.connectors.config.ConnectorConnectionPool) ArrayList(java.util.ArrayList) ActionReport(org.glassfish.api.ActionReport) PropertyVetoException(java.beans.PropertyVetoException) SecurityMap(org.glassfish.connectors.config.SecurityMap) ConfigBeanProxy(org.jvnet.hk2.config.ConfigBeanProxy) ConfigCode(org.jvnet.hk2.config.ConfigCode) BackendPrincipal(org.glassfish.connectors.config.BackendPrincipal)

Example 9 with SecurityMap

use of org.glassfish.connectors.config.SecurityMap in project Payara by payara.

the class ConnectorSecurityMap method doesMapNameExist.

boolean doesMapNameExist(String poolName, String mapname, Collection<ConnectorConnectionPool> ccPools) {
    // check if the mapname exists for the given pool name..
    List<SecurityMap> maps = getAllSecurityMapsForPool(poolName, ccPools);
    boolean doesMapNameExist = false;
    if (maps != null) {
        for (SecurityMap sm : maps) {
            String name = sm.getName();
            if (name.equals(mapname)) {
                doesMapNameExist = true;
            }
        }
    }
    return doesMapNameExist;
}
Also used : SecurityMap(org.glassfish.connectors.config.SecurityMap)

Example 10 with SecurityMap

use of org.glassfish.connectors.config.SecurityMap in project Payara by payara.

the class ConnectorSecurityMap method getSecurityMap.

SecurityMap getSecurityMap(String mapName, String poolName, Collection<ConnectorConnectionPool> ccPools) {
    List<SecurityMap> maps = getAllSecurityMapsForPool(poolName, ccPools);
    SecurityMap map = null;
    if (maps != null) {
        for (SecurityMap sm : maps) {
            if (sm.getName().equals(mapName)) {
                map = sm;
                break;
            }
        }
    }
    return map;
}
Also used : SecurityMap(org.glassfish.connectors.config.SecurityMap)

Aggregations

SecurityMap (org.glassfish.connectors.config.SecurityMap)10 ActionReport (org.glassfish.api.ActionReport)4 ConnectorConnectionPool (org.glassfish.connectors.config.ConnectorConnectionPool)4 PropertyVetoException (java.beans.PropertyVetoException)3 TransactionFailure (org.jvnet.hk2.config.TransactionFailure)3 ConnectorConnectionPool (com.sun.enterprise.connectors.ConnectorConnectionPool)2 ConnectorConfigProperty (com.sun.enterprise.deployment.ConnectorConfigProperty)2 List (java.util.List)2 BackendPrincipal (org.glassfish.connectors.config.BackendPrincipal)2 PoolInfo (org.glassfish.resourcebase.resources.api.PoolInfo)2 Property (org.jvnet.hk2.config.types.Property)2 ConnectorRuntimeException (com.sun.appserv.connectors.internal.api.ConnectorRuntimeException)1 ArrayList (java.util.ArrayList)1 ConfigBeanProxy (org.jvnet.hk2.config.ConfigBeanProxy)1 ConfigCode (org.jvnet.hk2.config.ConfigCode)1