Search in sources :

Example 1 with SecurityMap

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

the class CreateConnectorSecurityMap method execute.

/**
 * Executes the command with the command parameters passed as Properties
 * where the keys are the parameter 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;
    }
    if (principals == null && userGroups == null) {
        report.setMessage(localStrings.getLocalString("create.connector.security.map.noPrincipalsOrGroupsMap", "Either the principal or the user group has to be specified while creating a security map." + " Both cannot be null."));
        report.setActionExitCode(ActionReport.ExitCode.FAILURE);
        return;
    }
    if (principals != null && userGroups != null) {
        report.setMessage(localStrings.getLocalString("create.connector.security.map.specifyPrincipalsOrGroupsMap", "A work-security-map can have either (any number of) group mapping or (any number of) principals" + " mapping but not both. Specify --principals or --usergroups."));
        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("create.connector.security.map.duplicate", "A security map named {0} already exists for connector connection pool {1}. Please give a" + " different map name.", securityMapName, poolName));
        report.setActionExitCode(ActionReport.ExitCode.FAILURE);
        return;
    }
    // get all the security maps for this pool.....
    List<SecurityMap> maps = getAllSecurityMapsForPool(poolName, ccPools);
    if (principals != null) {
        for (String principal : principals) {
            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;
            }
        }
    }
    if (userGroups != null) {
        for (String userGroup : userGroups) {
            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;
            }
        }
    }
    ConnectorConnectionPool connPool = null;
    for (ConnectorConnectionPool ccp : ccPools) {
        if (ccp.getName().equals(poolName)) {
            connPool = ccp;
        }
    }
    try {
        ConfigSupport.apply(new SingleConfigCode<ConnectorConnectionPool>() {

            public Object run(ConnectorConnectionPool ccp) throws PropertyVetoException, TransactionFailure {
                List<SecurityMap> securityMaps = ccp.getSecurityMap();
                SecurityMap newResource = ccp.createChild(SecurityMap.class);
                newResource.setName(securityMapName);
                if (principals != null) {
                    for (String p : principals) {
                        newResource.getPrincipal().add(p);
                    }
                }
                if (userGroups != null) {
                    for (String u : userGroups) {
                        newResource.getUserGroup().add(u);
                    }
                }
                BackendPrincipal backendPrincipal = newResource.createChild(BackendPrincipal.class);
                backendPrincipal.setUserName(mappedusername);
                if (mappedpassword != null && !mappedpassword.isEmpty()) {
                    backendPrincipal.setPassword(mappedpassword);
                }
                newResource.setBackendPrincipal(backendPrincipal);
                securityMaps.add(newResource);
                return newResource;
            }
        }, connPool);
    } catch (TransactionFailure tfe) {
        Object[] params = { securityMapName, poolName };
        report.setMessage(localStrings.getLocalString("create.connector.security.map.fail", "Unable to create connector security map {0} for connector connection pool {1} ", params) + " " + 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) BackendPrincipal(org.glassfish.connectors.config.BackendPrincipal) List(java.util.List) ActionReport(org.glassfish.api.ActionReport)

Example 2 with SecurityMap

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

the class ConnectorSecurityMap method isUserGroupExisting.

boolean isUserGroupExisting(String usergroup, List<SecurityMap> maps) {
    boolean exists = false;
    List<String> existingUserGroups = null;
    if (maps != null) {
        for (SecurityMap sm : maps) {
            existingUserGroups = sm.getUserGroup();
            if (existingUserGroups != null && usergroup != null) {
                for (String eug : existingUserGroups) {
                    if (eug.equals(usergroup)) {
                        exists = true;
                        break;
                    }
                }
            }
        }
    }
    return exists;
}
Also used : SecurityMap(org.glassfish.connectors.config.SecurityMap)

Example 3 with SecurityMap

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

the class ConnectorSecurityMap method isPrincipalExisting.

boolean isPrincipalExisting(String principal, List<SecurityMap> maps) {
    boolean exists = false;
    List<String> existingPrincipals = null;
    if (maps != null) {
        for (SecurityMap sm : maps) {
            existingPrincipals = sm.getPrincipal();
            if (existingPrincipals != null && principal != null) {
                for (String ep : existingPrincipals) {
                    if (ep.equals(principal)) {
                        exists = true;
                        break;
                    }
                }
            }
        }
    }
    return exists;
}
Also used : SecurityMap(org.glassfish.connectors.config.SecurityMap)

Example 4 with SecurityMap

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

the class ListConnectorSecurityMaps 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();
    final ActionReport.MessagePart mp = report.getTopMessagePart();
    /* Issue 5918 Used in ManifestManager to keep output sorted */
    // try {
    // PropsFileActionReporter reporter = (PropsFileActionReporter) report;
    // reporter.useMainChildrenAttribute(true);
    // } catch(ClassCastException e) {
    // ignore this is not a manifest output.
    // }
    Collection<ConnectorConnectionPool> ccPools = domain.getResources().getResources(ConnectorConnectionPool.class);
    if (!doesPoolNameExist(poolName, ccPools)) {
        report.setMessage(localStrings.getLocalString("create.connector.security.map.noSuchPoolFound", "Specified connector connection pool {0} does not exist. Please specify a valid pool name.", poolName));
        report.setActionExitCode(ActionReport.ExitCode.FAILURE);
        return;
    }
    if (securityMap != null) {
        if (!doesMapNameExist(poolName, securityMap, ccPools)) {
            report.setMessage(localStrings.getLocalString("list.connector.security.maps.securityMapNotFound", "Security map {0} does not exist for connector connection pool {1}. Please give a valid map name.", securityMap, poolName));
            report.setActionExitCode(ActionReport.ExitCode.FAILURE);
            return;
        }
    }
    try {
        final List<SecurityMap> securityMaps = getAllSecurityMapsForPool(poolName, ccPools);
        if (securityMaps != null && !securityMaps.isEmpty()) {
            if (securityMap == null && long_opt) {
                for (SecurityMap sm : securityMaps) {
                    listSecurityMapDetails(sm, mp);
                }
            } else if (securityMap == null && !long_opt) {
                // print the map names .....
                for (SecurityMap sm : securityMaps) {
                    listSecurityMapNames(sm, mp);
                }
            } else {
                // map name is not null, long_opt is redundant when security map is specified
                for (SecurityMap sm : securityMaps) {
                    if (sm.getName().equals(securityMap)) {
                        // if (long_opt) {
                        listSecurityMapDetails(sm, mp);
                        break;
                    // } else {
                    // listSecurityMapNames(sm, mp);
                    // break;
                    // }
                    }
                }
            }
        }
    } catch (Exception e) {
        Logger.getLogger(ListConnectorSecurityMaps.class.getName()).log(Level.SEVERE, "list-connector-security-maps failed", e);
        report.setMessage(localStrings.getLocalString("" + "list.connector.security.maps.fail", "Unable to list security map {0} for connector connection pool {1}", securityMap, poolName) + " " + e.getLocalizedMessage());
        report.setActionExitCode(ActionReport.ExitCode.FAILURE);
        report.setFailureCause(e);
        return;
    }
    report.setActionExitCode(ActionReport.ExitCode.SUCCESS);
}
Also used : ConnectorConnectionPool(org.glassfish.connectors.config.ConnectorConnectionPool) SecurityMap(org.glassfish.connectors.config.SecurityMap) ActionReport(org.glassfish.api.ActionReport)

Example 5 with SecurityMap

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

the class ConnectorConnectionPoolDeployer method redeployResource.

/**
 * {@inheritDoc}
 */
public synchronized void redeployResource(Object resource) throws Exception {
    // Connector connection pool reconfiguration or
    // change in security maps
    org.glassfish.connectors.config.ConnectorConnectionPool domainCcp = (org.glassfish.connectors.config.ConnectorConnectionPool) resource;
    List<SecurityMap> securityMaps = domainCcp.getSecurityMap();
    // Since 8.1 PE/SE/EE, only if pool has already been deployed in this
    // server-instance earlier, reconfig this pool
    PoolInfo poolInfo = ConnectorsUtil.getPoolInfo(domainCcp);
    if (!runtime.isConnectorConnectionPoolDeployed(poolInfo)) {
        if (_logger.isLoggable(Level.FINE)) {
            _logger.fine("The connector connection pool " + poolInfo + " is either not referred or not yet created in " + "this server instance and pool and hence " + "redeployment is ignored");
        }
        return;
    }
    String rarName = domainCcp.getResourceAdapterName();
    String connDefName = domainCcp.getConnectionDefinitionName();
    List<Property> props = domainCcp.getProperty();
    ConnectorConnectionPool ccp = getConnectorConnectionPool(domainCcp, poolInfo);
    populateConnectorConnectionPool(ccp, connDefName, rarName, props, securityMaps);
    boolean poolRecreateRequired = false;
    try {
        if (_logger.isLoggable(Level.FINE)) {
            _logger.fine("Calling reconfigure pool");
        }
        poolRecreateRequired = runtime.reconfigureConnectorConnectionPool(ccp, new HashSet());
    } catch (ConnectorRuntimeException cre) {
        Object[] params = new Object[] { poolInfo, cre };
        _logger.log(Level.WARNING, "error.reconfiguring.pool", params);
    }
    if (poolRecreateRequired) {
        if (_logger.isLoggable(Level.FINE)) {
            _logger.fine("Pool recreation required");
        }
        runtime.recreateConnectorConnectionPool(ccp);
        if (_logger.isLoggable(Level.FINE)) {
            _logger.fine("Pool recreation done");
        }
    }
}
Also used : ConnectorRuntimeException(com.sun.appserv.connectors.internal.api.ConnectorRuntimeException) 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)

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