📄 kerberosnamecreator.java
字号:
/*
Simple Implementation of Kerberos protocol v5
Copyright (C) 2003 Thia Yeo Ching (tycordinal@yahoo.co.uk)
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
package SimpleKerberos.guitool;
import SimpleKerberos.IAuthenticationService;
import SimpleKerberos.AuthenticationServiceFactory;
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
public class KerberosNameCreator extends JFrame
implements ActionListener
{
public static final String TITLE = "Kerberos Name Creator";
private JLabel nameLabel;
private JLabel hostLabel;
private JLabel pwdLabel;
private JLabel retypeLabel;
private JTextField hostText;
private JTextField nameText;
private JPasswordField pwdText;
private JPasswordField retypeText;
private JButton okButton;
private StatusArea statusArea;
private static final String ELLIPSIS = "...";
private static final String RETYPE_PWD = "Please retype your password twice exactly";
private static final String EMPTY = "";
public static void main(String args[])
{
new KerberosNameCreator().setVisible(true);
}
public KerberosNameCreator()
{
super(TITLE);
hostLabel = new JLabel("Kerberos Host Name");
nameLabel = new JLabel("Name");
pwdLabel = new JLabel("Password");
retypeLabel = new JLabel("Retype Password");
hostText = new JTextField();
nameText = new JTextField();
pwdText = new JPasswordField();
retypeText = new JPasswordField();
okButton = new JButton("OK");
statusArea = new StatusArea();
LayoutManager detailsLayout = new GridLayout(4, 2);
Container detailsPane = new Container();
detailsPane.setLayout(detailsLayout);
detailsPane.add(hostLabel);
detailsPane.add(hostText);
detailsPane.add(nameLabel);
detailsPane.add(nameText);
detailsPane.add(pwdLabel);
detailsPane.add(pwdText);
detailsPane.add(retypeLabel);
detailsPane.add(retypeText);
LayoutManager contentLayout = new GridLayout(3, 1);
Container contentPane = this.getContentPane();
contentPane.setLayout(contentLayout);
contentPane.add(detailsPane);
contentPane.add(okButton);
contentPane.add(statusArea);
okButton.addActionListener(this);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.pack();
}
private boolean checkIdenticalPassword()
{
if ((pwdText.getPassword().length > 0 && retypeText.getPassword().length > 0)
&&
(new String(pwdText.getPassword()).equals(new String(retypeText.getPassword()))))
{
return true;
}
statusArea.appendStatus(RETYPE_PWD);
pwdText.setText(EMPTY);
retypeText.setText(EMPTY);
return false;
}
public void actionPerformed(ActionEvent e)
{
if (e.getSource() == okButton)
{
statusArea.clearStatus();
if (checkDetails())
{
createKerberosName(hostText.getText(), nameText.getText(), new String(pwdText.getPassword()));
}
}
}
private boolean checkName()
{
if (nameText.getText().length() > 0)
{
return true;
}
statusArea.appendStatus("Please enter your name");
return false;
}
private boolean checkHost()
{
if (hostText.getText().length() > 0)
{
return true;
}
statusArea.appendStatus("Please enter your host");
return false;
}
private boolean checkDetails()
{
boolean c1 = checkIdenticalPassword();
boolean c2 = checkName();
boolean c3 = checkHost();
return c1 && c2 && c3;
}
private boolean do_createKerberosName(IAuthenticationService auth,
String name, String pwd)
{
try
{
if (auth.createName(name, pwd))
{
return true;
}
statusArea.appendStatus("name "+name+" existed, cannot create again.");
}
catch (Exception e)
{
statusArea.appendStatus(e.toString());
e.printStackTrace();
}
return false;
}
private void createKerberosName(String host, String name, String pwd)
{
statusArea.appendStatus("Contacting host " + host + ELLIPSIS);
// assuming that the services are running
IAuthenticationService auth = AuthenticationServiceFactory.getRemoteInstance(host);
if (auth != null)
{
if (do_createKerberosName(auth, name, pwd))
{
statusArea.appendStatus("name successfully created");
}
return;
}
//clearStatus();
statusArea.appendStatus("failed to contact host " + host);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -