- // final ILoginContext loginContext = SecureRapActivator
- // .createLoginContext(SecureRapActivator.CONTEXT_SPRING);
- // tryLogin: while (subject == null && !display.isDisposed()) {
- // try {
- // loginContext.login();
- // subject = loginContext.getSubject();
- //
- // // add security context to session
- // if (httpSession.getAttribute(SPRING_SECURITY_CONTEXT_KEY) == null)
- // httpSession.setAttribute(SPRING_SECURITY_CONTEXT_KEY,
- // SecurityContextHolder.getContext());
- // // add thread locale to RWT session
- // log.info("Locale " + LocaleUtils.threadLocale.get());
- // RWT.setLocale(LocaleUtils.threadLocale.get());
- //
- // // Once the user is logged in, she can have a longer session
- // // timeout
- // RWT.getRequest().getSession()
- // .setMaxInactiveInterval(sessionTimeout);
- // if (log.isDebugEnabled())
- // log.debug("Authenticated " + subject);
- // } catch (LoginException e) {
- // BadCredentialsException bce = wasCausedByBadCredentials(e);
- // if (bce != null) {
- // MessageDialog.openInformation(display.getActiveShell(),
- // "Bad Credentials", bce.getMessage());
- // // retry login
- // continue tryLogin;
- // }
- // return processLoginDeath(display, e);
- // }
- // }
-
- final String username = subject.getPrincipals().iterator().next()
- .getName();
+ tryLogin: while (subject.getPrincipals(X500Principal.class).size() == 0) {
+ try {
+ loginContext.login();
+ if (subject.getPrincipals(X500Principal.class).size() == 0)
+ throw new ArgeoException("Login succeeded but no auth");// fatal
+
+ // add thread locale to RWT session
+ if (log.isTraceEnabled())
+ log.trace("Locale " + LocaleUtils.threadLocale.get());
+ RWT.setLocale(LocaleUtils.threadLocale.get());
+
+ // once the user is logged in, longer session timeout
+ RWT.getRequest().getSession()
+ .setMaxInactiveInterval(sessionTimeout);
+
+ if (log.isDebugEnabled())
+ log.debug("Authenticated " + subject);
+ } catch (FailedLoginException e) {
+ MessageDialog.openInformation(display.getActiveShell(),
+ "Bad Credentials", e.getMessage());
+ // retry login
+ continue tryLogin;
+ } catch (LoginException e) {
+ return processLoginDeath(display, e);
+ }
+ }
+ }
+ final String username = subject.getPrincipals(X500Principal.class)
+ .iterator().next().getName();