User Tools

Site Tools


blog:implementing_login_in_rcp_applications

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
blog:implementing_login_in_rcp_applications [2008/04/26 21:50]
djo Java formatting
blog:implementing_login_in_rcp_applications [2014/10/17 22:08] (current)
Line 1: Line 1:
 +====== 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 <at> 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:
 +
 +<code java>
 +    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;​
 +        } 
 +
 +    }
 +</​code>​
 +
 +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~~
  
blog/implementing_login_in_rcp_applications.txt ยท Last modified: 2014/10/17 22:08 (external edit)