use of org.jvnet.hk2.config.SingleConfigCode in project Payara by payara.
the class HoggingThreadsConfigurer method execute.
@Override
public void execute(AdminCommandContext context) {
Config config = targetUtil.getConfig(target);
HoggingThreadsHealthCheck service = habitat.getService(HoggingThreadsHealthCheck.class);
final ActionReport actionReport = context.getActionReport();
if (service == null) {
actionReport.appendMessage(strings.getLocalString("healthcheck.hoggingthreads.configure.status.error", "Hogging Threads Checker Service could not be found"));
actionReport.setActionExitCode(ActionReport.ExitCode.FAILURE);
return;
}
// Warn about deprecated option
if (name != null) {
actionReport.appendMessage("\n--name parameter is decremented, please begin using the --checkerName option\n");
}
try {
HealthCheckServiceConfiguration healthCheckServiceConfiguration = config.getExtensionByType(HealthCheckServiceConfiguration.class);
HoggingThreadsChecker hoggingThreadConfiguration = healthCheckServiceConfiguration.getCheckerByType(HoggingThreadsChecker.class);
if (hoggingThreadConfiguration == null) {
ConfigSupport.apply(new SingleConfigCode<HealthCheckServiceConfiguration>() {
@Override
public Object run(final HealthCheckServiceConfiguration healthCheckServiceConfigurationProxy) throws PropertyVetoException, TransactionFailure {
HoggingThreadsChecker checkerProxy = healthCheckServiceConfigurationProxy.createChild(HoggingThreadsChecker.class);
applyValues(checkerProxy);
healthCheckServiceConfigurationProxy.getCheckerList().add(checkerProxy);
actionReport.setActionExitCode(ActionReport.ExitCode.SUCCESS);
return healthCheckServiceConfigurationProxy;
}
}, healthCheckServiceConfiguration);
} else {
ConfigSupport.apply(new SingleConfigCode<HoggingThreadsChecker>() {
@Override
public Object run(final HoggingThreadsChecker hoggingThreadConfigurationProxy) throws PropertyVetoException, TransactionFailure {
applyValues(hoggingThreadConfigurationProxy);
actionReport.setActionExitCode(ActionReport.ExitCode.SUCCESS);
return hoggingThreadConfigurationProxy;
}
}, hoggingThreadConfiguration);
}
if (dynamic) {
if (server.isDas()) {
if (targetUtil.getConfig(target).isDas()) {
HoggingThreadsChecker checkerByType = healthCheckServiceConfiguration.getCheckerByType(HoggingThreadsChecker.class);
service.setOptions(service.constructOptions(checkerByType));
healthCheckService.registerCheck(checkerByType.getName(), service);
healthCheckService.reboot();
}
} else {
// it implicitly targetted to us as we are not the DAS
// restart the service
HoggingThreadsChecker checkerByType = healthCheckServiceConfiguration.getCheckerByType(HoggingThreadsChecker.class);
service.setOptions(service.constructOptions(hoggingThreadConfiguration));
healthCheckService.registerCheck(checkerByType.getName(), service);
healthCheckService.reboot();
}
}
} catch (TransactionFailure ex) {
logger.log(Level.WARNING, "Exception during command ", ex);
actionReport.setMessage(ex.getCause().getMessage());
actionReport.setActionExitCode(ActionReport.ExitCode.FAILURE);
}
}
use of org.jvnet.hk2.config.SingleConfigCode in project Payara by payara.
the class DisablePhoneHome method execute.
@Override
public void execute(AdminCommandContext context) {
final ActionReport report = context.getActionReport();
try {
ConfigSupport.apply(new SingleConfigCode<PhoneHomeRuntimeConfiguration>() {
@Override
public Object run(PhoneHomeRuntimeConfiguration configurationProxy) throws PropertyVetoException, TransactionFailure {
configurationProxy.setEnabled("false");
return configurationProxy;
}
}, configuration);
} catch (TransactionFailure ex) {
report.setActionExitCode(ActionReport.ExitCode.FAILURE);
}
service.stop();
report.setMessage("Phone Home Service is disabled");
report.setActionExitCode(ActionReport.ExitCode.SUCCESS);
}
use of org.jvnet.hk2.config.SingleConfigCode in project Payara by payara.
the class EnablePhoneHome method execute.
@Override
public void execute(AdminCommandContext context) {
final ActionReport report = context.getActionReport();
try {
ConfigSupport.apply(new SingleConfigCode<PhoneHomeRuntimeConfiguration>() {
@Override
public Object run(PhoneHomeRuntimeConfiguration configurationProxy) throws PropertyVetoException, TransactionFailure {
configurationProxy.setEnabled("true");
return configurationProxy;
}
}, configuration);
} catch (TransactionFailure ex) {
report.setActionExitCode(ActionReport.ExitCode.FAILURE);
}
service.start();
report.setMessage("Phone Home Service is enabled");
report.setActionExitCode(ActionReport.ExitCode.SUCCESS);
}
use of org.jvnet.hk2.config.SingleConfigCode in project Payara by payara.
the class CreateFileUser 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
*/
@Override
public void execute(AdminCommandContext context) {
final ActionReport report = context.getActionReport();
// Get FileRealm class name, match it with what is expected.
String fileRealmClassName = fileAuthRealm.getClassname();
// Report error if provided impl is not the one expected
if (fileRealmClassName != null && !fileRealmClassName.equals("com.sun.enterprise.security.auth.realm.file.FileRealm")) {
report.setMessage(localStrings.getLocalString("create.file.user.realmnotsupported", "Configured file realm {0} is not supported.", fileRealmClassName));
report.setActionExitCode(ActionReport.ExitCode.FAILURE);
return;
}
// Ensure we have the file associated with the authrealm
String keyFile = null;
for (Property fileProp : fileAuthRealm.getProperty()) {
if (fileProp.getName().equals("file"))
keyFile = fileProp.getValue();
}
final String kf = keyFile;
if (keyFile == null) {
report.setMessage(localStrings.getLocalString("create.file.user.keyfilenotfound", "There is no physical file associated with this file realm {0} ", authRealmName));
report.setActionExitCode(ActionReport.ExitCode.FAILURE);
return;
}
boolean exists = (new File(kf)).exists();
if (!exists) {
report.setMessage(localStrings.getLocalString("file.realm.keyfilenonexistent", "The specified physical file {0} associated with the file realm {1} does not exist.", new Object[] { kf, authRealmName }));
report.setActionExitCode(ActionReport.ExitCode.FAILURE);
return;
}
// Now get all inputs ready. userid and groups are straightforward but
// password is tricky. It is stored in the file passwordfile passed
// through the CLI options. It is stored under the name
// AS_ADMIN_USERPASSWORD. Fetch it from there.
// fetchPassword(report);
final String password = userpassword;
if (password == null) {
report.setMessage(localStrings.getLocalString("create.file.user.keyfilenotreadable", "Password for user {0} " + "has to be specified in --userpassword option or supplied " + "through AS_ADMIN_USERPASSWORD property in the file specified " + "in --passwordfile option", userName));
report.setActionExitCode(ActionReport.ExitCode.FAILURE);
return;
}
// Issue 17525 Fix - Check for null passwords for admin-realm if secureadmin is enabled
secureAdmin = domain.getSecureAdmin();
if ((SecureAdmin.Util.isEnabled(secureAdmin)) && (authRealmName.equals(adminService.getAuthRealmName()))) {
if (password.isEmpty()) {
report.setMessage(localStrings.getLocalString("null_empty_password", "The admin user password is null or empty"));
report.setActionExitCode(ActionReport.ExitCode.FAILURE);
return;
}
}
// now adding user
try {
// even though create-file-user is not an update to the security-service
// do we need to make it transactional by referncing the securityservice
// hypothetically ?.
ConfigSupport.apply(new SingleConfigCode<SecurityService>() {
public Object run(SecurityService param) throws PropertyVetoException, TransactionFailure {
try {
realmsManager.createRealms(config);
// If the (shared) keyfile is updated by an external process, load the users first
refreshRealm(config.getName(), authRealmName);
FileRealm fileRealm = (FileRealm) realmsManager.getFromLoadedRealms(config.getName(), authRealmName);
CreateFileUser.handleAdminGroup(authRealmName, groups);
String[] groups1 = groups.toArray(new String[groups.size()]);
fileRealm.addUser(userName, password.toCharArray(), groups1);
fileRealm.persist();
report.setActionExitCode(ActionReport.ExitCode.SUCCESS);
} catch (Exception e) {
String localalizedErrorMsg = (e.getLocalizedMessage() == null) ? "" : e.getLocalizedMessage();
report.setMessage(localStrings.getLocalString("create.file.user.useraddfailed", "Adding User {0} to the file realm {1} failed", userName, authRealmName) + " " + localalizedErrorMsg);
report.setActionExitCode(ActionReport.ExitCode.FAILURE);
report.setFailureCause(e);
}
return null;
}
}, securityService);
} catch (Exception e) {
report.setMessage(localStrings.getLocalString("create.file.user.useraddfailed", "Adding User {0} to the file realm {1} failed", userName, authRealmName) + " " + e.getLocalizedMessage());
report.setActionExitCode(ActionReport.ExitCode.FAILURE);
report.setFailureCause(e);
}
}
use of org.jvnet.hk2.config.SingleConfigCode in project Payara by payara.
the class CreateMessageSecurityProvider method execute.
/**
* Executes the command with the command parameters passed as Properties
* where the keys are parameter names and the values the parameter values
*
* @param context information
*/
@Override
public void execute(AdminCommandContext context) {
final ActionReport report = context.getActionReport();
List<MessageSecurityConfig> mscs = secService.getMessageSecurityConfig();
// Let's find the correct MessageSecurityConfig. As of now,
// there can be only two of them - one for SOAP and one for
// HttpServlet
MessageSecurityConfig msgSecCfg = null;
for (MessageSecurityConfig msc : mscs) {
if (msc.getAuthLayer().equals(authLayer)) {
msgSecCfg = msc;
}
}
// then, add a new provider config under it provided it is not duplicate
if (msgSecCfg != null) {
// check if there exists a provider config by the
// specified provider name; if so return failure.
List<ProviderConfig> pcs = msgSecCfg.getProviderConfig();
for (ProviderConfig pc : pcs) {
if (pc.getProviderId().equals(providerId)) {
report.setMessage(localStrings.getLocalString("create.message.security.provider.duplicatefound", "Message security provider named {0} exists. " + "Cannot add duplicate.", providerId));
report.setActionExitCode(ActionReport.ExitCode.FAILURE);
return;
}
}
// No duplicate message security providers found. So add one.
try {
ConfigSupport.apply(new SingleConfigCode<MessageSecurityConfig>() {
public Object run(MessageSecurityConfig param) throws PropertyVetoException, TransactionFailure {
ProviderConfig newPC = param.createChild(ProviderConfig.class);
populateProviderConfigElement(newPC);
param.getProviderConfig().add(newPC);
// security config object
if (isDefaultProvider) {
if (providerType.equals(SERVER) || providerType.equals(CLIENT_SERVER)) {
param.setDefaultProvider(providerId);
}
if (providerType.equals(CLIENT) || providerType.equals(CLIENT_SERVER)) {
param.setDefaultClientProvider(providerId);
}
}
return newPC;
}
}, msgSecCfg);
} catch (TransactionFailure e) {
report.setMessage(localStrings.getLocalString("create.message.security.provider.fail", "Creation of message security provider named {0} failed", providerId));
report.setActionExitCode(ActionReport.ExitCode.FAILURE);
report.setFailureCause(e);
return;
}
report.setActionExitCode(ActionReport.ExitCode.SUCCESS);
report.setMessage(localStrings.getLocalString("create.message.security.provider.success", "Creation of message security provider named {0} completed " + "successfully", providerId));
} else // Now if there is NO message security config for this type of layer
// then, first add a message security config for the layer and then
// add a provider config under this message security config
{
try {
ConfigSupport.apply(new SingleConfigCode<SecurityService>() {
public Object run(SecurityService param) throws PropertyVetoException, TransactionFailure {
MessageSecurityConfig newMSC = param.createChild(MessageSecurityConfig.class);
newMSC.setAuthLayer(authLayer);
param.getMessageSecurityConfig().add(newMSC);
ProviderConfig newPC = newMSC.createChild(ProviderConfig.class);
populateProviderConfigElement(newPC);
newMSC.getProviderConfig().add(newPC);
// security config object
if (isDefaultProvider) {
if (providerType.equals(SERVER) || providerType.equals(CLIENT_SERVER)) {
newMSC.setDefaultProvider(providerId);
}
if (providerType.equals(CLIENT) || providerType.equals(CLIENT_SERVER)) {
newMSC.setDefaultClientProvider(providerId);
}
}
return newMSC;
}
}, secService);
} catch (TransactionFailure e) {
report.setMessage(localStrings.getLocalString("create.message.security.provider.fail", "Creation of message security provider named {0} failed", providerId));
report.setActionExitCode(ActionReport.ExitCode.FAILURE);
report.setFailureCause(e);
return;
}
report.setActionExitCode(ActionReport.ExitCode.SUCCESS);
/* report.setMessage(localStrings.getLocalString(
"create.message.security.provider.success",
"Creation of message security provider named {0} completed " +
"successfully", providerId)); */
}
}
Aggregations