use of com.sun.enterprise.admin.launcher.GFLauncher in project Payara by payara.
the class ChangeAdminPasswordCommand method changeAdminPasswordLocally.
private int changeAdminPasswordLocally(String domainDir, String domainName) throws CommandException {
if (!isLocalHost(programOpts.getHost())) {
throw new CommandException(strings.get("CannotExecuteLocally"));
}
GFLauncher launcher = null;
try {
launcher = GFLauncherFactory.getInstance(RuntimeType.DAS);
GFLauncherInfo info = launcher.getInfo();
info.setDomainName(domainName);
info.setDomainParentDir(domainDir);
launcher.setup();
// throw new exception
if (launcher.isSecureAdminEnabled()) {
if ((newpassword == null) || (newpassword.isEmpty())) {
throw new CommandException(strings.get("NullNewPassword"));
}
}
String adminKeyFile = launcher.getAdminRealmKeyFile();
if (adminKeyFile != null) {
// This is a FileRealm, instantiate it.
FileRealmHelper helper = new FileRealmHelper(adminKeyFile);
// Authenticate the old password
String[] groups = helper.authenticate(programOpts.getUser(), password.toCharArray());
if (groups == null) {
throw new CommandException(strings.get("InvalidCredentials", programOpts.getUser()));
}
helper.updateUser(programOpts.getUser(), programOpts.getUser(), newpassword.toCharArray(), null);
helper.persist();
return SUCCESS;
} else {
// Cannot change password locally for non file realms
throw new CommandException(strings.get("NotFileRealmCannotChangeLocally"));
}
} catch (MiniXmlParserException ex) {
throw new CommandException(ex);
} catch (GFLauncherException ex) {
throw new CommandException(ex);
} catch (IOException ex) {
throw new CommandException(ex);
}
}
Aggregations