Java LDAP用户密码验证
到http://download.csdn.net/source/1781441下载JLDAP.jar文件
验证代码段如下:
DirContext ctx = null;
String account = "aa"; //用户名
String password = "123"; //登录密码
String root = "dc=scut,dc=edu,dc=cn"; // root
Hashtable env = new Hashtable();
env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory");
env.put(Context.PROVIDER_URL, "ldap://10.10.10.10:389/" + root);
env.put(Context.SECURITY_AUTHENTICATION, "simple");
env.put(Context.SECURITY_PRINCIPAL, account+"@xxx.com" );
env.put(Context.SECURITY_CREDENTIALS, password);
try {
// 链接ldap
ctx = new InitialDirContext(env);
JOptionPane.showMessageDialog(this, "认证成功");
System.out.println("认证成功");
} catch (javax.naming.AuthenticationException e) {
JOptionPane.showMessageDialog(this, "认证失败");
System.out.println("认证失败");
} catch (Exception e) {
JOptionPane.showMessageDialog(this, "认证出错");
System.out.println("认证出错:");
e.printStackTrace();
}
相关文档:
继承:
java只有单继承,不能同时继承多个类
class Animal{}
class Fish extends Aniaml{}
super.(父类中与子类相同的方法)();//super-特殊的变量,用于访问父类中与子类相同的方法,如下
//父类
class Fish extends animal
{
void output()
{
System.out.println("Fish");
&n ......
import java.util.LinkedList;
//单向队列
public class Queue {
public Queue() {
}
private LinkedList list = new LinkedList();
public void pu ......
JSP:javascript 和 struts部分
<table width="100%" border="0" cellspacing="0" cellpadding="6">
<tr>
<td>
<span class="txt1">三级单位:</span>
<html:select property="oilarea" style="width:182" styleId="area" onchange="javascript:fillWell()"&g ......
/*从服务器中下载文件到本地*/
/*url:文件存放在服务器的地址;target:要保存的路径*/
public String DownloadFile(String url,String target){
URLConnection con=null;
URL theUrl=null;
try {
theUrl=new URL(url);//建立地址
......
/*对传入的向量进行排序(按照参与者姓名排序)*/ public Vector[] Sort(Vector vtID, Vector vtName) {
Vector[] vt = {vtID, vtName};
String exChangeID = null;
String exChangeName = null;
//Comparator cmp = Collator.getInstance(java.util.Locale.CHINA);
......