3 * Copyright (C) 2007 EDIT
4 * European Distributed Institute of Taxonomy
5 * http://www.e-taxonomy.eu
7 * The contents of this file are subject to the Mozilla Public License Version 1.1
8 * See LICENSE.TXT at the top of this package for the full license terms.
11 package eu
.etaxonomy
.taxeditor
.dialogs
;
13 import org
.apache
.log4j
.Logger
;
14 import org
.eclipse
.jface
.dialogs
.Dialog
;
15 import org
.eclipse
.swt
.SWT
;
16 import org
.eclipse
.swt
.custom
.CLabel
;
17 import org
.eclipse
.swt
.layout
.GridData
;
18 import org
.eclipse
.swt
.widgets
.Composite
;
19 import org
.eclipse
.swt
.widgets
.Control
;
20 import org
.eclipse
.swt
.widgets
.Shell
;
21 import org
.eclipse
.swt
.widgets
.Text
;
22 import org
.springframework
.security
.authentication
.BadCredentialsException
;
23 import org
.springframework
.security
.authentication
.LockedException
;
24 import org
.springframework
.security
.authentication
.UsernamePasswordAuthenticationToken
;
26 import eu
.etaxonomy
.taxeditor
.store
.CdmStore
;
27 import eu
.etaxonomy
.taxeditor
.store
.StoreUtil
;
30 * TODO wrap in a LoginModule
31 * see: http://java.sun.com/j2se/1.5.0/docs/api/javax/security/auth/spi/LoginModule.html
37 public class LoginDialog
extends Dialog
{
40 private static final Logger logger
= Logger
.getLogger(LoginDialog
.class);
42 private static Text text_password
;
43 private static Text text_username
;
48 * <p>Constructor for LoginDialog.</p>
50 * @param parentShell a {@link org.eclipse.swt.widgets.Shell} object.
52 public LoginDialog(Shell parentShell
) {
59 * @see org.eclipse.jface.dialogs.Dialog#createDialogArea(org.eclipse.swt.widgets.Composite)
63 protected Control
createDialogArea(Composite parent
) {
64 Composite composite
= (Composite
) super.createDialogArea(parent
);
65 //add controls to composite as necessary
68 // Label for the heading
69 final CLabel titleLabel
= new CLabel(composite
, SWT
.NONE
);
70 titleLabel
.setText("User Login");
72 // Label for the username
73 final CLabel userNameLabel
= new CLabel(composite
, SWT
.NONE
);
74 userNameLabel
.setText("Username");
76 // Textfield for the username
77 text_username
= new Text(composite
, SWT
.BORDER
);
78 text_username
.setLayoutData(new GridData(SWT
.FILL
, SWT
.FILL
, true, true));
80 // Label for the password
81 final CLabel passwordLabel
= new CLabel(composite
, SWT
.NONE
);
82 passwordLabel
.setText("Password");
84 // Textfield for the password
85 text_password
= new Text(composite
, SWT
.PASSWORD
| SWT
.BORDER
);
86 text_password
.setLayoutData(new GridData(SWT
.FILL
, SWT
.FILL
, true, true));
95 * @see org.eclipse.jface.window.Window#configureShell(org.eclipse.swt.widgets.Shell)
98 protected void configureShell(Shell shell
) {
99 super.configureShell(shell
);
101 shell
.setText(title
);
106 * @see org.eclipse.jface.dialogs.Dialog#okPressed()
110 protected void okPressed() {
111 String username
= text_username
.getText().trim();
112 String password
= text_password
.getText().trim();
114 UsernamePasswordAuthenticationToken token
= new UsernamePasswordAuthenticationToken(username
, password
);
117 CdmStore
.getLoginManager().authenticate(token
);
118 }catch(BadCredentialsException e
){
119 logger
.error("Bad credentials", e
);
120 StoreUtil
.warningDialog("Could not authenticate", this, "Could not authenticate. Reason: Bad Credentials.");
121 }catch(LockedException e
){
122 logger
.error("Account is locked", e
);
123 StoreUtil
.warningDialog("Could not authenticate", this, "Could not authenticate. Reason: Account is locked.");
124 }catch(IllegalArgumentException e
){
125 logger
.error("Null argument for either user or password", e
);
126 StoreUtil
.warningDialog("Could not authenticate", this, "Could not authenticate. Reason: Username and/or Password empty.");