use of org.netxms.api.client.SessionListener 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());
}
}
}
*/
}
}
Aggregations