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
.providers
.UsernamePasswordAuthenticationToken
;
25 import eu
.etaxonomy
.taxeditor
.store
.CdmStore
;
32 public class LoginDialog
extends Dialog
{
35 private static final Logger logger
= Logger
.getLogger(LoginDialog
.class);
37 private static Text passwordText
;
38 private static Text usernameText
;
43 public LoginDialog(Shell parentShell
) {
49 * @see org.eclipse.jface.dialogs.Dialog#createDialogArea(org.eclipse.swt.widgets.Composite)
52 protected Control
createDialogArea(Composite parent
) {
53 Composite composite
= (Composite
) super.createDialogArea(parent
);
54 //add controls to composite as necessary
57 // Label for the heading
58 final CLabel titleLabel
= new CLabel(composite
, SWT
.NONE
);
59 titleLabel
.setText("User Login");
61 // Label for the username
62 final CLabel userNameLabel
= new CLabel(composite
, SWT
.NONE
);
63 userNameLabel
.setText("Username");
65 // Textfield for the username
66 usernameText
= new Text(composite
, SWT
.BORDER
);
67 usernameText
.setLayoutData(new GridData(SWT
.FILL
, SWT
.FILL
, true, true));
69 // Label for the password
70 final CLabel passwordLabel
= new CLabel(composite
, SWT
.NONE
);
71 passwordLabel
.setText("Password");
73 // Textfield for the password
74 passwordText
= new Text(composite
, SWT
.BORDER
);
75 passwordText
.setEchoChar('*');
76 passwordText
.setLayoutData(new GridData(SWT
.FILL
, SWT
.FILL
, true, true));
84 * @see org.eclipse.jface.dialogs.Dialog#okPressed()
87 protected void okPressed() {
89 String username
= usernameText
.getText().trim();
90 String password
= passwordText
.getText().trim();
92 // password is stored as salted md5 hash
93 String passwordHash
= password
;
95 UsernamePasswordAuthenticationToken token
= new UsernamePasswordAuthenticationToken(username
, passwordHash
);
98 CdmStore
.getAuthenticationManager().authenticate(token
);
99 }catch(BadCredentialsException e
){
100 logger
.error("Bad credentials");
101 }catch(IllegalArgumentException e
){
102 logger
.error("Null argument for either user or password");