use of org.jvnet.hk2.config.TransactionFailure in project Payara by payara.
the class MonitoredAttributeBagResource method put.
/**
* Creates new monitored-attributes. This method deletes all of the existing
* monitored-attributes.
*
* @param attributes the list of monitored-attributes to be created.
* @return a list of the monitored-attributes after the transaction.
*/
@PUT
@Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML, MediaType.APPLICATION_FORM_URLENCODED })
@Produces({ MediaType.TEXT_HTML, MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
public ActionReportResult put(List<Map<String, String>> attributes) {
RestActionReporter ar = new RestActionReporter();
ar.setActionExitCode(ActionReport.ExitCode.SUCCESS);
ar.setActionDescription("monitored-attribute");
try {
setMonitoredAttributes(attributes);
List monitoredAttributes = getMonitoredAttributes();
Properties extraProperties = new Properties();
extraProperties.put("monitoredAttributes", monitoredAttributes);
ar.setExtraProperties(extraProperties);
} catch (TransactionFailure ex) {
ar.setActionExitCode(ActionReport.ExitCode.FAILURE);
ar.setMessage(ex.getMessage());
}
return new ActionReportResult(tagName, ar, new OptionsResult(Util.getResourceName(uriInfo)));
}
use of org.jvnet.hk2.config.TransactionFailure in project Payara by payara.
the class ModuleInfo method save.
/**
* Saves its state to the configuration. this method must be called within a transaction
* to the configured module instance.
*
* @param module the module being persisted
*/
public void save(Module module) throws TransactionFailure, PropertyVetoException {
// write out the module properties only for composite app
if (Boolean.valueOf(moduleProps.getProperty(ServerTags.IS_COMPOSITE))) {
moduleProps.remove(ServerTags.IS_COMPOSITE);
for (Iterator itr = moduleProps.keySet().iterator(); itr.hasNext(); ) {
String propName = (String) itr.next();
Property prop = module.createChild(Property.class);
module.getProperty().add(prop);
prop.setName(propName);
prop.setValue(moduleProps.getProperty(propName));
}
}
for (EngineRef ref : _getEngineRefs()) {
Engine engine = module.createChild(Engine.class);
module.getEngines().add(engine);
ref.save(engine);
}
}
use of org.jvnet.hk2.config.TransactionFailure in project Payara by payara.
the class CreateJACCProvider method configureProperties.
private void configureProperties(JaccProvider newJacc) throws PropertyVetoException, TransactionFailure {
if (properties != null) {
for (Object key : properties.keySet()) {
Object value = properties.get(key);
Property property = newJacc.createChild(Property.class);
property.setName(key.toString());
property.setValue(value.toString());
newJacc.getProperty().add(property);
}
}
}
use of org.jvnet.hk2.config.TransactionFailure 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
*/
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)); */
}
}
use of org.jvnet.hk2.config.TransactionFailure in project Payara by payara.
the class DeleteFileUser 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();
// 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("delete.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 kFile = keyFile;
if (keyFile == null) {
report.setMessage(localStrings.getLocalString("delete.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(kFile)).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[] { kFile, authRealmName }));
report.setActionExitCode(ActionReport.ExitCode.FAILURE);
return;
}
// hypothetically ?.
try {
ConfigSupport.apply(new SingleConfigCode<SecurityService>() {
public Object run(SecurityService param) throws PropertyVetoException, TransactionFailure {
try {
realmsManager.createRealms(config);
final FileRealm fr = (FileRealm) realmsManager.getFromLoadedRealms(config.getName(), authRealmName);
fr.removeUser(userName);
fr.persist();
CreateFileUser.refreshRealm(config.getName(), authRealmName);
report.setActionExitCode(ActionReport.ExitCode.SUCCESS);
} catch (NoSuchUserException e) {
report.setMessage(localStrings.getLocalString("delete.file.user.usernotfound", "There is no such existing user {0} in the file realm {1}.", userName, authRealmName) + " " + e.getLocalizedMessage());
report.setActionExitCode(ActionReport.ExitCode.FAILURE);
report.setFailureCause(e);
} catch (BadRealmException e) {
report.setMessage(localStrings.getLocalString("delete.file.user.realmcorrupted", "Configured file realm {0} is corrupted.", authRealmName) + " " + e.getLocalizedMessage());
report.setActionExitCode(ActionReport.ExitCode.FAILURE);
report.setFailureCause(e);
} catch (Exception e) {
e.printStackTrace();
report.setMessage(localStrings.getLocalString("delete.file.user.userdeletefailed", "Removing User {0} from file realm {1} failed", userName, authRealmName) + " " + e.getLocalizedMessage());
report.setActionExitCode(ActionReport.ExitCode.FAILURE);
report.setFailureCause(e);
}
return null;
}
}, securityService);
} catch (Exception e) {
report.setMessage(localStrings.getLocalString("delete.file.user.userdeletefailed", "Removing User {0} from file realm {1} failed", userName, authRealmName) + " " + e.getLocalizedMessage());
report.setActionExitCode(ActionReport.ExitCode.FAILURE);
report.setFailureCause(e);
}
}
Aggregations