Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Remote Application Platform (RAP) » setDefaultButton on a login shell with combo might lead to security issues?
setDefaultButton on a login shell with combo might lead to security issues? [message #82614] Sat, 12 April 2008 21:47 Go to next message
Alexandru Tica is currently offline Alexandru TicaFriend
Messages: 2
Registered: July 2009
Junior Member
Hi,

I have a simple login form with username/password fields, two combo-boxes
and a submit button set as a default button on its parent shell. Pressing
ENTER within one of the combo-boxes activates the corresponding list but
this clashes somehow with the submit default button which also respond to
the ENTER key. In my case this opens a security hole as the following
scenario reveals:

1. Using TAB key go to one of the combo-boxes
2. Press ENTER
3. Now I have the combo-box list displayed and a modal message box which
warns that invalid credentials have been inputed
4. With the mouse select an item from the combo (yes, it is possible even
I have the modal message box dialog)
5. Now close the login dialog
6. Press OK on the message dialog
7. Voila, you're in without any credentials.

Below is the code I use for the above scenario:

import java.text.MessageFormat;

import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.rwt.lifecycle.IEntryPoint;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Combo;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;
import org.eclipse.ui.PlatformUI;

/**
* This class controls all aspects of the application's execution
*/
public class ApplicationTest implements IEntryPoint {

private boolean isValid;
private int pin1 = 3;
private int pin2 = 5;

private void buildLoginForm(Display display) {
final Shell shell = new Shell(display, SWT.CLOSE);
shell.setText("Login");

GridLayout gridLayout = new GridLayout(2, false);
gridLayout.marginBottom = 15;
shell.setLayout(gridLayout);
Label caption = new Label(shell, SWT.NONE);
caption.setText("Welcome to Test Application\nPlease provide your
credentials.");
GridData gd = new GridData(GridData.FILL_HORIZONTAL |
GridData.GRAB_HORIZONTAL);
gd.horizontalSpan = 2;
caption.setLayoutData(gd);
Label lbl1 = new Label(shell, SWT.NONE);
lbl1.setText("UserName:");
final Text txtUserName = new Text(shell, SWT.BORDER);
gd = new GridData(GridData.FILL_HORIZONTAL |
GridData.GRAB_HORIZONTAL);
gd.widthHint = 300;
txtUserName.setLayoutData(gd);
Label lbl2 = new Label(shell, SWT.NONE);
lbl2.setText("Password:");
final Text txtPassword = new Text(shell, SWT.BORDER |
SWT.PASSWORD);
gd = new GridData(GridData.FILL_HORIZONTAL |
GridData.GRAB_HORIZONTAL);
gd.widthHint = 300;
txtPassword.setLayoutData(gd);
final Label lblPin1 = new Label(shell, SWT.NONE);
lblPin1.setText(MessageFormat.format("The {0}{1} digit from your
PIN", pin1+"", pin1 == 1 ? "st" : pin1 == 2 ? "nd" : pin1 == 3 ? "rd" :
"th"));
final Combo txtPin1 = new Combo(shell, SWT.BORDER | SWT.READ_ONLY);
txtPin1.setItems(new String[] {"0", "1", "2", "3", "4", "5", "6",
"7", "8", "9"});
final Label lblPin2 = new Label(shell, SWT.NONE);
lblPin2.setText(MessageFormat.format("The {0}{1} digit from your
PIN", pin2+"", pin2 == 1 ? "st" : pin2 == 2 ? "nd" : pin2 == 3 ? "rd" :
"th"));
final Combo txtPin2 = new Combo(shell, SWT.BORDER | SWT.READ_ONLY);
txtPin2.setItems(new String[] {"0", "1", "2", "3", "4", "5", "6",
"7", "8", "9"});

Button btn = new Button(shell, SWT.PUSH);
btn.addSelectionListener(new SelectionAdapter() {
@SuppressWarnings("unchecked")
public void widgetSelected(SelectionEvent e) {
String userName = txtUserName.getText();
String userPwd = txtPassword.getText();
if (userName.equals("root") && (userPwd.equals("xxx"))) {
isValid = true;
} else {
MessageDialog.openError(shell, "Error", "Invalid username
or password.");
}
}

});
btn.setText("Submit");
gd = new GridData(GridData.HORIZONTAL_ALIGN_END);
gd.horizontalSpan = 2;
btn.setLayoutData(gd);

// TODO: buggy in connection with a combo
shell.setDefaultButton(btn);

shell.pack();
shell.setMaximized(false);
shell.open();
txtUserName.setFocus();
shell.layout();

while (!shell.isDisposed()) {
if (isValid) {
shell.dispose();
break;
}
if (!display.readAndDispatch()) {
display.sleep();
}
}
}

public int createUI() {
Display display = PlatformUI.createDisplay();
buildLoginForm(display);
PlatformUI.createAndRunWorkbench(display, new
ApplicationWorkbenchAdvisor());
return 0;
}

}
Re: setDefaultButton on a login shell with combo might lead to security issues? [message #82637 is a reply to message #82614] Sun, 13 April 2008 18:48 Go to previous messageGo to next message
Arpit Desai is currently offline Arpit DesaiFriend
Messages: 25
Registered: July 2009
Junior Member
Hello,

Do the following in createUI():

return PlatformUI.createAndRunWorkbench(display, new
> ApplicationWorkbenchAdvisor());

only when the login is successfull that should solve the problem. Here
is how I did it.


public class Application implements IEntryPoint {

public int createUI() {
Display display = PlatformUI.createDisplay();
WorkbenchAdvisor advisor = new ApplicationWorkbenchAdvisor();
if (login(display)) {
return PlatformUI.createAndRunWorkbench(display, advisor);
}
return 0;
}

private boolean login(Display display) {
LoginDialog bar = new LoginDialog(display.getActiveShell());
boolean returnValue = false;
while (!returnValue) {
returnValue = bar.open() == IDialogConstants.OK_ID ? true : false;
if (true == returnValue) {
// validate user
String strUserId = bar.getUserId();
String strPassword = bar.getPassword();
if (strUserId.equals("demo") && strPassword.equals("demo")) {
returnValue = true;
} else if (strUserId.equals("xxx")
&& strPassword.equals("xxx")) {
returnValue = true;
} else {
MessageDialog
.openError(display.getActiveShell(), "Error",
"Aunthenticaiton failed \n Invalid username and password");
returnValue = false;
}

} else {
MessageDialog
.openError(display.getActiveShell(), "Error",
"Aunthenticaiton failed \n Please enter valid username and
password");

}
}
return returnValue;
}
}


Regards,
Arpit




talek wrote:
> Hi,
>
> I have a simple login form with username/password fields, two
> combo-boxes and a submit button set as a default button on its parent
> shell. Pressing ENTER within one of the combo-boxes activates the
> corresponding list but this clashes somehow with the submit default
> button which also respond to the ENTER key. In my case this opens a
> security hole as the following scenario reveals:
>
> 1. Using TAB key go to one of the combo-boxes
> 2. Press ENTER
> 3. Now I have the combo-box list displayed and a modal message box which
> warns that invalid credentials have been inputed
> 4. With the mouse select an item from the combo (yes, it is possible
> even I have the modal message box dialog)
> 5. Now close the login dialog
> 6. Press OK on the message dialog
> 7. Voila, you're in without any credentials.
>
> Below is the code I use for the above scenario:
>
> import java.text.MessageFormat;
>
> import org.eclipse.jface.dialogs.MessageDialog;
> import org.eclipse.rwt.lifecycle.IEntryPoint;
> import org.eclipse.swt.SWT;
> import org.eclipse.swt.events.SelectionAdapter;
> import org.eclipse.swt.events.SelectionEvent;
> import org.eclipse.swt.layout.GridData;
> import org.eclipse.swt.layout.GridLayout;
> import org.eclipse.swt.widgets.Button;
> import org.eclipse.swt.widgets.Combo;
> import org.eclipse.swt.widgets.Display;
> import org.eclipse.swt.widgets.Label;
> import org.eclipse.swt.widgets.Shell;
> import org.eclipse.swt.widgets.Text;
> import org.eclipse.ui.PlatformUI;
>
> /**
> * This class controls all aspects of the application's execution
> */
> public class ApplicationTest implements IEntryPoint {
>
> private boolean isValid;
> private int pin1 = 3;
> private int pin2 = 5;
>
> private void buildLoginForm(Display display) {
> final Shell shell = new Shell(display, SWT.CLOSE);
> shell.setText("Login");
>
> GridLayout gridLayout = new GridLayout(2, false);
> gridLayout.marginBottom = 15;
> shell.setLayout(gridLayout);
> Label caption = new Label(shell, SWT.NONE);
> caption.setText("Welcome to Test Application\nPlease provide your
> credentials.");
> GridData gd = new GridData(GridData.FILL_HORIZONTAL |
> GridData.GRAB_HORIZONTAL);
> gd.horizontalSpan = 2;
> caption.setLayoutData(gd);
> Label lbl1 = new Label(shell, SWT.NONE);
> lbl1.setText("UserName:");
> final Text txtUserName = new Text(shell, SWT.BORDER);
> gd = new GridData(GridData.FILL_HORIZONTAL |
> GridData.GRAB_HORIZONTAL);
> gd.widthHint = 300;
> txtUserName.setLayoutData(gd);
> Label lbl2 = new Label(shell, SWT.NONE);
> lbl2.setText("Password:");
> final Text txtPassword = new Text(shell, SWT.BORDER | SWT.PASSWORD);
> gd = new GridData(GridData.FILL_HORIZONTAL |
> GridData.GRAB_HORIZONTAL);
> gd.widthHint = 300;
> txtPassword.setLayoutData(gd);
> final Label lblPin1 = new Label(shell, SWT.NONE);
> lblPin1.setText(MessageFormat.format("The {0}{1} digit from your
> PIN", pin1+"", pin1 == 1 ? "st" : pin1 == 2 ? "nd" : pin1 == 3 ? "rd" :
> "th"));
> final Combo txtPin1 = new Combo(shell, SWT.BORDER | SWT.READ_ONLY);
> txtPin1.setItems(new String[] {"0", "1", "2", "3", "4", "5", "6",
> "7", "8", "9"});
> final Label lblPin2 = new Label(shell, SWT.NONE);
> lblPin2.setText(MessageFormat.format("The {0}{1} digit from your
> PIN", pin2+"", pin2 == 1 ? "st" : pin2 == 2 ? "nd" : pin2 == 3 ? "rd" :
> "th"));
> final Combo txtPin2 = new Combo(shell, SWT.BORDER | SWT.READ_ONLY);
> txtPin2.setItems(new String[] {"0", "1", "2", "3", "4", "5", "6",
> "7", "8", "9"});
> Button btn = new Button(shell, SWT.PUSH);
> btn.addSelectionListener(new SelectionAdapter() {
> @SuppressWarnings("unchecked")
> public void widgetSelected(SelectionEvent e) {
> String userName = txtUserName.getText();
> String userPwd = txtPassword.getText();
> if (userName.equals("root") &&
> (userPwd.equals("xxx"))) {
> isValid = true;
> } else {
> MessageDialog.openError(shell, "Error",
> "Invalid username or password.");
> }
> }
>
> });
> btn.setText("Submit");
> gd = new GridData(GridData.HORIZONTAL_ALIGN_END);
> gd.horizontalSpan = 2;
> btn.setLayoutData(gd);
> // TODO: buggy in connection with a combo
> shell.setDefaultButton(btn);
> shell.pack();
> shell.setMaximized(false);
> shell.open();
> txtUserName.setFocus();
> shell.layout();
>
> while (!shell.isDisposed()) {
> if (isValid) {
> shell.dispose();
> break;
> }
> if (!display.readAndDispatch()) {
> display.sleep();
> }
> }
> }
>
> public int createUI() {
> Display display = PlatformUI.createDisplay();
> buildLoginForm(display);
> PlatformUI.createAndRunWorkbench(display, new
> ApplicationWorkbenchAdvisor());
> return 0;
> }
>
> }
>
>
Re: setDefaultButton on a login shell with combo might lead to security issues? [message #82650 is a reply to message #82637] Sun, 13 April 2008 19:27 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: rsternberg.innoopract.com

Hi,

yes, there is a bug in the handling of the Return key event when a
default button exists. Both the Combo and the default Button receive the
Return event. Could you file a bug with your example?

With regard to security, I also think this is a problem in your
application. Your startup code should ensure that no unprivileged user
can ever get access to the application even in case of an error. With
the snippet provided by Arpit for example, this can never happen.

Best regards,
Ralf

Arpit Desai wrote:
> Hello,
>
> Do the following in createUI():
>
> return PlatformUI.createAndRunWorkbench(display, new
> > ApplicationWorkbenchAdvisor());
>
> only when the login is successfull that should solve the problem. Here
> is how I did it.
>
>
> public class Application implements IEntryPoint {
>
> public int createUI() {
> Display display = PlatformUI.createDisplay();
> WorkbenchAdvisor advisor = new ApplicationWorkbenchAdvisor();
> if (login(display)) {
> return PlatformUI.createAndRunWorkbench(display, advisor);
> }
> return 0;
> }
>
> private boolean login(Display display) {
> LoginDialog bar = new LoginDialog(display.getActiveShell());
> boolean returnValue = false;
> while (!returnValue) {
> returnValue = bar.open() == IDialogConstants.OK_ID ? true :
> false;
> if (true == returnValue) {
> // validate user
> String strUserId = bar.getUserId();
> String strPassword = bar.getPassword();
> if (strUserId.equals("demo") &&
> strPassword.equals("demo")) {
> returnValue = true;
> } else if (strUserId.equals("xxx")
> && strPassword.equals("xxx")) {
> returnValue = true;
> } else {
> MessageDialog
> .openError(display.getActiveShell(), "Error",
> "Aunthenticaiton failed \n Invalid
> username and password");
> returnValue = false;
> }
>
> } else {
> MessageDialog
> .openError(display.getActiveShell(), "Error",
> "Aunthenticaiton failed \n Please enter
> valid username and password");
>
> }
> }
> return returnValue;
> }
> }
>
>
> Regards,
> Arpit
>
>
>
>
> talek wrote:
>> Hi,
>>
>> I have a simple login form with username/password fields, two
>> combo-boxes and a submit button set as a default button on its parent
>> shell. Pressing ENTER within one of the combo-boxes activates the
>> corresponding list but this clashes somehow with the submit default
>> button which also respond to the ENTER key. In my case this opens a
>> security hole as the following scenario reveals:
>>
>> 1. Using TAB key go to one of the combo-boxes
>> 2. Press ENTER
>> 3. Now I have the combo-box list displayed and a modal message box
>> which warns that invalid credentials have been inputed
>> 4. With the mouse select an item from the combo (yes, it is possible
>> even I have the modal message box dialog)
>> 5. Now close the login dialog
>> 6. Press OK on the message dialog
>> 7. Voila, you're in without any credentials.
>>
>> Below is the code I use for the above scenario:
>>
>> import java.text.MessageFormat;
>>
>> import org.eclipse.jface.dialogs.MessageDialog;
>> import org.eclipse.rwt.lifecycle.IEntryPoint;
>> import org.eclipse.swt.SWT;
>> import org.eclipse.swt.events.SelectionAdapter;
>> import org.eclipse.swt.events.SelectionEvent;
>> import org.eclipse.swt.layout.GridData;
>> import org.eclipse.swt.layout.GridLayout;
>> import org.eclipse.swt.widgets.Button;
>> import org.eclipse.swt.widgets.Combo;
>> import org.eclipse.swt.widgets.Display;
>> import org.eclipse.swt.widgets.Label;
>> import org.eclipse.swt.widgets.Shell;
>> import org.eclipse.swt.widgets.Text;
>> import org.eclipse.ui.PlatformUI;
>>
>> /**
>> * This class controls all aspects of the application's execution
>> */
>> public class ApplicationTest implements IEntryPoint {
>>
>> private boolean isValid;
>> private int pin1 = 3;
>> private int pin2 = 5;
>> private void buildLoginForm(Display display) {
>> final Shell shell = new Shell(display, SWT.CLOSE);
>> shell.setText("Login");
>> GridLayout gridLayout = new GridLayout(2, false);
>> gridLayout.marginBottom = 15;
>> shell.setLayout(gridLayout);
>> Label caption = new Label(shell, SWT.NONE);
>> caption.setText("Welcome to Test Application\nPlease provide
>> your credentials.");
>> GridData gd = new GridData(GridData.FILL_HORIZONTAL |
>> GridData.GRAB_HORIZONTAL);
>> gd.horizontalSpan = 2;
>> caption.setLayoutData(gd);
>> Label lbl1 = new Label(shell, SWT.NONE);
>> lbl1.setText("UserName:");
>> final Text txtUserName = new Text(shell, SWT.BORDER);
>> gd = new GridData(GridData.FILL_HORIZONTAL |
>> GridData.GRAB_HORIZONTAL);
>> gd.widthHint = 300;
>> txtUserName.setLayoutData(gd);
>> Label lbl2 = new Label(shell, SWT.NONE);
>> lbl2.setText("Password:");
>> final Text txtPassword = new Text(shell, SWT.BORDER |
>> SWT.PASSWORD);
>> gd = new GridData(GridData.FILL_HORIZONTAL |
>> GridData.GRAB_HORIZONTAL);
>> gd.widthHint = 300;
>> txtPassword.setLayoutData(gd);
>> final Label lblPin1 = new Label(shell, SWT.NONE);
>> lblPin1.setText(MessageFormat.format("The {0}{1} digit from
>> your PIN", pin1+"", pin1 == 1 ? "st" : pin1 == 2 ? "nd" : pin1 == 3 ?
>> "rd" : "th"));
>> final Combo txtPin1 = new Combo(shell, SWT.BORDER |
>> SWT.READ_ONLY);
>> txtPin1.setItems(new String[] {"0", "1", "2", "3", "4", "5",
>> "6", "7", "8", "9"});
>> final Label lblPin2 = new Label(shell, SWT.NONE);
>> lblPin2.setText(MessageFormat.format("The {0}{1} digit from
>> your PIN", pin2+"", pin2 == 1 ? "st" : pin2 == 2 ? "nd" : pin2 == 3 ?
>> "rd" : "th"));
>> final Combo txtPin2 = new Combo(shell, SWT.BORDER |
>> SWT.READ_ONLY);
>> txtPin2.setItems(new String[] {"0", "1", "2", "3", "4", "5",
>> "6", "7", "8", "9"});
>> Button btn = new Button(shell, SWT.PUSH);
>> btn.addSelectionListener(new SelectionAdapter() {
>> @SuppressWarnings("unchecked")
>> public void widgetSelected(SelectionEvent e) {
>> String userName = txtUserName.getText();
>> String userPwd = txtPassword.getText();
>> if (userName.equals("root") &&
>> (userPwd.equals("xxx"))) {
>> isValid = true;
>> } else {
>> MessageDialog.openError(shell, "Error",
>> "Invalid username or password.");
>> }
>> }
>>
>> });
>> btn.setText("Submit");
>> gd = new GridData(GridData.HORIZONTAL_ALIGN_END);
>> gd.horizontalSpan = 2;
>> btn.setLayoutData(gd);
>> // TODO: buggy in connection with a combo
>> shell.setDefaultButton(btn);
>> shell.pack();
>> shell.setMaximized(false);
>> shell.open();
>> txtUserName.setFocus();
>> shell.layout();
>>
>> while (!shell.isDisposed()) {
>> if (isValid) {
>> shell.dispose();
>> break;
>> }
>> if (!display.readAndDispatch()) {
>> display.sleep();
>> }
>> } }
>> public int createUI() {
>> Display display = PlatformUI.createDisplay();
>> buildLoginForm(display);
>> PlatformUI.createAndRunWorkbench(display, new
>> ApplicationWorkbenchAdvisor());
>> return 0;
>> }
>>
>> }
>>
>>
Re: setDefaultButton on a login shell with combo might lead to security issues? [message #82690 is a reply to message #82650] Mon, 14 April 2008 07:39 Go to previous message
Alexandru Tica is currently offline Alexandru TicaFriend
Messages: 2
Registered: July 2009
Junior Member
Hi,

thanks Arpid,
thanks Ralh,

for pointing out the way to improve the login operation. I've opened the
bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=226875 concerning this
issue.

Ralf Sternberg wrote:
> Hi,
>
> yes, there is a bug in the handling of the Return key event when a
> default button exists. Both the Combo and the default Button receive the
> Return event. Could you file a bug with your example?
>
> With regard to security, I also think this is a problem in your
> application. Your startup code should ensure that no unprivileged user
> can ever get access to the application even in case of an error. With
> the snippet provided by Arpit for example, this can never happen.
>
> Best regards,
> Ralf
>
> Arpit Desai wrote:
>> Hello,
>>
>> Do the following in createUI():
>>
>> return PlatformUI.createAndRunWorkbench(display, new
>> > ApplicationWorkbenchAdvisor());
>>
>> only when the login is successfull that should solve the problem. Here
>> is how I did it.
>>
>>
>> public class Application implements IEntryPoint {
>>
>> public int createUI() {
>> Display display = PlatformUI.createDisplay();
>> WorkbenchAdvisor advisor = new ApplicationWorkbenchAdvisor();
>> if (login(display)) {
>> return PlatformUI.createAndRunWorkbench(display, advisor);
>> }
>> return 0;
>> }
>>
>> private boolean login(Display display) {
>> LoginDialog bar = new LoginDialog(display.getActiveShell());
>> boolean returnValue = false;
>> while (!returnValue) {
>> returnValue = bar.open() == IDialogConstants.OK_ID ? true
>> : false;
>> if (true == returnValue) {
>> // validate user
>> String strUserId = bar.getUserId();
>> String strPassword = bar.getPassword();
>> if (strUserId.equals("demo") &&
>> strPassword.equals("demo")) {
>> returnValue = true;
>> } else if (strUserId.equals("xxx")
>> && strPassword.equals("xxx")) {
>> returnValue = true;
>> } else {
>> MessageDialog
>> .openError(display.getActiveShell(), "Error",
>> "Aunthenticaiton failed \n Invalid
>> username and password");
>> returnValue = false;
>> }
>>
>> } else {
>> MessageDialog
>> .openError(display.getActiveShell(), "Error",
>> "Aunthenticaiton failed \n Please
>> enter valid username and password");
>>
>> }
>> }
>> return returnValue;
>> }
>> }
>>
>>
>> Regards,
>> Arpit
>>
>>
>>
>>
>> talek wrote:
>>> Hi,
>>>
>>> I have a simple login form with username/password fields, two
>>> combo-boxes and a submit button set as a default button on its parent
>>> shell. Pressing ENTER within one of the combo-boxes activates the
>>> corresponding list but this clashes somehow with the submit default
>>> button which also respond to the ENTER key. In my case this opens a
>>> security hole as the following scenario reveals:
>>>
>>> 1. Using TAB key go to one of the combo-boxes
>>> 2. Press ENTER
>>> 3. Now I have the combo-box list displayed and a modal message box
>>> which warns that invalid credentials have been inputed
>>> 4. With the mouse select an item from the combo (yes, it is possible
>>> even I have the modal message box dialog)
>>> 5. Now close the login dialog
>>> 6. Press OK on the message dialog
>>> 7. Voila, you're in without any credentials.
>>>
>>> Below is the code I use for the above scenario:
>>>
>>> import java.text.MessageFormat;
>>>
>>> import org.eclipse.jface.dialogs.MessageDialog;
>>> import org.eclipse.rwt.lifecycle.IEntryPoint;
>>> import org.eclipse.swt.SWT;
>>> import org.eclipse.swt.events.SelectionAdapter;
>>> import org.eclipse.swt.events.SelectionEvent;
>>> import org.eclipse.swt.layout.GridData;
>>> import org.eclipse.swt.layout.GridLayout;
>>> import org.eclipse.swt.widgets.Button;
>>> import org.eclipse.swt.widgets.Combo;
>>> import org.eclipse.swt.widgets.Display;
>>> import org.eclipse.swt.widgets.Label;
>>> import org.eclipse.swt.widgets.Shell;
>>> import org.eclipse.swt.widgets.Text;
>>> import org.eclipse.ui.PlatformUI;
>>>
>>> /**
>>> * This class controls all aspects of the application's execution
>>> */
>>> public class ApplicationTest implements IEntryPoint {
>>>
>>> private boolean isValid;
>>> private int pin1 = 3;
>>> private int pin2 = 5;
>>> private void buildLoginForm(Display display) {
>>> final Shell shell = new Shell(display, SWT.CLOSE);
>>> shell.setText("Login");
>>> GridLayout gridLayout = new GridLayout(2, false);
>>> gridLayout.marginBottom = 15;
>>> shell.setLayout(gridLayout);
>>> Label caption = new Label(shell, SWT.NONE);
>>> caption.setText("Welcome to Test Application\nPlease provide
>>> your credentials.");
>>> GridData gd = new GridData(GridData.FILL_HORIZONTAL |
>>> GridData.GRAB_HORIZONTAL);
>>> gd.horizontalSpan = 2;
>>> caption.setLayoutData(gd);
>>> Label lbl1 = new Label(shell, SWT.NONE);
>>> lbl1.setText("UserName:");
>>> final Text txtUserName = new Text(shell, SWT.BORDER);
>>> gd = new GridData(GridData.FILL_HORIZONTAL |
>>> GridData.GRAB_HORIZONTAL);
>>> gd.widthHint = 300;
>>> txtUserName.setLayoutData(gd);
>>> Label lbl2 = new Label(shell, SWT.NONE);
>>> lbl2.setText("Password:");
>>> final Text txtPassword = new Text(shell, SWT.BORDER |
>>> SWT.PASSWORD);
>>> gd = new GridData(GridData.FILL_HORIZONTAL |
>>> GridData.GRAB_HORIZONTAL);
>>> gd.widthHint = 300;
>>> txtPassword.setLayoutData(gd);
>>> final Label lblPin1 = new Label(shell, SWT.NONE);
>>> lblPin1.setText(MessageFormat.format("The {0}{1} digit from
>>> your PIN", pin1+"", pin1 == 1 ? "st" : pin1 == 2 ? "nd" : pin1 == 3 ?
>>> "rd" : "th"));
>>> final Combo txtPin1 = new Combo(shell, SWT.BORDER |
>>> SWT.READ_ONLY);
>>> txtPin1.setItems(new String[] {"0", "1", "2", "3", "4", "5",
>>> "6", "7", "8", "9"});
>>> final Label lblPin2 = new Label(shell, SWT.NONE);
>>> lblPin2.setText(MessageFormat.format("The {0}{1} digit from
>>> your PIN", pin2+"", pin2 == 1 ? "st" : pin2 == 2 ? "nd" : pin2 == 3 ?
>>> "rd" : "th"));
>>> final Combo txtPin2 = new Combo(shell, SWT.BORDER |
>>> SWT.READ_ONLY);
>>> txtPin2.setItems(new String[] {"0", "1", "2", "3", "4", "5",
>>> "6", "7", "8", "9"});
>>> Button btn = new Button(shell, SWT.PUSH);
>>> btn.addSelectionListener(new SelectionAdapter() {
>>> @SuppressWarnings("unchecked")
>>> public void widgetSelected(SelectionEvent e) {
>>> String userName = txtUserName.getText();
>>> String userPwd = txtPassword.getText();
>>> if (userName.equals("root") &&
>>> (userPwd.equals("xxx"))) {
>>> isValid = true;
>>> } else {
>>> MessageDialog.openError(shell, "Error",
>>> "Invalid username or password.");
>>> }
>>> }
>>>
>>> });
>>> btn.setText("Submit");
>>> gd = new GridData(GridData.HORIZONTAL_ALIGN_END);
>>> gd.horizontalSpan = 2;
>>> btn.setLayoutData(gd);
>>> // TODO: buggy in connection with a combo
>>> shell.setDefaultButton(btn);
>>> shell.pack();
>>> shell.setMaximized(false);
>>> shell.open();
>>> txtUserName.setFocus();
>>> shell.layout();
>>>
>>> while (!shell.isDisposed()) {
>>> if (isValid) {
>>> shell.dispose();
>>> break;
>>> }
>>> if (!display.readAndDispatch()) {
>>> display.sleep();
>>> }
>>> } }
>>> public int createUI() {
>>> Display display = PlatformUI.createDisplay();
>>> buildLoginForm(display);
>>> PlatformUI.createAndRunWorkbench(display, new
>>> ApplicationWorkbenchAdvisor());
>>> return 0;
>>> }
>>>
>>> }
>>>
>>>
Previous Topic:Ivalid version of Require-Bundle in org.eclipse.rap.jface 1.1.0
Next Topic:Deployment of rapdemo.war fails on JBoss 4.2.2.GA
Goto Forum:
  


Current Time: Thu Apr 25 11:28:50 GMT 2024

Powered by FUDForum. Page generated in 0.03244 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top