Search in sources :

Example 51 with ActionReport

use of org.glassfish.api.ActionReport 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 52 with ActionReport

use of org.glassfish.api.ActionReport in project Payara by payara.

the class CreateResourceAdapterConfig 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();
    HashMap attrList = new HashMap();
    attrList.put(RESOURCE_ADAPTER_CONFIG_NAME, raName);
    // attrList.put("name", name);
    attrList.put(THREAD_POOL_IDS, threadPoolIds);
    attrList.put(ServerTags.OBJECT_TYPE, objectType);
    ResourceStatus rs;
    // TODO ASR : need similar validation while creating app-scoped-resource of resource-adapter-config
    String appName = raName;
    if (!ConnectorsUtil.isStandAloneRA(raName)) {
        appName = ConnectorsUtil.getApplicationNameOfEmbeddedRar(raName);
        Application application = applications.getApplication(appName);
        if (application != null) {
            // embedded RAR
            String resourceAdapterName = ConnectorsUtil.getRarNameFromApplication(raName);
            Module module = application.getModule(resourceAdapterName);
            if (module != null) {
                Resources msr = module.getResources();
                if (msr != null) {
                    if (hasDuplicate(msr, report))
                        return;
                }
            }
        }
    } else {
        // standalone RAR
        Application application = applications.getApplication(appName);
        if (application != null) {
            Resources appScopedResources = application.getResources();
            if (appScopedResources != null) {
                if (hasDuplicate(appScopedResources, report))
                    return;
            }
        }
    }
    ResourceAdapterConfigManager resAdapterConfigMgr = new ResourceAdapterConfigManager();
    try {
        rs = resAdapterConfigMgr.create(domain.getResources(), attrList, properties, target);
    } catch (Exception ex) {
        Logger.getLogger(CreateResourceAdapterConfig.class.getName()).log(Level.SEVERE, "Unable to create resource adapter config for " + raName, ex);
        String def = "Resource adapter config: {0} could not be created, reason: {1}";
        report.setMessage(localStrings.getLocalString("create.resource.adapter.config.fail", def, raName) + " " + ex.getLocalizedMessage());
        report.setActionExitCode(ActionReport.ExitCode.FAILURE);
        report.setFailureCause(ex);
        return;
    }
    ActionReport.ExitCode ec = ActionReport.ExitCode.SUCCESS;
    if (rs.getStatus() == ResourceStatus.FAILURE) {
        ec = ActionReport.ExitCode.FAILURE;
        if (rs.getMessage() != null) {
            report.setMessage(rs.getMessage());
        } else {
            report.setMessage(localStrings.getLocalString("create.resource.adapter.config.fail", "Resource adapter config {0} creation failed", raName, ""));
        }
        if (rs.getException() != null)
            report.setFailureCause(rs.getException());
    }
    report.setActionExitCode(ec);
}
Also used : HashMap(java.util.HashMap) ResourceStatus(org.glassfish.resourcebase.resources.api.ResourceStatus) ActionReport(org.glassfish.api.ActionReport)

Example 53 with ActionReport

use of org.glassfish.api.ActionReport in project Payara by payara.

the class ListConnectorResources 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();
    try {
        Collection<ConnectorResource> connectorResources = domain.getResources().getResources(ConnectorResource.class);
        for (ConnectorResource resource : connectorResources) {
            if (bindableResourcesHelper.resourceExists(resource.getJndiName(), target)) {
                ActionReport.MessagePart part = report.getTopMessagePart().addChild();
                part.setMessage(resource.getJndiName());
            }
        }
    } catch (Exception e) {
        report.setMessage(localStrings.getLocalString("list.connector.resources.fail", "List connector resources failed") + " " + e.getLocalizedMessage());
        report.setActionExitCode(ActionReport.ExitCode.FAILURE);
        report.setFailureCause(e);
        return;
    }
    report.setActionExitCode(ActionReport.ExitCode.SUCCESS);
}
Also used : ActionReport(org.glassfish.api.ActionReport) ConnectorResource(org.glassfish.connectors.config.ConnectorResource)

Example 54 with ActionReport

use of org.glassfish.api.ActionReport in project Payara by payara.

the class PingConnectionPool 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();
    boolean status = false;
    Resources resources = domain.getResources();
    String scope = "";
    if (moduleName != null) {
        if (!poolUtil.isValidModule(applicationName, moduleName, poolName, report)) {
            return;
        }
        Application application = applications.getApplication(applicationName);
        Module module = application.getModule(moduleName);
        resources = module.getResources();
        scope = "java:module/";
    } else if (applicationName != null) {
        if (!poolUtil.isValidApplication(applicationName, poolName, report)) {
            return;
        }
        Application application = applications.getApplication(applicationName);
        resources = application.getResources();
        scope = "java:app/";
    }
    if (!poolUtil.isValidPool(resources, poolName, scope, report)) {
        return;
    }
    PoolInfo poolInfo = new PoolInfo(poolName, applicationName, moduleName);
    try {
        status = connRuntime.pingConnectionPool(poolInfo);
        if (status) {
            report.setActionExitCode(ActionReport.ExitCode.SUCCESS);
        } else {
            report.setActionExitCode(ActionReport.ExitCode.FAILURE);
            report.setMessage(localStrings.getLocalString("ping.connection.pool.fail", "Ping Connection Pool for {0} Failed", poolInfo));
        }
    } catch (Exception e) {
        report.setMessage(localStrings.getLocalString("ping.connection.pool.fail", "Ping Connection Pool for {0} Failed", poolInfo));
        report.setActionExitCode(ActionReport.ExitCode.FAILURE);
        report.setFailureCause(e);
    }
}
Also used : PoolInfo(org.glassfish.resourcebase.resources.api.PoolInfo) ActionReport(org.glassfish.api.ActionReport)

Example 55 with ActionReport

use of org.glassfish.api.ActionReport in project Payara by payara.

the class GetAdminObjectInterfaceNames method execute.

/**
 * @inheritDoc
 */
public void execute(AdminCommandContext context) {
    final ActionReport report = context.getActionReport();
    try {
        String[] adminObjectInterfaceNames = connectorRuntime.getAdminObjectInterfaceNames(rarName);
        Properties extraProperties = new Properties();
        if (adminObjectInterfaceNames != null) {
            extraProperties.put("adminObjectInterfaceNames", Arrays.asList(adminObjectInterfaceNames));
        }
        report.setExtraProperties(extraProperties);
    } catch (Exception e) {
        report.setMessage("_get-admin-object-interface-names failed : " + e.getMessage());
        report.setActionExitCode(ActionReport.ExitCode.FAILURE);
        report.setFailureCause(e);
        return;
    }
    ActionReport.ExitCode ec = ActionReport.ExitCode.SUCCESS;
    report.setActionExitCode(ec);
}
Also used : ActionReport(org.glassfish.api.ActionReport) Properties(java.util.Properties)

Aggregations

ActionReport (org.glassfish.api.ActionReport)508 TransactionFailure (org.jvnet.hk2.config.TransactionFailure)86 Properties (java.util.Properties)83 Config (com.sun.enterprise.config.serverbeans.Config)73 PropertyVetoException (java.beans.PropertyVetoException)72 ParameterMap (org.glassfish.api.admin.ParameterMap)66 Logger (java.util.logging.Logger)56 IOException (java.io.IOException)47 ArrayList (java.util.ArrayList)47 HashMap (java.util.HashMap)43 File (java.io.File)41 CommandTarget (org.glassfish.config.support.CommandTarget)30 Target (org.glassfish.internal.api.Target)30 Map (java.util.Map)27 Server (com.sun.enterprise.config.serverbeans.Server)25 List (java.util.List)25 ServiceLocator (org.glassfish.hk2.api.ServiceLocator)24 CommandRunner (org.glassfish.api.admin.CommandRunner)23 ExtendedDeploymentContext (org.glassfish.internal.deployment.ExtendedDeploymentContext)23 DeployCommandParameters (org.glassfish.api.deployment.DeployCommandParameters)19