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
.BadCredentialsException
;
23 import org
.springframework
.security
.LockedException
;
24 import org
.springframework
.security
.providers
.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
;
50 public LoginDialog(Shell parentShell
) {
57 * @see org.eclipse.jface.dialogs.Dialog#createDialogArea(org.eclipse.swt.widgets.Composite)
60 protected Control
createDialogArea(Composite parent
) {
61 Composite composite
= (Composite
) super.createDialogArea(parent
);
62 //add controls to composite as necessary
65 // Label for the heading
66 final CLabel titleLabel
= new CLabel(composite
, SWT
.NONE
);
67 titleLabel
.setText("User Login");
69 // Label for the username
70 final CLabel userNameLabel
= new CLabel(composite
, SWT
.NONE
);
71 userNameLabel
.setText("Username");
73 // Textfield for the username
74 text_username
= new Text(composite
, SWT
.BORDER
);
75 text_username
.setLayoutData(new GridData(SWT
.FILL
, SWT
.FILL
, true, true));
77 // Label for the password
78 final CLabel passwordLabel
= new CLabel(composite
, SWT
.NONE
);
79 passwordLabel
.setText("Password");
81 // Textfield for the password
82 text_password
= new Text(composite
, SWT
.PASSWORD
| SWT
.BORDER
);
83 text_password
.setLayoutData(new GridData(SWT
.FILL
, SWT
.FILL
, true, true));
92 * @see org.eclipse.jface.window.Window#configureShell(org.eclipse.swt.widgets.Shell)
94 protected void configureShell(Shell shell
) {
95 super.configureShell(shell
);
102 * @see org.eclipse.jface.dialogs.Dialog#okPressed()
105 protected void okPressed() {
106 String username
= text_username
.getText().trim();
107 String password
= text_password
.getText().trim();
109 UsernamePasswordAuthenticationToken token
= new UsernamePasswordAuthenticationToken(username
, password
);
112 CdmStore
.getLoginManager().authenticate(token
);
113 }catch(BadCredentialsException e
){
114 logger
.error("Bad credentials", e
);
115 StoreUtil
.warningDialog("Could not authenticate. Reason: Bad Credentials.");
116 }catch(LockedException e
){
117 logger
.error("Account is locked", e
);
118 StoreUtil
.warningDialog("Could not authenticate. Reason: Account is locked.");
119 }catch(IllegalArgumentException e
){
120 logger
.error("Null argument for either user or password", e
);
121 StoreUtil
.warningDialog("Could not authenticate. Reason: Username and/or Password empty.");