Search in sources :

Example 21 with ConnectorConnectionPool

use of org.glassfish.connectors.config.ConnectorConnectionPool 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 22 with ConnectorConnectionPool

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

the class ConnectorConnectionPoolManager method createResource.

private ConnectorConnectionPool createResource(Resources param, Properties properties) throws PropertyVetoException, TransactionFailure {
    ConnectorConnectionPool newResource = createConfigBean(param, properties);
    param.getResources().add(newResource);
    return newResource;
}
Also used : ConnectorConnectionPool(org.glassfish.connectors.config.ConnectorConnectionPool)

Example 23 with ConnectorConnectionPool

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

the class ActiveJmsResourceAdapter method setValuesFromConfiguration.

private void setValuesFromConfiguration(String cfName, EjbMessageBeanDescriptor descriptor_) throws ConnectorRuntimeException {
    // todo: need to enable
    List<Property> ep = null;
    try {
        /*Resources rbeans = getAllResources();//ServerBeansFactory.getDomainBean(ctx).getResources();
            ConnectorResource res = (ConnectorResource)
                             rbeans.getResourceByName(ConnectorResource.class, cfName);*/
        String appName = descriptor_.getApplication().getAppName();
        String moduleName = ConnectorsUtil.getModuleName(descriptor_);
        ConnectorResource res = (ConnectorResource) ResourcesUtil.createInstance().getResource(cfName, appName, moduleName, ConnectorResource.class);
        if (res == null) {
            String msg = sm.getString("ajra.mdb_cf_not_created", cfName);
            throw new ConnectorRuntimeException(msg);
        }
        ConnectorConnectionPool ccp = (ConnectorConnectionPool) ResourcesUtil.createInstance().getResource(res.getPoolName(), appName, moduleName, ConnectorConnectionPool.class);
        // rbeans.getResourceByName(ConnectorConnectionPool.class, res.getPoolName());
        ep = ccp.getProperty();
    } catch (Exception ce) {
        String msg = sm.getString("ajra.mdb_cf_not_created", cfName);
        ConnectorRuntimeException cre = new ConnectorRuntimeException(msg);
        cre.initCause(ce);
        throw cre;
    }
    if (ep == null) {
        String msg = sm.getString("ajra.cannot_find_phy_dest");
        throw new ConnectorRuntimeException(msg);
    }
    for (int i = 0; i < ep.size(); i++) {
        Property prop = ep.get(i);
        String name = prop.getName();
        if (name.equals(MCFADDRESSLIST)) {
            name = ADDRESSLIST;
        }
        String val = prop.getValue();
        if (val == null || val.equals("")) {
            continue;
        }
        descriptor_.putRuntimeActivationConfigProperty(new EnvironmentProperty(name, val, null));
    }
}
Also used : ConnectorRuntimeException(com.sun.appserv.connectors.internal.api.ConnectorRuntimeException) ConnectorConnectionPool(org.glassfish.connectors.config.ConnectorConnectionPool) EnvironmentProperty(com.sun.enterprise.deployment.EnvironmentProperty) Property(org.jvnet.hk2.config.types.Property) EnvironmentProperty(com.sun.enterprise.deployment.EnvironmentProperty) ConnectorConfigProperty(com.sun.enterprise.deployment.ConnectorConfigProperty) ConnectorResource(org.glassfish.connectors.config.ConnectorResource) MultiException(org.glassfish.hk2.api.MultiException) PrivilegedActionException(java.security.PrivilegedActionException) ExecutionException(java.util.concurrent.ExecutionException) ResourceAdapterInternalException(javax.resource.spi.ResourceAdapterInternalException) URISyntaxException(java.net.URISyntaxException) ConnectorRuntimeException(com.sun.appserv.connectors.internal.api.ConnectorRuntimeException)

Aggregations

ConnectorConnectionPool (org.glassfish.connectors.config.ConnectorConnectionPool)23 ConnectorResource (org.glassfish.connectors.config.ConnectorResource)10 ActionReport (org.glassfish.api.ActionReport)9 ConnectorRuntimeException (com.sun.appserv.connectors.internal.api.ConnectorRuntimeException)5 SecurityMap (org.glassfish.connectors.config.SecurityMap)4 TransactionFailure (org.jvnet.hk2.config.TransactionFailure)4 ResourcePool (com.sun.enterprise.config.serverbeans.ResourcePool)3 PropertyVetoException (java.beans.PropertyVetoException)3 AdminObjectResource (org.glassfish.connectors.config.AdminObjectResource)3 PoolInfo (org.glassfish.resourcebase.resources.api.PoolInfo)3 ResourceInfo (org.glassfish.resourcebase.resources.api.ResourceInfo)3 ConnectionFactoryDefinitionDescriptor (com.sun.enterprise.deployment.ConnectionFactoryDefinitionDescriptor)2 JMSConnectionFactoryDefinitionDescriptor (com.sun.enterprise.deployment.JMSConnectionFactoryDefinitionDescriptor)2 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 List (java.util.List)2 Properties (java.util.Properties)2 NamingException (javax.naming.NamingException)2 ResourceException (javax.resource.ResourceException)2 BackendPrincipal (org.glassfish.connectors.config.BackendPrincipal)2