📄 authentication.java
字号:
/*
* @author Reghu
* @version 1.0
*
* Development Environment : Oracle9i JDeveloper
* Name of the Application : Authentication.java
* Creation/Modification History :
*
* Reghu 30-Dec-2002 Created
*
*/
package oracle.otnsamples.vsm.client;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.Rectangle;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.BorderFactory;
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPasswordField;
import javax.swing.JTextField;
import oracle.otnsamples.util.ServiceLocator;
import oracle.otnsamples.vsm.services.ProfileException;
import oracle.otnsamples.vsm.services.ProfileManagement;
import oracle.otnsamples.vsm.services.ProfileManagementHome;
import oracle.otnsamples.vsm.services.data.Profile;
/**
* This java file prompts the login page for Admin utility of VSM application.
*
* @author Reghu
* @version 1.0
*/
public class Authentication extends JDialog implements Runnable {
// UI components
private JButton cancel = new JButton();
private JButton login = new JButton();
private JLabel header = new JLabel();
private JLabel password = new JLabel();
private JLabel username = new JLabel();
private JPasswordField passwd = new JPasswordField();
private JTextField user = new JTextField();
private static SPScreen splash;
private Thread process = null;// Thread object for dataprocessing
/**
* Constructor, initializes and sets up listeners for the GUI components of
* the application
*/
public Authentication() {
try {
jbInit();
} catch(Exception e) {
e.printStackTrace();
}
}
/**
* This method calls the appropriate method for each thread
*/
public void run() {
try {
if (process == Thread.currentThread()) {
splash = new SPScreen();
AdminSample.init();
}
} catch (Exception e) {
e.printStackTrace();
}
}
/**
* Method to start a thread for event processing
*/
public void processEvent() {
if( process == null ) {
process = new Thread(this,"ProcessThread");
process.start();
}
}
/**
* Initialize all the GUI components and the layout
* @exception Exception
*/
private void jbInit() throws Exception {
this.getContentPane().setLayout(null);
this.setSize(new Dimension(425, 248));
this.setTitle("VSM Admin Login Information");
this.setResizable(false);
username.setText("User Name");
username.setBounds(new Rectangle(80, 50, 85, 35));
username.setFont(new Font("Book Antiqua", 1, 14));
username.setForeground(new Color(131, 131, 87));
password.setText("Password");
password.setBounds(new Rectangle(80, 85, 85, 35));
password.setFont(new Font("Book Antiqua", 1, 14));
password.setForeground(new Color(131, 131, 87));
user.setBounds(new Rectangle(165, 55, 160, 25));
user.setEditable(true);
header.setBounds(new Rectangle(25, 15, 370, 190));
header.setBorder(BorderFactory.createTitledBorder("OTN WebStore Administration"));
header.setBackground(new Color(223, 223, 191));
passwd.setBounds(new Rectangle(165, 90, 160, 25));
login.setText("Login");
login.setBounds(new Rectangle(150, 135, 75, 30));
login.setForeground(new Color(131, 131, 87));
login.setBackground(new Color(223, 223, 191));
login.setFont(new Font("Book Antiqua", 1, 14));
// Action to be prformed when the user logins to the application
login.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
String msg = null;
if((user.getText() == null) || "".equals(user.getText().trim())) {
JOptionPane.showMessageDialog(
Authentication.this,
"Please Enter User Name", "Error",
JOptionPane.ERROR_MESSAGE);
} else if(
(passwd.getPassword() == null) ||
(passwd.getPassword().length == 0)) {
JOptionPane.showMessageDialog(
Authentication.this,
"Please Enter Password", "Error",
JOptionPane.ERROR_MESSAGE);
} else {
String userName = user.getText();
String password = new String(passwd.getPassword());
ProfileManagement profRemote = null;
try {
// Get the EJB Home
ProfileManagementHome profHome =
(ProfileManagementHome) ServiceLocator.getLocator()
.getService("ProfileManagement");
// Get Remote Interface
profRemote = profHome.create();
Profile prof = profRemote.validateUser(userName, password);
if(prof.getRole().equals("malladmin")) {
Authentication.this.setVisible(false);
Authentication.this.dispose();
processEvent();
} else {
JOptionPane.showMessageDialog(
Authentication.this,
"Don't have the privileges of Admin",
"Error", JOptionPane.ERROR_MESSAGE);
}
} catch(ProfileException exp) {
JOptionPane.showMessageDialog(
Authentication.this,
"Invalid user credentials", "Error",
JOptionPane.ERROR_MESSAGE);
} catch(Exception exp) {
JOptionPane.showMessageDialog(
Authentication.this, exp.toString(),
"Error", JOptionPane.ERROR_MESSAGE);
} finally {
try {
if(profRemote != null) {
profRemote.remove();
}
} catch(Exception ex) {
// do nothing
}
}
}
}
});
cancel.setText("Exit");
cancel.setBounds(new Rectangle(245, 135, 70, 30));
cancel.setForeground(new Color(131, 131, 87));
cancel.setBackground(new Color(223, 223, 191));
cancel.setActionCommand("exit");
cancel.setFont(new Font("Book Antiqua", 1, 14));
this.getContentPane().add(header, null);
this.getContentPane().add(cancel, null);
this.getContentPane().add(login, null);
this.getContentPane().add(passwd, null);
this.getContentPane().add(user, null);
this.getContentPane().add(password, null);
this.getContentPane().add(username, null);
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
Dimension frameSize = this.getSize();
header.setFont(new Font("Book Antiqua", 1, 11));
user.setNextFocusableComponent(password);
username.setBackground(new Color(240, 240, 230));
cancel.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
System.exit(0);
}
});
header.setForeground(new Color(223, 223, 191));
this.setBackground(new Color(223, 223, 191));
if(frameSize.height > screenSize.height) {
frameSize.height = screenSize.height;
}
if(frameSize.width > screenSize.width) {
frameSize.width = screenSize.width;
}
this.setLocation(
(screenSize.width - frameSize.width) / 2,
(screenSize.height - frameSize.height) / 2);
this.setVisible(true);
}
/**
* Main entry point for the admin utility of the VSM application.
* @param args
*/
public static void main(String[] args) {
new Authentication();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -