package com.novell.admin.ndssnapins.loginMethods.CPassword;
import java.awt.*;
import java.awt.event.*;
import java.io.*;
import java.util.*;
import java.text.*;
import javax.swing.*;
import com.novell.admin.common.ui.*;
import com.novell.admin.ns.*;
import com.novell.admin.ns.nds.*;
import com.novell.admin.snapins.creator.*;
import com.novell.application.console.snapin.*;
import com.novell.application.console.widgets.*;
import com.novell.utility.localization.*;
import com.novell.utility.nmsgbox.*;
import com.novell.security.japi.nmas.*;
import com.novell.admin.security.util.*;
public final class CPasswordUserCreatorSnapin extends CreatorSnapinPanel
implements ItemListener
{
private final String snapinName = CPassword.getString(CPassword.CPassword_SNAPIN_NAME);
private final String snapinDescription = CPassword.getString(CPassword.CPassword_METHOD_SNAPIN_DESCRIPTION);
private Shell shell;
private String treeName;
private String userDN;
private String coUserDN;
private String cPasswordLabel = CPassword.getString(CPassword.CPassword_LABEL);
private String cPasswordEntryLabel = CPassword.getString(CPassword.CPassword_ENTRY_LABEL);
private String cPasswordNotSupportedLabel = CPassword.getString(CPassword.CPassword_NOT_SUPPORTED_LABEL);
private String cPasswordConfirmLabel = CPassword.getString(CPassword.CPassword_CONFIRM_LABEL);
private String cPasswordAllowLabel = CPassword.getString(CPassword.CPassword_ALLOW_LABEL);
private String cPasswordInstructions = CPassword.getString(CPassword.CPassword_INSTRUCTIONS);
private NDSObjectAttribute hostServerAttrib = null;
private JCheckBox cPasswordAllowCheck = new JCheckBox(cPasswordAllowLabel, false);
private JPasswordField cPasswordEntryField = new JPasswordField(20);
private JLabel cPasswordEntryJLabel = new JLabel(cPasswordEntryLabel);
private boolean debug = false;
private boolean cPasswordAllow = false;
private Color colorOff;
private Color colorOn;
public boolean initSnapin(InitSnapinInfo info)
{
shell = info.getShell();
if (OSUtil.getOStype() != OSUtil.NETWARE)
{
try
{
System.loadLibrary("NMASWrap");
}
catch(UnsatisfiedLinkError ex)
{
NMsgBox msg = new NMsgBox(shell.getShellFrame(),
CPassword.getString(CPassword.CPassword_LOAD_LIBRARY_FAILED_TITLE),
CPassword.getString(CPassword.CPassword_LOAD_LIBRARY_FAILED_MESSAGE),
3, null, null);
msg.show();
return false;
}
}
return true;
}
public void shutdownSnapin( )
{
}
public String getSnapinName()
{
return snapinName;
}
public String getSnapinDescription()
{
return snapinDescription;
}
public String[] getHandledAttributeNames()
{
String[] attributes = new String[1];
attributes[0] = "";
return attributes;
}
public ObjectAttribute[] getAttributes()
{
ObjectAttribute[] attribs = new ObjectAttribute[1];
return attribs;
}
public boolean canCreate()
{
return checkData();
}
public void layoutControls()
{
int ccode, i;
setLayout(new BorderLayout(5, 10));
JPanel centerPanel = new JPanel(new BorderLayout(0, 10));
JPanel templatePanel = new JPanel(new BorderLayout(20, 0));
if (OSUtil.getOStype() == OSUtil.NETWARE)
{
centerPanel.add(new JLabel(cPasswordNotSupportedLabel));
}
else
{
cPasswordAllow = false;
cPasswordAllowCheck.setSelected(false);
colorOn = cPasswordEntryField.getBackground();
colorOff = cPasswordEntryJLabel.getBackground();
cPasswordEntryJLabel.setEnabled(false);
cPasswordEntryField.setEnabled(false);
cPasswordEntryField.setBackground(colorOff);
cPasswordEntryField.setEchoChar('*');
cPasswordAllowCheck.addItemListener(this);
templatePanel.add(cPasswordAllowCheck, BorderLayout.NORTH);
templatePanel.add(new Canvas(), BorderLayout.WEST);
JPanel tbPanel = new JPanel(new BorderLayout(5, 0));
tbPanel.add(cPasswordEntryJLabel, BorderLayout.NORTH);
tbPanel.add(cPasswordEntryField, BorderLayout.CENTER);
templatePanel.add(tbPanel, BorderLayout.CENTER);
centerPanel.add(templatePanel, BorderLayout.NORTH);
}
add(centerPanel, BorderLayout.CENTER);
}
public void itemStateChanged(ItemEvent event)
{
Object src = event.getSource();
int i;
String selectedClearance, tmpLabel;
if (src == cPasswordAllowCheck)
{
cPasswordAllow = cPasswordAllowCheck.isSelected();
if (cPasswordAllow)
{
cPasswordEntryJLabel.setEnabled(true);
cPasswordEntryField.setEnabled(true);
cPasswordEntryField.setBackground(colorOn);
}
else
{
cPasswordEntryJLabel.setEnabled(false);
cPasswordEntryField.setEnabled(false);
cPasswordEntryField.setBackground(colorOff);
}
}
}
public void onPostCreate(ObjectEntry oe)
{
if (null != oe)
{
coUserDN = oe.getFullName();
int slashLoc = coUserDN.indexOf('/');
treeName = coUserDN.substring(0, slashLoc);
userDN = coUserDN.substring(slashLoc+1, coUserDN.length());
}
int ccode;
if (cPasswordAllow)
{
if ((ccode = NMASWrap.NMAS_PutLoginConfig(treeName, userDN, CPassword.MethodIDLen, CPassword.MethodID, CPassword.AllowTag, CPassword.AllowDataLen, CPassword.AllowData)) != 0)
{
String message = CPassword.getString(CPassword.CPassword_PLC_ERR_MSG) + ccode;
if(debug) System.out.println(message + "--> " + treeName + ", " + userDN + ", " + CPassword.MethodIDLen + ", " + CPassword.MethodID + ", " + CPassword.AllowTag + ", " + CPassword.AllowDataLen + ", " + CPassword.AllowData);
if(debug) System.out.println("coUserDN--> " + coUserDN);
NMsgBox msg = new NMsgBox(shell.getShellFrame(), CPassword.getString(CPassword.CPassword_ENTRY_ERR_TITLE), message, NMsgBox.ERROR, null, null);
msg.show();
return;
}
String CPasswordString = new String (cPasswordEntryField.getPassword());
if(debug) System.out.println(CPasswordString);
if(debug) System.out.println("Saving password...");
String CPasswordDataString = CPassword.ClearTextID + CPasswordString + "\0";
byte CPasswordData[] = CPasswordDataString.getBytes();
if ((ccode = NMASWrap.NMAS_PutLoginSecret(treeName, userDN, CPassword.MethodIDLen, CPassword.MethodID, CPassword.SecretTag, CPasswordData.length, CPasswordData)) != 0)
{
String message = "Error" + ccode + "from NMAS_PutLoginSecret";
if(debug) System.out.println(message);
NMsgBox msg = new NMsgBox(shell.getShellFrame(), "Password Entry Error", message, NMsgBox.ERROR, null, null);
msg.show();
}
}
}
public void onNameSet(String name)
{
}
private boolean checkData()
{
return true;
}
}