use of org.jvnet.hk2.config.types.Property in project Payara by payara.
the class CreateAuditModule method populateAuditModuleElement.
private void populateAuditModuleElement(AuditModule newAuditModule) throws PropertyVetoException, TransactionFailure {
newAuditModule.setName(auditModuleName);
newAuditModule.setClassname(className);
if (properties != null) {
for (Object propname : properties.keySet()) {
Property newprop = newAuditModule.createChild(Property.class);
newprop.setName((String) propname);
newprop.setValue(properties.getProperty((String) propname));
newAuditModule.getProperty().add(newprop);
}
}
}
use of org.jvnet.hk2.config.types.Property 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
*/
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);
final FileRealm fr = (FileRealm) realmsManager.getFromLoadedRealms(config.getName(), authRealmName);
CreateFileUser.handleAdminGroup(authRealmName, groups);
String[] groups1 = groups.toArray(new String[groups.size()]);
try {
fr.addUser(userName, password.toCharArray(), groups1);
} catch (BadRealmException br) {
if (se != null && se.isDas()) {
throw new BadRealmException(br);
}
}
fr.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.types.Property in project Payara by payara.
the class CreateProfilerTest method testExecuteSuccess.
/**
* Test of execute method, of class CreateProfiler.
* asadmin create-profiler --nativelibrarypath "myNativeLibraryPath"
* --enabled=true --classpath "myProfilerClasspath" testProfiler
*/
@Test
public void testExecuteSuccess() {
// Set the options and operand to pass to the command
parameters.set("classpath", "myProfilerClasspath");
parameters.set("enabled", "true");
parameters.set("nativelibrarypath", "myNativeLibraryPath");
parameters.set("property", "a=x:b=y:c=z");
parameters.set("DEFAULT", "testProfiler");
// Call CommandRunnerImpl.doCommand(..) to execute the command
cr.getCommandInvocation("create-profiler", context.getActionReport(), adminSubject()).parameters(parameters).execute(command);
// Check the exit code is SUCCESS
assertEquals(ActionReport.ExitCode.SUCCESS, context.getActionReport().getActionExitCode());
// Check that the profiler is created
boolean isCreated = false;
int propertyCount = 0;
Profiler profiler = javaConfig.getProfiler();
if (profiler.getName().equals("testProfiler")) {
assertEquals("myProfilerClasspath", profiler.getClasspath());
assertEquals("true", profiler.getEnabled());
assertEquals("myNativeLibraryPath", profiler.getNativeLibraryPath());
List<Property> properties = profiler.getProperty();
for (Property property : properties) {
if (property.getName().equals("a"))
assertEquals("x", property.getValue());
if (property.getName().equals("b"))
assertEquals("y", property.getValue());
if (property.getName().equals("c"))
assertEquals("z", property.getValue());
propertyCount++;
}
isCreated = true;
logger.fine("Profiler element myProfiler is created.");
}
assertTrue(isCreated);
assertEquals(propertyCount, 3);
// Check the exit code is SUCCESS
assertEquals(ActionReport.ExitCode.SUCCESS, context.getActionReport().getActionExitCode());
// Check the success message
// assertEquals("Command create-profiler executed successfully.", context.getActionReport().getMessage());
logger.fine("msg: " + context.getActionReport().getMessage());
}
use of org.jvnet.hk2.config.types.Property in project Payara by payara.
the class LogManagerService method generateAttributeChangeEvent.
public void generateAttributeChangeEvent(String property, String propertyDetail, Map props) {
PropertyChangeEvent pce = new PropertyChangeEvent(this, property, propertyDetail, props.get(property));
UnprocessedChangeEvents ucel = new UnprocessedChangeEvents(new UnprocessedChangeEvent(pce, "server log file attribute " + property + " changed."));
List<UnprocessedChangeEvents> b = new ArrayList();
b.add(ucel);
ucl.unprocessedTransactedEvents(b);
}
use of org.jvnet.hk2.config.types.Property in project Payara by payara.
the class ConfigConfigSource method setValue.
public boolean setValue(final String propertyName, final String propertyValue) throws TransactionFailure {
boolean success = false;
Config config = domainConfiguration.getConfigs().getConfigByName(configurationName);
if (config != null) {
Property p = config.getProperty(PROPERTY_PREFIX + propertyName);
if (p == null) {
ConfigSupport.apply(new SingleConfigCode<Config>() {
@Override
public Object run(Config config) throws TransactionFailure, PropertyVetoException {
Property prop = config.createChild(Property.class);
prop.setName(PROPERTY_PREFIX + propertyName);
prop.setValue(propertyValue);
config.getProperty().add(prop);
return null;
}
}, config);
} else {
ConfigSupport.apply(new SingleConfigCode<Property>() {
@Override
public Object run(Property config) throws TransactionFailure, PropertyVetoException {
config.setValue(propertyValue);
return null;
}
}, p);
}
success = true;
}
return success;
}
Aggregations