Search in sources :

Example 1 with GFLauncherInfo

use of com.sun.enterprise.admin.launcher.GFLauncherInfo 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);
    }
}
Also used : FileRealmHelper(org.glassfish.security.common.FileRealmHelper) GFLauncher(com.sun.enterprise.admin.launcher.GFLauncher) GFLauncherException(com.sun.enterprise.admin.launcher.GFLauncherException) MiniXmlParserException(com.sun.enterprise.universal.xml.MiniXmlParserException) IOException(java.io.IOException) GFLauncherInfo(com.sun.enterprise.admin.launcher.GFLauncherInfo)

Aggregations

GFLauncher (com.sun.enterprise.admin.launcher.GFLauncher)1 GFLauncherException (com.sun.enterprise.admin.launcher.GFLauncherException)1 GFLauncherInfo (com.sun.enterprise.admin.launcher.GFLauncherInfo)1 MiniXmlParserException (com.sun.enterprise.universal.xml.MiniXmlParserException)1 IOException (java.io.IOException)1 FileRealmHelper (org.glassfish.security.common.FileRealmHelper)1