导航:首页 > 编程语言 > javaldap连接

javaldap连接

发布时间:2024-11-02 03:27:21

A. 用java操作ldap是报错,求大神解救

出自 http://blog.csdn.net/techchan/article/details/5440775

1. error code 53
===========================================================================
问题:创建新用户时出现数据后端异常
在 WebSphere Portal Express 中,您可以设置密码的最短和最长长度。如果设置的密码长度与 LDAP 服务器的策略不相同,则在创建用户时您可能会看到以下异常:
EJPSG0015E: Data Backend Problem com.ibm.websphere.wmm.exception.WMMSystemException:
The following Naming Exception occurred ring processing:
"javax.naming.: [LDAP: error code 53 - 0000052D:
SvcErr: DSID-031A0FBC, problem 5003 (WILL_NOT_PERFORM), data 0
]; remaining name 'cn=see1anna,cn=users,dc=wps510,dc=rtp,dc=raleigh,dc=ibm,dc=com';
resolved object com.sun.jndi.ldap.LdapCtx@7075b1b4".

原因:这是由于“密码不能满足密码策略的要求”导致

解决方案:
1. 打开域安全策略-安全设置-账户策略-密码策略-密码必须符合复杂性要求。定义这个策略设置为:已禁用。/ 密码长度最小值:定义这个策略设置为0。

2. 打开域控制器安全策略-安全设置-账户策略-密码策略-密码必须符合复杂性要求。定义这个策略设置为:已禁用。/ 密码长度最小值:定义这个策略设置为0。

3. 最后运行刷新组策略命令为:gpupdate /force

===========================================================================

2. Need to specify class name
===========================================================================
javax.naming.NoInitialContextException: Need to specify class name in environment or system property, or as an applet parameter, or in an application resource file: java.naming.factory.initial

原因:LdapContext在处理完上个环节被close(),LdapContext=null;
解决方案:不close;

3. error code 50
===========================================================================
javax.naming.NoPermissionException: [LDAP: error code 50 - 00002098: SecErr: DSID-03150A45, problem 4003 (INSUFF_ACCESS_RIGHTS), data 0

4. error code 68
===========================================================================
javax.naming.NameAlreadyBoundException: [LDAP: error code 68 - 00000524: UpdErr: DSID-031A0F4F, problem 6005 (ENTRY_EXISTS), data 0

原因:创建的用户已经存在了

7. No trusted certificate
===========================================================================
javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorException: No trusted certificate found
1.cas机器A,A上a,b,c服务运行良好
2.website 位于B机器,cas可以截获请求,跳转javax.net.ssl.SSLHandshakeException

将A上生生成的客户端密钥,导入B
A运行
sudo keytool -genkey -alias tomcat -keyalg RSA -keypass changeit -storepass changeit -keystore server.keystore -validity 3600

$ keytool -export -trustcacerts -alias tomcat -file server.cer -keystore server.keystore -storepass changeit

$ sudo keytool -import -trustcacerts -alias tomcat -file server.cer -keystore $JAVA_HOME/jre/lib/security/cacerts -storepass changeit
B运行最后一句即可

建立信任关系,客户,服务密钥,客户多处

8. error code 1
===========================================================================
javax.naming.NamingException: [LDAP: error code 1 - 00000000: LdapErr: DSID-0C090AE2, comment: In order to perform this operation a successful bind must be completed on the connection., data 0, vece

原因:新增域用户的时候,ctx没有绑定管理员用户
解决方法:ctx.addToEnvironment(Context.SECURITY_PRINCIPAL, adminUser + "@" + ldapProperty.getDomain());
ctx.addToEnvironment(Context.SECURITY_CREDENTIALS, adminPwd);

9. error code 50
==========================================================================
javax.naming.NoPermissionException: [LDAP: error code 50 - 00000005: SecErr: DSID-03151E04, problem 4003 (INSUFF_ACCESS_RIGHTS)

原因:新建域用户时候,ctx绑定到一个普通用户(该用户没有新建用户的权限)
解决方法:使用管理员用户进行绑定:
ctx.addToEnvironment(Context.SECURITY_PRINCIPAL, adminUser + "@" + ldapProperty.getDomain());
ctx.addToEnvironment(Context.SECURITY_CREDENTIALS, adminPwd);

10. error code 19
==========================================================================
javax.naming.directory.: [LDAP: error code 19 - 0000052D: AtrErr: DSID-03190F00, #1:
0: 0000052D: DSID-03190F00, problem 1005 (CONSTRAINT_ATT_TYPE)

原因:这个最大的可能是不满足域安全策略:如密码复杂性、密码最短使用期限、强制密码历史。即长度、包含的字符、多久可以修改密码、是否可以使用历史密码等。

11. LDAP: error code 50
==========================================================================
javax.naming.NoPermissionException: [LDAP: error code 50 - 00000005: SecErr: DSID-031A0F44, problem 4003 (INSUFF_ACCESS_RIGHTS)

原因:这个是最初代码使用的replace操作,这个在AD里对应的是密码重设(普通用户默认没有这个权限,管理员可以操作),另外remove操作时提供的旧密码错误也可能报这个异常

12. RSA premaster secret error
==========================================================================
javax.naming.CommunicationException: simple bind failed: 172.18.20.4:636 [Root exception is javax.net.ssl.SSLKeyException: RSA premaster secret error]

原因:Tomcat 配置的JDK与添加证书的的JDK不一致。如:证书存放路径为C:/Java/jdk1.6.0_10/jre/lib/cacerts 而Tomcat 配置的JDK为C:/Java/jre6 ,使得两者路径不一致,SSL验证的时候,找不到证书

13.No trusted certificate found
==========================================================================

javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorException: No trusted certificate found

原因:信任证书库文件路径不正确
解决方法:将正确工程中 /WEB-INF/classes目录下

14. error code 49
==========================================================================
javax.naming.AuthenticationException: [LDAP: error code 49 - 80090308: LdapErr: DSID-0C090334, comment: AcceptSecurityContext error, data 52e, vece
希望可以帮到你

B. JAVA连接LDAP(Windows AD)验证时,密码为空验证通过的问题

密码为空 ,实际值是null

任何值与null比较时,记得返回值都是true,

故在程序里需要预先把空值过滤掉

if(pwd==null)
System.out.println("输入密码为空,验证不通过!");

C. 如何使用Java操作LDAP之LDAP连接

public static void main(String[] args) {
String url = "ldap://10.0.0.10:389/";
String domain = "dc=dtas,dc=com";
String user = "cn=administrator,cn=users";
String password = "111111";
Hashtable<String, String> env = new Hashtable<String, String>();
env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory"); // LDAP 工厂
env.put(Context.SECURITY_AUTHENTICATION, "simple"); // LDAP访问安全级别
env.put(Context.PROVIDER_URL, url);
env.put(Context.SECURITY_PRINCIPAL, user+","+domain); // 填DN
env.put(Context.SECURITY_CREDENTIALS, password); // AD Password
env.put("java.naming.ldap.attributes.binary", "objectSid objectGUID");
LdapContext ldapCtx = null;
try {
ldapCtx = new InitialLdapContext(env , null);
queryGroup(ldapCtx);
//queryUser(ldapCtx);

} catch (NamingException e) {
e.printStackTrace();
} finally {
if(ldapCtx != null) {
try {
ldapCtx.close();
} catch (NamingException e) {
}
}
}
}

private static void queryGroup(LdapContext ldapCtx) throws NamingException {
SearchControls searchCtls = new SearchControls();
searchCtls.setSearchScope(SearchControls.SUBTREE_SCOPE);
String searchFilter = "objectClass=organizationalUnit";
String searchBase = "ou=myDeptSubDept,ou=myDept,dc=DS-66,dc=com";
String returnedAtts[] = {"distinguishedName", "objectGUID", "name"};
searchCtls.setReturningAttributes(returnedAtts);
NamingEnumeration<SearchResult> answer = ldapCtx.search(searchBase, searchFilter, searchCtls);
while (answer.hasMoreElements()) {
SearchResult sr = answer.next();
Attributes Attrs = sr.getAttributes();
if (Attrs != null) {
NamingEnumeration<?> ne = Attrs.getAll();
while(ne.hasMore()) {
Attribute Attr = (Attribute)ne.next();
String name = Attr.getID();
Enumeration<?> values = Attr.getAll();
if (values != null) { // 迭代
while (values.hasMoreElements()) {
String value = "";
if("objectGUID".equals(name)) {
value = UUID.nameUUIDFromBytes((byte[]) values.nextElement()).toString();
} else {
value = (String)values.nextElement();
}
System.out.println(name + " " + value);
}
}
}
System.out.println("=====================");
}
}

}

阅读全文

与javaldap连接相关的资料

热点内容
联想服务器休眠后如何唤醒 浏览:111
四川话女孩学习编程 浏览:322
编译原理文法区分 浏览:1001
教师可以做程序员嘛 浏览:637
终结战场安卓国际服怎么下载 浏览:155
现在的高端服务器属于什么 浏览:810
企业银行解压流程 浏览:447
用app压缩文件 浏览:227
柱子正负零加密区 浏览:322
车辆贷款交完要去4s店解压 浏览:65
电脑可以运行plc编程吗 浏览:594
下载app的怎么连不上 浏览:765
程序员做量化交易有前途么 浏览:233
java程序编译成本地exe 浏览:525
安卓手机有噪音怎么回事 浏览:981
ios程序员饱和 浏览:7
51单片机控制pwm程序 浏览:299
汽车压缩机串气可以修么 浏览:633
30天学会全部语法pdf 浏览:52
java反编译修补bug 浏览:614