Search in sources :

Example 71 with ActionReport

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

the class CreateConnectorWorkSecurityMap method execute.

// TODO common code replicated in ConnectorWorkSecurityMapManager
/**
 * 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 (mapName == null) {
        report.setMessage(localStrings.getLocalString("create.connector.work.security.map.noMapName", "No mapname defined for connector work security map."));
        report.setActionExitCode(ActionReport.ExitCode.FAILURE);
        return;
    }
    if (raName == null) {
        report.setMessage(localStrings.getLocalString("create.connector.work.security.map.noRaName", "No raname defined for connector work security map."));
        report.setActionExitCode(ActionReport.ExitCode.FAILURE);
        return;
    }
    if (principalsMap == null && groupsMap == null) {
        report.setMessage(localStrings.getLocalString("create.connector.work.security.map.noMap", "No principalsmap or groupsmap defined for connector work security map."));
        report.setActionExitCode(ActionReport.ExitCode.FAILURE);
        return;
    }
    if (principalsMap != null && groupsMap != null) {
        report.setMessage(localStrings.getLocalString("create.connector.work.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" + "--principalsmap or --groupsmap."));
        report.setActionExitCode(ActionReport.ExitCode.FAILURE);
        return;
    }
    // ensure we don't already have one of this name
    if (hasDuplicate(domain.getResources(), report))
        return;
    // TODO ASR : need similar validation while creating app-scoped-resource of w-s-m
    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;
            }
        }
    }
    try {
        ConfigSupport.apply(new SingleConfigCode<Resources>() {

            public Object run(Resources param) throws PropertyVetoException, TransactionFailure {
                WorkSecurityMap workSecurityMap = param.createChild(WorkSecurityMap.class);
                workSecurityMap.setName(mapName);
                workSecurityMap.setResourceAdapterName(raName);
                if (principalsMap != null) {
                    for (Map.Entry e : principalsMap.entrySet()) {
                        PrincipalMap principalMap = workSecurityMap.createChild(PrincipalMap.class);
                        principalMap.setEisPrincipal((String) e.getKey());
                        principalMap.setMappedPrincipal((String) e.getValue());
                        workSecurityMap.getPrincipalMap().add(principalMap);
                    }
                } else if (groupsMap != null) {
                    for (Map.Entry e : groupsMap.entrySet()) {
                        GroupMap groupMap = workSecurityMap.createChild(GroupMap.class);
                        groupMap.setEisGroup((String) e.getKey());
                        groupMap.setMappedGroup((String) e.getValue());
                        workSecurityMap.getGroupMap().add(groupMap);
                    }
                } else {
                // no mapping
                }
                param.getResources().add(workSecurityMap);
                return workSecurityMap;
            }
        }, domain.getResources());
    } catch (TransactionFailure tfe) {
        Logger.getLogger(CreateConnectorWorkSecurityMap.class.getName()).log(Level.SEVERE, "create-connector-work-security-map failed", tfe);
        report.setMessage(localStrings.getLocalString("create.connector.work.security.map.fail", "Unable to create connector work security map {0}.", mapName) + " " + tfe.getLocalizedMessage());
        report.setActionExitCode(ActionReport.ExitCode.FAILURE);
        report.setFailureCause(tfe);
        return;
    }
    report.setActionExitCode(ActionReport.ExitCode.SUCCESS);
}
Also used : TransactionFailure(org.jvnet.hk2.config.TransactionFailure) PrincipalMap(org.glassfish.connectors.config.PrincipalMap) WorkSecurityMap(org.glassfish.connectors.config.WorkSecurityMap) ActionReport(org.glassfish.api.ActionReport) PropertyVetoException(java.beans.PropertyVetoException) GroupMap(org.glassfish.connectors.config.GroupMap) Map(java.util.Map) PrincipalMap(org.glassfish.connectors.config.PrincipalMap) WorkSecurityMap(org.glassfish.connectors.config.WorkSecurityMap) GroupMap(org.glassfish.connectors.config.GroupMap)

Example 72 with ActionReport

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

the class GetConnectorConfigJavaBeans method execute.

/**
 * @inheritDoc
 */
public void execute(AdminCommandContext context) {
    final ActionReport report = context.getActionReport();
    try {
        Properties extraProperties = new Properties();
        Map<String, String> configProps = connectorRuntime.getConnectorConfigJavaBeans(rarName, connectionDefnName, javaBeanType);
        extraProperties.put("configProps", configProps);
        report.setExtraProperties(extraProperties);
    } catch (Exception e) {
        report.setMessage("_get-connector-config-java-beans 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)

Example 73 with ActionReport

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

the class DeleteAdminObject 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 (jndiName == null) {
        report.setMessage(localStrings.getLocalString("delete.admin.object.noJndiName", "No JNDI name defined for administered object."));
        report.setActionExitCode(ActionReport.ExitCode.FAILURE);
        return;
    }
    // ensure we already have this resource
    if (!isResourceExists(domain.getResources(), jndiName)) {
        report.setMessage(localStrings.getLocalString("delete.admin.object.notfound", "An administered object named {0} does not exist.", jndiName));
        report.setActionExitCode(ActionReport.ExitCode.FAILURE);
        return;
    }
    if (environment.isDas()) {
        if (domain.getConfigNamed(target) != null) {
            if (resourceUtil.getTargetsReferringResourceRef(jndiName).size() > 0) {
                report.setMessage(localStrings.getLocalString("delete.admin.object.resource-ref.exist", "admin-object [ {0} ] is referenced in an" + "instance/cluster target, Use delete-resource-ref on appropriate target", jndiName));
                report.setActionExitCode(ActionReport.ExitCode.FAILURE);
                return;
            }
        } else {
            if (!resourceUtil.isResourceRefInTarget(jndiName, target)) {
                report.setMessage(localStrings.getLocalString("delete.admin.object.no.resource-ref", "admin-object [ {0} ] is not referenced in target [ {1} ]", jndiName, target));
                report.setActionExitCode(ActionReport.ExitCode.FAILURE);
                return;
            }
            if (resourceUtil.getTargetsReferringResourceRef(jndiName).size() > 1) {
                report.setMessage(localStrings.getLocalString("delete.admin.object.multiple.resource-refs", "admin-object [ {0} ] is referenced in multiple " + "instance/cluster targets, Use delete-resource-ref on appropriate target", jndiName));
                report.setActionExitCode(ActionReport.ExitCode.FAILURE);
                return;
            }
        }
    }
    try {
        // delete resource-ref
        resourceUtil.deleteResourceRef(jndiName, target);
        // delete admin-object-resource
        if (ConfigSupport.apply(new SingleConfigCode<Resources>() {

            public Object run(Resources param) throws PropertyVetoException, TransactionFailure {
                Resource resource = ConnectorsUtil.getResourceByName(domain.getResources(), AdminObjectResource.class, jndiName);
                return param.getResources().remove(resource);
            }
        }, domain.getResources()) == null) {
            report.setMessage(localStrings.getLocalString("delete.admin.object.fail", "Unable to delete administered object {0}", jndiName));
            report.setActionExitCode(ActionReport.ExitCode.FAILURE);
            return;
        }
    } catch (TransactionFailure tfe) {
        report.setMessage(localStrings.getLocalString("delete.admin.object.fail", "Unable to delete administered object {0}", jndiName) + " " + tfe.getLocalizedMessage());
        report.setActionExitCode(ActionReport.ExitCode.FAILURE);
        report.setFailureCause(tfe);
    }
    report.setMessage(localStrings.getLocalString("delete.admin.object.success", "Administered object {0} deleted", jndiName));
    report.setActionExitCode(ActionReport.ExitCode.SUCCESS);
}
Also used : TransactionFailure(org.jvnet.hk2.config.TransactionFailure) SingleConfigCode(org.jvnet.hk2.config.SingleConfigCode) AdminObjectResource(org.glassfish.connectors.config.AdminObjectResource) Resource(com.sun.enterprise.config.serverbeans.Resource) Resources(com.sun.enterprise.config.serverbeans.Resources) ActionReport(org.glassfish.api.ActionReport)

Example 74 with ActionReport

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

the class DeleteConnectorWorkSecurityMap 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();
    // ensure we already have this resource
    if (!isResourceExists()) {
        report.setMessage(localStrings.getLocalString("delete.connector.work.security.map.notFound", "A connector work security map named {0} for resource adapter {1} does not exist.", mapName, raName));
        report.setActionExitCode(ActionReport.ExitCode.FAILURE);
        return;
    }
    try {
        // delete connector-work-security-map
        ConfigSupport.apply(new SingleConfigCode<Resources>() {

            Collection<WorkSecurityMap> workSecurityMaps = domain.getResources().getResources(WorkSecurityMap.class);

            public Object run(Resources param) throws PropertyVetoException, TransactionFailure {
                for (WorkSecurityMap resource : workSecurityMaps) {
                    if (resource.getName().equals(mapName) && resource.getResourceAdapterName().equals(raName)) {
                        param.getResources().remove(resource);
                        break;
                    }
                }
                return workSecurityMaps;
            }
        }, domain.getResources());
    } catch (TransactionFailure tfe) {
        Logger.getLogger(DeleteConnectorWorkSecurityMap.class.getName()).log(Level.SEVERE, "delete-connector-work-security-map failed", tfe);
        report.setMessage(localStrings.getLocalString("" + "delete.connector.work.security.map.fail", "Unable to delete connector work security map {0} for resource adapter {1}", mapName, raName) + " " + 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) WorkSecurityMap(org.glassfish.connectors.config.WorkSecurityMap) Resources(com.sun.enterprise.config.serverbeans.Resources) ActionReport(org.glassfish.api.ActionReport)

Example 75 with ActionReport

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

the class GetMessageListenerConfigPropertyTypes method execute.

/**
 * @inheritDoc
 */
public void execute(AdminCommandContext context) {
    final ActionReport report = context.getActionReport();
    try {
        Map<String, String> messageListenerConfigPropTypes = connectorRuntime.getMessageListenerConfigPropTypes(rarName, messageListenerType);
        Properties extraProperties = new Properties();
        extraProperties.put("messageListenerConfigPropTypes", messageListenerConfigPropTypes);
        report.setExtraProperties(extraProperties);
    } catch (Exception e) {
        report.setMessage("_get-message-listener-config-property-types : " + 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