====== Implementing Login in RCP Applications ====== Recently, the eclipsepowered discussion mailing list has been talking about how to implement login in an Eclipse RCP application. In the discussion, I described two major use cases: 1. RCP is a standard framework for deploying corporate applications. Logging into RCP implies logging into all of your corporate applications. 2. RCP is a container for many applications, some of which require a login. Olivier Crameri [olivier.crameri netoxygen.ch] then proposed an elegant solution to use case #1: implement your login in your RCP application's IPlatformRunnable class, after initializing the SWT Display object, but before running PlatformUI.createAndRunWorkbench. Here's his solution with a few modifications by myself: The IPlatformRunnable class looks something like the following: public class Client implements IPlatformRunnable { private static RootRMIInterface serverConnection = null; public static getDefaultConnection() { return serverConnection; } public Object run(Object args) { WorkbenchAdvisor workbenchAdvisor = new ClientWorkbenchAdvisor(); Display display = PlatformUI.createDisplay(); if (authenticate(display)) { int returnCode = PlatformUI.createAndRunWorkbench(display, workbenchAdvisor); if (returnCode == PlatformUI.RETURN_RESTART) { return IPlatformRunnable.EXIT_RESTART; } else { return IPlatformRunnable.EXIT_OK; } } else return IPlatformRunnable.EXIT_OK; } private boolean authenticate(Display display) { Shell shell = new Shell(display); LoginDialog loginDialog = new LoginDialog(shell); loginDialog.setBlockOnOpen(true); loginDialog.open(); Client.serverConnection = loginDialog.serverConnection; return loginDialog.isAuthenticated; } } The LoginDialog object performs the following functions: * Attempts to authenticate the user using the username/password pair that was entered. * If authentication is unsuccessful, the isAuthenticated field is set to false. * If authentication is successful, the RMI server returns a new RMI object stub back to the LoginDialog object. After the login dialog authenticates the user, the main Clientclass then retrieves the RMI stub and makes it available to all other classes in the application via the Singleton pattern. ~~LINKBACK~~ ~~DISCUSSION:closed~~