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());
}
}
}
}
}
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());
}
}
}
Aggregations