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);
}
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);
}
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);
}
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);
}
}
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);
}
Aggregations