1 /*******************************************************************************
2 * Copyright (c) 2012 - 2015 hangum.
3 * All rights reserved. This program and the accompanying materials
4 * are made available under the terms of the GNU Lesser Public License v2.1
5 * which accompanies this distribution, and is available at
6 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
9 * hangum - initial API and implementation
10 ******************************************************************************/
11 package com
.hangum
.tadpole
.engine
.security
;
13 import org
.apache
.commons
.lang
.StringUtils
;
14 import org
.apache
.log4j
.Logger
;
15 import org
.eclipse
.jface
.dialogs
.IDialogConstants
;
16 import org
.eclipse
.jface
.dialogs
.MessageDialog
;
17 import org
.eclipse
.swt
.SWT
;
18 import org
.eclipse
.swt
.events
.KeyAdapter
;
19 import org
.eclipse
.swt
.events
.KeyEvent
;
20 import org
.eclipse
.swt
.graphics
.Point
;
21 import org
.eclipse
.swt
.layout
.GridData
;
22 import org
.eclipse
.swt
.layout
.GridLayout
;
23 import org
.eclipse
.swt
.widgets
.Composite
;
24 import org
.eclipse
.swt
.widgets
.Control
;
25 import org
.eclipse
.swt
.widgets
.Label
;
26 import org
.eclipse
.swt
.widgets
.Shell
;
27 import org
.eclipse
.swt
.widgets
.Text
;
29 import com
.hangum
.tadpole
.commons
.libs
.core
.message
.CommonMessages
;
30 import com
.hangum
.tadpole
.commons
.otp
.core
.GetOTPCode
;
31 import com
.hangum
.tadpole
.engine
.Messages
;
32 import com
.hangum
.tadpole
.engine
.manager
.TadpoleSQLManager
;
33 import com
.hangum
.tadpole
.engine
.query
.dao
.system
.UserDBDAO
;
34 import com
.hangum
.tadpole
.session
.manager
.SessionManager
;
45 public class DBPasswordAndOTPDialog
extends PasswordDialog
{
46 private static final Logger logger
= Logger
.getLogger(DBPasswordAndOTPDialog
.class);
53 public DBPasswordAndOTPDialog(Shell parentShell
, UserDBDAO userDB
) {
54 super(parentShell
, userDB
);
58 protected void configureShell(Shell newShell
) {
59 super.configureShell(newShell
);
60 newShell
.setText(Messages
.get().DBLockDialog_0
);
64 * Create contents of the dialog.
68 protected Control
createDialogArea(Composite parent
) {
69 Composite container
= (Composite
) super.createDialogArea(parent
);
70 container
.setLayout(new GridLayout(2, false));
72 Label lblDbPassword
= new Label(container
, SWT
.NONE
);
73 lblDbPassword
.setText(CommonMessages
.get().Password
);
75 textPassword
= new Text(container
, SWT
.BORDER
| SWT
.PASSWORD
);
76 textPassword
.addKeyListener(new KeyAdapter() {
78 public void keyReleased(KeyEvent e
) {
79 if(e
.keyCode
== SWT
.Selection
) {
84 textPassword
.setLayoutData(new GridData(SWT
.FILL
, SWT
.CENTER
, true, false, 1, 1));
86 Label lblOtp
= new Label(container
, SWT
.NONE
);
87 lblOtp
.setText("OTP Code");
89 textOTP
= new Text(container
, SWT
.BORDER
);
90 textOTP
.setLayoutData(new GridData(SWT
.FILL
, SWT
.CENTER
, true, false, 1, 1));
91 textOTP
.addKeyListener(new KeyAdapter() {
93 public void keyReleased(KeyEvent e
) {
94 if(e
.keyCode
== SWT
.Selection
) {
107 * @see org.eclipse.jface.dialogs.Dialog#okPressed()
110 protected void okPressed() {
111 String strOTPCode
= textOTP
.getText();
113 if("".equals(strOTPCode
)) {
114 MessageDialog
.openError(getShell(), CommonMessages
.get().Error
, Messages
.get().OTPEmpty
);
119 GetOTPCode
.isValidate(SessionManager
.getEMAIL(), SessionManager
.getOTPSecretKey(), strOTPCode
);
120 } catch(Exception e
) {
121 logger
.error("OTP check", e
);
122 MessageDialog
.openError(getShell(), CommonMessages
.get().Error
, e
.getMessage());
128 // 실제 접속 되는지 테스트해봅니다.
130 userDB
.setPasswd(StringUtils
.trim(textPassword
.getText()));
131 TadpoleSQLManager
.getInstance(userDB
);
132 } catch(Exception e
) {
133 logger
.error("Test Passwd+opt Connection error ");
135 String msg
= e
.getMessage();
136 if(StringUtils
.contains(msg
, "No more data to read from socket")) {
137 MessageDialog
.openWarning(getShell(), CommonMessages
.get().Warning
, msg
+ CommonMessages
.get().Check_DBAccessSystem
);
139 MessageDialog
.openWarning(getShell(), CommonMessages
.get().Warning
, msg
);
141 textPassword
.setFocus();
150 * Create contents of the button bar.
154 protected void createButtonsForButtonBar(Composite parent
) {
155 createButton(parent
, IDialogConstants
.OK_ID
, CommonMessages
.get().Confirm
, true);
156 createButton(parent
, IDialogConstants
.CANCEL_ID
, CommonMessages
.get().Cancel
, false);
160 * Return the initial size of the dialog.
163 protected Point
getInitialSize() {
164 return new Point(402, 148);