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();
}
相关文档:
C++与Java的语法区别
首先,两个大的不同是主函数和怎样编译的不同,接下来是许多小的区别。
main 函数
C++
//自由浮动的函数
int main( int argc, char* argv[])
{
printf( "Hello, world" );
}
Java
// 每个函数都必须是一个类的一部分;当java <class>运行是一个特定类的主函数会被调 ......
Calendar 类是一个抽象类,它为特定瞬间与一组诸如 YEAR、MONTH、DAY_OF_MONTH、HOUR 等 日历字段之间的转换提供了一些方法,并为操作日历字段(例如获得下星期的日期)提供了一些方法。瞬间可用毫秒值来表示,它是距历元(即格林威治标准时间 1970 年 1 月 1 日的 00:00:00.000,格里高利历)的偏移量。
例:
Calenda ......
/*从服务器中下载文件到本地*/
/*url:文件存放在服务器的地址;target:要保存的路径*/
public String DownloadFile(String url,String target){
URLConnection con=null;
URL theUrl=null;
try {
theUrl=new URL(url);//建立地址
......
一. 什么是Native Method
简单地讲,一个Native Method就是一个java调用非java代码的接口。一个Native Method是这样一个java的方法:该方法的实现由非java语言实现,比如C。这个特征并非java所特有,很多其它的编程语言都有这一机制,比如在C++中,你可以用extern "C"告知C++编译器去调用一个C的函 ......