최신버전에 맞는 타겟플렛폼 설정.
[Tadpole.git] / com.hangum.tadpole.commons.sql / src / com / hangum / tadpole / engine / security / DBPasswordAndOTPDialog.java
blob8e144780dd02461630b4a9bb90e9ba531569bed8
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
7 *
8 * Contributors:
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;
36 /**
37 * DB Lock Dialog
40 * @author hangum
41 * @version 1.6.1
42 * @since 2015. 3. 24.
45 public class DBPasswordAndOTPDialog extends PasswordDialog {
46 private static final Logger logger = Logger.getLogger(DBPasswordAndOTPDialog.class);
47 private Text textOTP;
49 /**
50 * Create the dialog.
51 * @param parentShell
53 public DBPasswordAndOTPDialog(Shell parentShell, UserDBDAO userDB) {
54 super(parentShell, userDB);
57 @Override
58 protected void configureShell(Shell newShell) {
59 super.configureShell(newShell);
60 newShell.setText(Messages.get().DBLockDialog_0);
63 /**
64 * Create contents of the dialog.
65 * @param parent
67 @Override
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() {
77 @Override
78 public void keyReleased(KeyEvent e) {
79 if(e.keyCode == SWT.Selection) {
80 textOTP.setFocus();
83 });
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() {
92 @Override
93 public void keyReleased(KeyEvent e) {
94 if(e.keyCode == SWT.Selection) {
95 okPressed();
98 });
100 initUI();
101 textOTP.setFocus();
103 return container;
106 /* (non-Javadoc)
107 * @see org.eclipse.jface.dialogs.Dialog#okPressed()
109 @Override
110 protected void okPressed() {
111 String strOTPCode = textOTP.getText();
113 if("".equals(strOTPCode)) {
114 MessageDialog.openError(getShell(), CommonMessages.get().Error, Messages.get().OTPEmpty);
115 textOTP.setFocus();
116 return;
118 try {
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());
123 textOTP.setFocus();
125 return;
128 // 실제 접속 되는지 테스트해봅니다.
129 try {
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);
138 } else {
139 MessageDialog.openWarning(getShell(), CommonMessages.get().Warning, msg);
141 textPassword.setFocus();
143 return;
146 super.okPressed();
150 * Create contents of the button bar.
151 * @param parent
153 @Override
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.
162 @Override
163 protected Point getInitialSize() {
164 return new Point(402, 148);