Skip to main content link. Accesskey S
  • Log In
  • Help
  • IBM Logo
  • Lotus Expeditor wiki
  • All Wikis
  • All Forums
  • Home
  • Product Documentation
  • Community Articles
  • Learning Center
  • IBM Redbooks
Community Articles Product Documentation Learning Center IBM Redbooks This category Lotus Expeditor 6.2.3 Documentation Custom Search Scope...
Search
Community Articles > Expeditor Client for Desktop > Sample: Platform Login Listener
  • New Article
  • Share Show Menu▼
  • Subscribe Show Menu▼

About the Original Author

IBM contributorVan Staub
Contribution Summary:
  • Articles authored: 26
  • Articles edited: 13
  • Comments Posted: 4

Recent articles by this author

Sample: Toolbar and Menu Contributions

Expeditor user interface team best practices on toolbar and menu contributions

Sample: Component Properties

OverviewComponent properties allow developers to create code that at compile time has specific function but accepts flexible input at runtime. For example, a developer can create a component that uses a predefined component property to update the title tab's text within a composite ...

Sample: Multiuser Features

Overview When multiple users share the same workstation, the configuration is referred to as a multiuser installation. This means that a single Expeditor client exists and is shared among all users; however, each user has their own workspace containing configuration details specific to that ...

Sample: Starting Plugins

Overview By default, Eclipse plugins are lazy. Lazy is the technical term (located in the bundle's manifest) that means that plugins are started when a request is either directly made by the Platform to start the plugin or indirectly through class loading. For example, the latter case implies ...

Sample: HTTP Communication

Overview The enhanced HTTP client in Expeditor allows developers to quickly create code that requests data from remote servers over HTTP or HTTPS. The enhanced client wraps the standard Java URLConnectionclasses such that authenticated requests leverage the Accounts framework and HTTPS ...

Community articleSample: Platform Login Listener

Added by IBM contributor Van Staub on January 10, 2011 | Version 1
  • Edit
  • More Actions Show Menu▼
Rate this article 1 starsRate this article 2 starsRate this article 3 starsRate this article 4 starsRate this article 5 stars
expanded Abstract
collapsed Abstract
No abstract provided.
Tags: samples
ShowTable of Contents
HideTable of Contents
  • 1 Overview
  • 2 ILoginContextEventListener
    • 2.1 Creating an ILoginContextEventListener
    • 2.2 Registering ILoginContextEventListener
  • 3 Enabling the Listener

Overview


The Expeditor desktop client may prompt the user to login to the platform. This is sometimes referred to as platform SSO on the wiki. It may be required that custom application code only execute after the login process is complete. In such a scenario, how can code know when the login process is complete?

ILoginContextEventListener


The ILoginContextEventListener type allows implementors to receive notification pertaining to the login process. Expeditor developers can register ILoginContextEventListener listeners to receive the logged in event and subsequently execute the necessary code.

Creating an ILoginContextEventListener


Add the com.ibm.rcp.security.auth plugin as a dependency within your plugin. The following class demonstrates a listener that responds to login events by writing to the platform's logger.

import java.util.logging.Level;
import java.util.logging.Logger;

import javax.security.auth.login.LoginException;

import org.eclipse.ui.PlatformUI;

import com.ibm.rcp.security.auth.events.ILoginContextEventListener;
import com.ibm.rcp.security.auth.events.LoginContextEvent;
import com.ibm.rcp.security.auth.login.CanceledLoginException;

public class PlatformLoginListener implements ILoginContextEventListener {

	private static Logger logger = Logger.getLogger(PlatformLoginListener.class
			.getName());

	@Override
	public void handleLogin(LoginContextEvent event) {
		handleEvent(event, true);
	}

	@Override
	public void handleLogout(LoginContextEvent event) {
		handleEvent(event, false);
	};

	private void handleEvent(LoginContextEvent event, boolean login) {
		String process = login ? "Login" : "Logout";

		if (event.type == LoginContextEvent.MethodBegin) {
			logger.finer(process + " starting");
		} else if (event.type == LoginContextEvent.MethodEnd
				&& event.hasException == false) {
			logger.fine(process + " success");
		} else if (event.type == LoginContextEvent.MethodEnd
				&& event.hasException == true) {
			// there was an exception
			// was this canceled or another reason
			boolean wasCanceled = false;

			// if it was canceled, one of the nested exceptions will be a
			// CanceledLoginException
			Throwable cause = event.exception.getCause();
			while (cause != null) {
				if (cause instanceof CanceledLoginException) {
					// found a CanceledLoginException, so login must have been
					// canceled
					wasCanceled = true;
					logger.finer(process + " canceled");

					// if cancelled login, close
					if (login && !PlatformUI.getWorkbench().close()) {
						System.err
								.println("Logout cancelled; Could not close workbench");
						System.exit(-1);
					}
				}

				cause = cause.getCause();
			}

			if (!wasCanceled) {
				// no cancellation, so another reason
				LoginException e = event.exception;
				logger.log(Level.SEVERE, process + " failed with exception", e);
			}
		}
	}
}



Registering ILoginContextEventListener


After implementing your ILoginContextEventListener, register it with the platform. For example, the following code registers the listener within the plugin's Activator class.

import com.ibm.rcp.security.auth.SecurePlatform;
...
public void start(BundleContext context) throws Exception {
		super.start(context);
		plugin = this;
		
		PlatformLoginListener listener = new PlatformLoginListener();
		SecurePlatform.getLoginContext().addListener(listener);
	}


Enabling the Listener


Because Eclipse plugins are lazily loaded, the platform should automatically register the listener code as early as possible. This can be done using the com.ibm.rcp.lifecycle.application extension. Plugins that contribute to the extension are loaded when the platform starts.

<extension
         point="com.ibm.rcp.lifecycle.application.startBundles">
      <application
            id="com.ibm.rcp.personality.framework.RCPApplication">
         <bundle
               id="com.ibm.rcp.support.platform.login"></bundle>
      </application>
   </extension>


The above extension starts the com.ibm.rcp.support.platform.login plugin that contains the above ILoginContextEventListener implementation when the platform loads. Since the ILoginContextEventListener is added within the plugin's start() method, the code is executed when the com.ibm.rcp.lifecycle.application.startBundles extension point is processed.

  • Edit
  • More Actions Show Menu▼


expanded Attachments (0)
collapsed Attachments (0)
Edit the article to add or modify attachments.
expanded Versions (1)
collapsed Versions (1)
Version Comparison     
VersionDateChanged by              Summary of changes
This version (1)Jan 10, 2011 12:18:04 PMVan Staub  IBM contributor
expanded Comments (0)
collapsed Comments (0)
Copy and paste this wiki markup to link to this article from another article in this wiki.
Go ElsewhereStay ConnectedHelpAbout
  • IBM Collaboration Solutions wikis
  • IBM developerWorks
  • IBM Software support
  • Twitter LinkIBMSocialBizUX on Twitter
  • FacebookIBMSocialBizUX on Facebook
  • ForumsLotus product forums
  • BlogsIBM Social Business UX blog
  • Community LinkIBM Collaboration Solutions
  • Wiki Help
  • Forgot user name/password
  • Wiki design feedback
  • Content feedback
  • About the wiki
  • About IBM
  • Privacy
  • Accessibility
  • IBM Terms of use
  • Wiki terms of use