import java.net.*;
import java.awt.*;
import java.awt.event.*;
import java.io.*;
import java.util.*;
import javax.naming.*;
import javax.naming.directory.*;
import javax.swing.*;public class LDAPTest {
public static void main(String[] args) {
JFrame frame = new LDAPFrame();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true); }}
class LDAPFrame extends JFrame
{
public LDAPFrame()
{
setTitle("LDAPTest");
setSize(DEFAULT_WIDTH,DEFAULT_HEIGHT);

JPanel northPanel = new JPanel();
northPanel.setLayout(new java.awt.GridLayout(1,2,3,1));
northPanel.add(new JLabel("uid"),SwingConstants.RIGHT);
uidField = new JTextField();
northPanel.add(uidField);
add(northPanel,BorderLayout.NORTH);

JPanel buttonPanel = new JPanel();
add(buttonPanel,BorderLayout.SOUTH);

findButton =new JButton("Find");
findButton.addActionListener(new 
        ActionListener()
                 {
               public void actionPerformed(ActionEvent event)
               {
                findEntry();
               }
                 });
buttonPanel.add(findButton);

saveButton= new JButton("Save");
saveButton.addActionListener(new 
    ActionListener()
            {
          public void actionPerformed(ActionEvent event)
          {
           saveEntry();
          }
            });
buttonPanel.add(findButton);

deleteButton = new JButton("Delete");
deleteButton.addActionListener(new 
        ActionListener()
                 {
               public void actionPerformed (ActionEvent event)
               {
                deleteEntry();
               }
                 });
buttonPanel.add(deleteButton);

addWindowListener(new WindowAdapter()
                {
               public void windowClosing(WindowEvent event)
               {
                try
                {
                if(context!=null) context.close();
                }
                catch(NamingException e)
                {
                e.printStackTrace();
                }
               }
                });
}

public void findEntry()
{
try
{
if(scrollPane!=null) remove (scrollPane);
String dn="uid="+uidField.getText()+",ou=people,dc=mycompany,dc=com";
if(context==null)  context=getContext();
attrs=context.getAttributes(dn);
dataPanel = new DataPanel(attrs);
scrollPane= new JScrollPane(dataPanel);
add(scrollPane,BorderLayout.CENTER);
validate();
uid=uidField.getText();
}
catch(NamingException e)
{
JOptionPane.showMessageDialog(this, e);
}
catch(IOException e)
{
JOptionPane.showMessageDialog(this, e);

}
}

public void saveEntry()
{
try
{
if(dataPanel==null) return;
if(context==null)  context=getContext();
if(uidField.getText().equals(uid))
{
String dn="uid="+uidField.getText()+",ou=people,dc=mycompany,dc=com";
Attributes editedAttrs= dataPanel.getEditedAttributes();
NamingEnumeration<?extends Attribute> attrEnum= attrs.getAll();
while(attrEnum.hasMore())
{
Attribute attr =attrEnum.next();
String id= attr.getID();
Object value= attr.get();
Attribute editedAttr= editedAttrs.get(id);
if(editedAttr!=null&&attr.get().equals(editedAttr.get()))
context.modifyAttributes(dn,DirContext.REPLACE_ATTRIBUTE,new BasicAttributes(id,editedAttr.get()));
}
}
else 
{
String dn="uid="+uidField.getText()+",ou=people,dc=mycompany,dc=com";
attrs=dataPanel.getEditedAttributes();
Attribute objclass= new BasicAttribute("objectClass");
objclass.add("uidObject");
objclass.add("perosn");
attrs.put(objclass);
attrs.put("uid",uidField.getText());
context.createSubcontext(dn,attrs);
}
findEntry();
}
catch(NamingException e)
{
JOptionPane.showMessageDialog(LDAPFrame.this, e);
e.printStackTrace();
}
catch(IOException e)
{
JOptionPane.showMessageDialog(LDAPFrame.this,e);
e.printStackTrace();
}
}

public void deleteEntry()
{
try
{
String dn="uid="+uidField.getText()+",ou=people,dc=mycompany,dc=com";
if(context==null) context=getContext();
context.destroySubcontext(dn);
uidField.setText("");
remove(scrollPane);
scrollPane=null;
repaint();
}
catch(NamingException e)
{
JOptionPane.showMessageDialog(LDAPFrame.this, e);
e.printStackTrace();
}
catch(IOException e)
{
JOptionPane.showMessageDialog(LDAPFrame.this,e);
e.printStackTrace();
}
}

public static DirContext getContext() throws NamingException ,IOException
{
Properties props = new Properties();
FileInputStream in = new FileInputStream("ldapserver.properties");
props.load(in);
in.close();

String url = props.getProperty("ldap.url");
String username= props.getProperty("ldap.username");
String password= props.getProperty("ldap.password");

Hashtable<String,String> env = new Hashtable<String,String>();
env.put(Context.SECURITY_PRINCIPAL, username);
env.put(Context.SECURITY_CREDENTIALS, password);
DirContext initial = new InitialDirContext(env);
DirContext context= (DirContext) initial.lookup(url);

return context;
}

public static final int DEFAULT_WIDTH=300;
public static final int DEFAULT_HEIGHT=200;

private JButton findButton;
private JButton saveButton;
private JButton deleteButton;

private JTextField uidField;
private DataPanel dataPanel;
private Component scrollPane;

private DirContext context;
private String uid;
private Attributes attrs;

}class DataPanel extends JPanel
{
public DataPanel(Attributes attrs) throws NamingException
{
setLayout(new java.awt.GridLayout(0,2,3,1));
NamingEnumeration <? extends Attribute> attrEnum= attrs.getAll();
while(attrEnum.hasMore())
{
Attribute attr = attrEnum.next();
String id = attr.getID();

NamingEnumeration<?> valueEnum = attr.getAll();
while(valueEnum.hasMore())
{
Object value = valueEnum.next();
if(id.equals("userPassword"))
                   value= new String((byte[])value);
JLabel idLabel = new JLabel(id,SwingConstants.RIGHT);
JTextField valueField = new JTextField(""+value);
if(id.equals("objectClass"))
valueField.setEditable(false);
if(!id.equals("uid"))
{
add(idLabel);
add(valueField);
}
}
}
}
public Attributes getEditedAttributes()
{
Attributes attrs = new BasicAttributes();
for(int i=0;i<getComponentCount();i++)
{
JLabel idLabel=(JLabel)getComponent(i);
JTextField valueField= (JTextField) getComponent(i+1);
String id= idLabel.getText();
String value=valueField.getText();
if(id.equals("userPassword"))
attrs.put("userPassword",value.getBytes());
else if(!id.equals("")&&!id.equals("objectClass"))
attrs.put(id,value);
}
return attrs;
}
}弄了很久,还是在dataPanel = new DataPanel(attrs)这里出现w问题,但是我看后面的那个DataPanel有这个方法的,不知道是什么问题,还有就是attrs=dataPanel.getEditedAttributes()这个也出现问题,我感觉应该是第一个的问题导致这个出现的问题,请大家帮忙看一下,这个到底是什么问题,谢谢,在线等。

解决方案 »

  1.   

    MPLS
    LSP IP Ping/LSP IP Jitter测试
    LSP IP Ping用于检测LSP的连通性,并对其时延、丢包等性能指标进行监测;LSP IP Iitter用于检测LSP的连通性,并对其时延、丢包、抖动等性能指标进行监测。NQA提供LSP Jitter以对两种类型的LSP进行可达性检测,并从源端接收到的信息中计算出数据包从源端到目的端和从目的端到源端的最大抖动时间、最小抖动时间及平均抖动时间,从而清晰的反映出MPLS网络状况。时延指标上限抖动指标平均抖动指标丢包率指标LspDelayKPI
    说明 LSP时延指标用来度量一段链路或路径的平均时延,LSP IP Ping/LSP IP Jitter测试都可以输出LSP时延指标。当前只有内置探针支持LSP IP Ping/LSP IP Jitte测试
     
    上限抖动指标
    UpperJitterKPI
    说明 只有LSP IP Jitter测试能够输出LSP抖动指标。上限抖动指标仅对超过阈值的抖动报文进行统计,因此相对平均抖动指标,上限抖动指标更精确的统计报文抖动的情况。该指标该指标反映了一段时间内报文的到达情况,一定程度上减少了由于抖动造成的突发拥塞或丢包计算造成的影响。当前只有内置探针支持LSP IP Ping/LSP IP Jitter测试。
     
      

  2.   

    平均抖动指标
    AverageJitterKPI
    说明 只有LSP IP Jitter测试能够输出LSP抖动指标。平均抖动是多次抖动的平均值,用来度量MPLS网络中报文抖动的严重程度。当前只有内置探针支持LSP IP Ping/LSP IP Jitter测试。
     
    LSP TE Ping/LSP TE Jitter测试
    LSP TE Ping用于检测LSP TE隧道的连通性,并对其时延、丢包等性能指标进行监测;LSP TE Jitter用于检测LSP TE隧道的连通性,并对其时延、丢包、抖动等性能指标进行监测。NQA提供LSP Jitter以对两种类型的LSP进行可达性检测,并从源端接收到的信息中计算出数据包从源端到目的端和从目的端到源端的最大抖动时间、最小抖动时间及平均抖动时间,从而清晰的反映出MPLS网络状况。
    LSP TE Ping/LSP TE Jitter测试
    LSP TE Ping用于检测LSP TE隧道的连通性,并对其时延、丢包等性能指标进行监测;LSP TE Jitter用于检测LSP TE隧道的连通性,并对其时延、丢包、抖动等性能指标进行监测。NQA提供LSP Jitter以对两种类型的LSP进行可达性检测,并从源端接收到的信息中计算出数据包从源端到目的端和从目的端到源端的最大抖动时间、最小抖动时间及平均抖动时间,从而清晰的反映出MPLS网络状况。
    上限抖动指标
    UpperJitterKPI
    说明 只有LSP TE Jitter测试能够输出LSP抖动指标。上限抖动指标仅对超过阈值的抖动报文进行统计,因此相对平均抖动指标,上限抖动指标更精确的统计报文抖动的情况。该指标该指标反映了一段时间内报文的到达情况,一定程度上减少了由于抖动造成的突发拥塞或丢包计算造成的影响。当前只有内置探针支持LSP TE Ping/LSP TE Jitter测试。
     
    丢包率指标
    LspLossRatioKPI
    说明 LSP丢包率指标用来度量报文单向丢包的严重程度。LSP TE Ping/LSP TE Jitter测试都可以输出LSP时延指标。当前只有内置探针支持LSP TE Ping/LSP TE Jitter测试