Search in sources :

Example 1 with PasswordExpiredDialog

use of org.netxms.ui.eclipse.console.dialogs.PasswordExpiredDialog in project netxms by netxms.

the class ApplicationWorkbenchAdvisor method doLogin.

/**
 * Show login dialog and perform login
 */
private void doLogin() {
    boolean success = false;
    final Properties properties = new AppPropertiesLoader().load();
    String password = "";
    // $NON-NLS-1$
    boolean autoLogin = (Application.getParameter("auto") != null);
    String ssoTicket = Application.getParameter("ticket");
    if (ssoTicket != null) {
        autoLogin = true;
        // $NON-NLS-1$
        String server = Application.getParameter("server");
        if (server == null)
            // $NON-NLS-1$ //$NON-NLS-2$
            server = properties.getProperty("server", "127.0.0.1");
        success = connectToServer(server, null, ssoTicket);
    } else if (autoLogin) {
        // $NON-NLS-1$
        String server = Application.getParameter("server");
        if (server == null)
            // $NON-NLS-1$ //$NON-NLS-2$
            server = properties.getProperty("server", "127.0.0.1");
        // $NON-NLS-1$
        String login = Application.getParameter("login");
        if (login == null)
            login = "guest";
        // $NON-NLS-1$
        password = Application.getParameter("password");
        if (password == null)
            password = "";
        success = connectToServer(server, login, password);
    }
    if (!autoLogin || !success) {
        Window loginDialog;
        do {
            loginDialog = BrandingManager.getInstance().getLoginForm(Display.getCurrent().getActiveShell(), properties);
            if (loginDialog.open() != Window.OK)
                continue;
            password = ((LoginForm) loginDialog).getPassword();
            success = connectToServer(// $NON-NLS-1$ //$NON-NLS-2$
            properties.getProperty("server", "127.0.0.1"), ((LoginForm) loginDialog).getLogin(), password);
        } while (!success);
    }
    if (success) {
        final NXCSession session = (NXCSession) RWT.getUISession().getAttribute(ConsoleSharedData.ATTRIBUTE_SESSION);
        final Display display = Display.getCurrent();
        session.addListener(new SessionListener() {

            private final Object MONITOR = new Object();

            @Override
            public void notificationHandler(final SessionNotification n) {
                if ((n.getCode() == SessionNotification.CONNECTION_BROKEN) || (n.getCode() == SessionNotification.SERVER_SHUTDOWN) || (n.getCode() == SessionNotification.SESSION_KILLED)) {
                    display.asyncExec(new Runnable() {

                        @Override
                        public void run() {
                            RWT.getUISession().setAttribute("NoPageReload", Boolean.TRUE);
                            PlatformUI.getWorkbench().close();
                            String productName = BrandingManager.getInstance().getProductName();
                            String msg = (n.getCode() == SessionNotification.CONNECTION_BROKEN) ? String.format(Messages.get().ApplicationWorkbenchAdvisor_ConnectionLostMessage, productName) : ((n.getCode() == SessionNotification.SESSION_KILLED) ? "Communication session was terminated by system administrator" : String.format(Messages.get().ApplicationWorkbenchAdvisor_ServerShutdownMessage, productName));
                            JavaScriptExecutor executor = RWT.getClient().getService(JavaScriptExecutor.class);
                            if (executor != null)
                                executor.execute("document.body.innerHTML='" + "<div style=\"position: absolute; top: 0; left: 0; width: 100%; height: 100%; background-image: none; background-color: white;\">" + "<p style=\"margin-top: 30px; margin-left: 30px; color: #800000; font-family: \"Segoe UI\", Verdana, Arial, sans-serif; font-weight: bold; font-size: 2em;\">" + msg + "</p><br/>" + "<button style=\"margin-left: 30px\" onclick=\"location.reload(true)\">RELOAD</button>" + "</div>';");
                            synchronized (MONITOR) {
                                MONITOR.notifyAll();
                            }
                        }
                    });
                    synchronized (MONITOR) {
                        try {
                            MONITOR.wait(5000);
                        } catch (InterruptedException e) {
                        }
                    }
                    ((UISessionImpl) RWT.getUISession(display)).shutdown();
                }
            }
        });
        try {
            RWT.getSettingStore().loadById(session.getUserName() + "@" + session.getServerId());
        } catch (IOException e) {
        }
        // Suggest user to change password if it is expired
        if (session.isPasswordExpired()) {
            final PasswordExpiredDialog dlg = new PasswordExpiredDialog(null, session.getGraceLogins());
            while (true) {
                if (dlg.open() != Window.OK)
                    return;
                final String currentPassword = password;
                IRunnableWithProgress job = new IRunnableWithProgress() {

                    @Override
                    public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
                        try {
                            NXCSession session = (NXCSession) RWT.getUISession(display).getAttribute(ConsoleSharedData.ATTRIBUTE_SESSION);
                            session.setUserPassword(session.getUserId(), dlg.getPassword(), currentPassword);
                        } catch (Exception e) {
                            throw new InvocationTargetException(e);
                        } finally {
                            monitor.done();
                        }
                    }
                };
                try {
                    ProgressMonitorDialog pd = new ProgressMonitorDialog(null);
                    pd.run(false, false, job);
                    MessageDialog.openInformation(null, Messages.get().ApplicationWorkbenchWindowAdvisor_Information, Messages.get().ApplicationWorkbenchWindowAdvisor_PasswordChanged);
                    return;
                } catch (InvocationTargetException e) {
                    MessageDialog.openError(null, Messages.get().ApplicationWorkbenchWindowAdvisor_Error, Messages.get().ApplicationWorkbenchWindowAdvisor_CannotChangePswd + e.getCause().getLocalizedMessage());
                } catch (InterruptedException e) {
                    MessageDialog.openError(null, Messages.get().ApplicationWorkbenchWindowAdvisor_Exception, e.toString());
                }
            }
        }
    }
}
Also used : Window(org.eclipse.jface.window.Window) NXCSession(org.netxms.client.NXCSession) ProgressMonitorDialog(org.eclipse.jface.dialogs.ProgressMonitorDialog) JavaScriptExecutor(org.eclipse.rap.rwt.client.service.JavaScriptExecutor) IOException(java.io.IOException) Properties(java.util.Properties) IOException(java.io.IOException) InvocationTargetException(java.lang.reflect.InvocationTargetException) InvocationTargetException(java.lang.reflect.InvocationTargetException) IRunnableWithProgress(org.eclipse.jface.operation.IRunnableWithProgress) PasswordExpiredDialog(org.netxms.ui.eclipse.console.dialogs.PasswordExpiredDialog) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) SessionListener(org.netxms.client.SessionListener) LoginForm(org.netxms.ui.eclipse.console.api.LoginForm) SessionNotification(org.netxms.client.SessionNotification) Display(org.eclipse.swt.widgets.Display)

Example 2 with PasswordExpiredDialog

use of org.netxms.ui.eclipse.console.dialogs.PasswordExpiredDialog in project netxms by netxms.

the class ApplicationWorkbenchWindowAdvisor method requestPasswordChange.

/**
 * @param currentPassword
 * @param session
 */
private void requestPasswordChange(final String currentPassword, final NXCSession session) {
    final PasswordExpiredDialog dlg = new PasswordExpiredDialog(null, session.getGraceLogins());
    while (true) {
        if (dlg.open() != Window.OK)
            return;
        IRunnableWithProgress job = new IRunnableWithProgress() {

            @Override
            public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
                try {
                    monitor.setTaskName(Messages.get().ApplicationWorkbenchWindowAdvisor_ChangingPassword);
                    session.setUserPassword(session.getUserId(), dlg.getPassword(), currentPassword);
                    // $NON-NLS-1$
                    monitor.setTaskName("");
                } catch (Exception e) {
                    throw new InvocationTargetException(e);
                } finally {
                    monitor.done();
                }
            }
        };
        try {
            ModalContext.run(job, true, SplashHandler.getInstance().getBundleProgressMonitor(), Display.getCurrent());
            MessageDialog.openInformation(null, Messages.get().ApplicationWorkbenchWindowAdvisor_Information, Messages.get().ApplicationWorkbenchWindowAdvisor_PasswordChanged);
            return;
        } catch (InvocationTargetException e) {
            MessageDialog.openError(null, Messages.get().ApplicationWorkbenchWindowAdvisor_Error, // $NON-NLS-1$
            Messages.get().ApplicationWorkbenchWindowAdvisor_CannotChangePswd + " " + e.getCause().getLocalizedMessage());
        } catch (InterruptedException e) {
            MessageDialog.openError(null, Messages.get().ApplicationWorkbenchWindowAdvisor_Exception, e.toString());
        }
    }
}
Also used : PasswordExpiredDialog(org.netxms.ui.eclipse.console.dialogs.PasswordExpiredDialog) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) PartInitException(org.eclipse.ui.PartInitException) InvocationTargetException(java.lang.reflect.InvocationTargetException) NXCException(org.netxms.client.NXCException) InvocationTargetException(java.lang.reflect.InvocationTargetException) IRunnableWithProgress(org.eclipse.jface.operation.IRunnableWithProgress)

Aggregations

InvocationTargetException (java.lang.reflect.InvocationTargetException)2 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)2 IRunnableWithProgress (org.eclipse.jface.operation.IRunnableWithProgress)2 PasswordExpiredDialog (org.netxms.ui.eclipse.console.dialogs.PasswordExpiredDialog)2 IOException (java.io.IOException)1 Properties (java.util.Properties)1 ProgressMonitorDialog (org.eclipse.jface.dialogs.ProgressMonitorDialog)1 Window (org.eclipse.jface.window.Window)1 JavaScriptExecutor (org.eclipse.rap.rwt.client.service.JavaScriptExecutor)1 Display (org.eclipse.swt.widgets.Display)1 PartInitException (org.eclipse.ui.PartInitException)1 NXCException (org.netxms.client.NXCException)1 NXCSession (org.netxms.client.NXCSession)1 SessionListener (org.netxms.client.SessionListener)1 SessionNotification (org.netxms.client.SessionNotification)1 LoginForm (org.netxms.ui.eclipse.console.api.LoginForm)1