Search in sources :

Example 1 with Session

use of org.netxms.api.client.Session in project netxms by netxms.

the class MobileApplicationWorkbenchAdvisor 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 = (RWT.getRequest().getParameter("auto") != null);
    String ssoTicket = RWT.getRequest().getParameter("ticket");
    if (ssoTicket != null) {
        autoLogin = true;
        // $NON-NLS-1$
        String server = RWT.getRequest().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 = RWT.getRequest().getParameter("server");
        if (server == null)
            // $NON-NLS-1$ //$NON-NLS-2$
            server = properties.getProperty("server", "127.0.0.1");
        // $NON-NLS-1$
        String login = RWT.getRequest().getParameter("login");
        if (login == null)
            login = "guest";
        // $NON-NLS-1$
        password = RWT.getRequest().getParameter("password");
        if (password == null)
            password = "";
        success = connectToServer(server, login, password);
    }
    if (!autoLogin || !success) {
        Window loginDialog;
        do {
            loginDialog = BrandingManager.getInstance().getMobileLoginForm(null, 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 Session session = (Session) RWT.getUISession().getAttribute(ConsoleSharedData.ATTRIBUTE_SESSION);
        final Display display = Display.getCurrent();
        session.addListener(new SessionListener() {

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

                        @Override
                        public void run() {
                            String productName = BrandingManager.getInstance().getProductName();
                            MessageDialog.openError(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), Messages.get().ApplicationWorkbenchAdvisor_CommunicationError, ((n.getCode() == SessionNotification.CONNECTION_BROKEN) ? String.format(Messages.get().ApplicationWorkbenchAdvisor_ConnectionLostMessage, productName) : String.format(Messages.get().ApplicationWorkbenchAdvisor_ServerShutdownMessage, productName)) + Messages.get().ApplicationWorkbenchAdvisor_OKToCloseMessage);
                            PlatformUI.getWorkbench().getActiveWorkbenchWindow().close();
                        }
                    });
                }
            }
        });
        try {
            RWT.getSettingStore().loadById(session.getUserName() + "@" + bytesToHexString(session.getServerId()));
        } catch (IOException e) {
        }
    // Suggest user to change password if it is expired
    /*
			if (session.isPasswordExpired())
			{
				final PasswordExpiredDialog dlg = new PasswordExpiredDialog(null);
				if (dlg.open() == Window.OK)
				{
					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);
					}
					catch(InvocationTargetException e)
					{
						MessageDialog.openError(null, "Error", String.format("Cannot change password: %s", e.getCause().getLocalizedMessage()));
					}
					catch(InterruptedException e)
					{
						MessageDialog.openError(null, "Exception", e.toString());
					}
				}
			}
			*/
    }
}
Also used : Window(org.eclipse.jface.window.Window) IOException(java.io.IOException) Properties(java.util.Properties) AppPropertiesLoader(org.netxms.ui.eclipse.console.AppPropertiesLoader) SessionListener(org.netxms.api.client.SessionListener) LoginForm(org.netxms.ui.eclipse.console.api.LoginForm) SessionNotification(org.netxms.api.client.SessionNotification) Session(org.netxms.api.client.Session) Display(org.eclipse.swt.widgets.Display)

Example 2 with Session

use of org.netxms.api.client.Session in project netxms by netxms.

the class MobileApplication method start.

/* (non-Javadoc)
	 * @see org.eclipse.equinox.app.IApplication#start(org.eclipse.equinox.app.IApplicationContext)
	 */
public Object start(IApplicationContext context) throws Exception {
    // $NON-NLS-1$
    String lang = RWT.getRequest().getParameter("lang");
    if (lang != null)
        RWT.setLocale(new Locale(lang));
    final Properties properties = new AppPropertiesLoader().load();
    int timeout;
    try {
        timeout = Integer.parseInt(properties.getProperty("sessionTimeout", "120"));
    } catch (NumberFormatException e) {
        timeout = 120;
    }
    final Display display = PlatformUI.createDisplay();
    RWT.getUISession().getHttpSession().setMaxInactiveInterval(timeout);
    display.disposeExec(new Runnable() {

        public void run() {
            Session session = ConsoleSharedData.getSession();
            if (session != null)
                session.disconnect();
        }
    });
    SharedIcons.init(display);
    WorkbenchAdvisor advisor = new MobileApplicationWorkbenchAdvisor();
    return PlatformUI.createAndRunWorkbench(display, advisor);
}
Also used : Locale(java.util.Locale) WorkbenchAdvisor(org.eclipse.ui.application.WorkbenchAdvisor) AppPropertiesLoader(org.netxms.ui.eclipse.console.AppPropertiesLoader) Properties(java.util.Properties) Display(org.eclipse.swt.widgets.Display) Session(org.netxms.api.client.Session)

Aggregations

Properties (java.util.Properties)2 Display (org.eclipse.swt.widgets.Display)2 Session (org.netxms.api.client.Session)2 AppPropertiesLoader (org.netxms.ui.eclipse.console.AppPropertiesLoader)2 IOException (java.io.IOException)1 Locale (java.util.Locale)1 Window (org.eclipse.jface.window.Window)1 WorkbenchAdvisor (org.eclipse.ui.application.WorkbenchAdvisor)1 SessionListener (org.netxms.api.client.SessionListener)1 SessionNotification (org.netxms.api.client.SessionNotification)1 LoginForm (org.netxms.ui.eclipse.console.api.LoginForm)1