+ final Display display = PlatformUI.createDisplay();
+ Subject subject = new Subject();
+
+ final LoginContext loginContext;
+ try {
+ loginContext = new LoginContext(AuthConstants.LOGIN_CONTEXT_ANONYMOUS,
+ subject);
+ loginContext.login();
+ } catch (LoginException e1) {
+ throw new CmsException("Cannot initialize login context", e1);
+ }
+
+ // identify after successful login
+ if (log.isDebugEnabled())
+ log.debug("Authenticated " + subject);
+ final String username = subject.getPrincipals().iterator().next()
+ .getName();
+
+ // Logout callback when the display is disposed
+ display.disposeExec(new Runnable() {
+ public void run() {
+ log.debug("Display disposed");
+ logout(loginContext, username);
+ }
+ });