作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
这里出了什么问题?我不明白?
/**
* @param args the command line arguments
*/
public class HsAppLDAP {
@SuppressWarnings("rawtypes")
public static void main(String[] args) {
// Déclaration des variables
ArrayList<String> values = new ArrayList<String>();
Connection connection;
Statement statement;
// Récupération des données depuis le fichier excel
try {
InputStream input = new FileInputStream("student.xls");
POIFSFileSystem fs = new POIFSFileSystem(input);
HSSFWorkbook wb = new HSSFWorkbook(fs);
HSSFSheet sheet = wb.getSheetAt(0);
Iterator rows = sheet.rowIterator();
while (rows.hasNext()) {
values.clear();
HSSFRow row = (HSSFRow) rows.next();
Iterator cells = row.cellIterator();
while (cells.hasNext()) {
HSSFCell cell = (HSSFCell) cells.next();
if (HSSFCell.CELL_TYPE_NUMERIC == cell.getCellType())
values.add(Integer.toString((int) cell.getNumericCellValue()));
else if (HSSFCell.CELL_TYPE_STRING == cell.getCellType())
values.add(cell.getStringCellValue());
}
// Insertion en BDD
String url = "ldap://192.168.0.244:389";
Hashtable env = new Hashtable();
env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory");
env.put(Context.PROVIDER_URL, url);
env.put(Context.SECURITY_AUTHENTICATION, "none");
env.put(Context.SECURITY_PRINCIPAL, "uid=admin, o=hs-fulda");
env.put(Context.SECURITY_CREDENTIALS, "ToCHange!");
try {
DirContext ctx = new InitialDirContext(env);
System.out.println("connected");
System.out.println(ctx.getEnvironment());
try {
Attribute cn = new BasicAttribute("cn", values.get(0));
System.out.println(cn);
Attribute sn = new BasicAttribute("sn", values.get(1));
System.out.println(sn);
Attribute fullName = new BasicAttribute("fullName", values.get(2) +" "+ values.get(1));
System.out.println(fullName);
Attribute givenName = new BasicAttribute("givenName", values.get(2));
System.out.println(givenName);
Attribute uid = new BasicAttribute("uid", values.get(0));
System.out.println(uid);
Attribute ou = new BasicAttribute("ou", values.get(3));
System.out.println(ou);
Attribute oc = new BasicAttribute("objectClass");
System.out.println(oc);
oc.add("Top");
oc.add("Person");
oc.add("organizationalPerson");
oc.add("inetOrgPerson");
BasicAttributes entry = new BasicAttributes();
entry.put(cn);
entry.put(sn);
entry.put(fullName);
entry.put(givenName);
entry.put(uid);
entry.put(ou);
entry.put(oc);
String entryDN = values.get(0);
ctx.createSubcontext(entryDN, entry);
} catch (Exception e) {
e.printStackTrace();
System.out.println("Insertion nicht möglich: ECHEC");
}
/**String sql = String
.format("INSERT INTO users(first_name, last_name, username, password, age) VALUES ('%s', '%s', '%s', '%s', %s)",
values.get(0), values.get(1),
values.get(2), values.get(3), values.get(4));**/
} catch (Exception e) {
e.printStackTrace();
}
}
} catch (IOException e) {
e.printStackTrace();
}
}
}
我有这个输出:
connected
{java.naming.provider.url=ldap://192.168.0.244:389, java.naming.factory.initial=com.sun.jndi.ldap.LdapCtxFactory, java.naming.security.principal=uid=admin, o=hs-fulda, java.naming.security.authentication=none, java.naming.security.credentials=ToCHange!}
cn: fdai0000
sn: Buehler
fullName: Mark Buehler
givenName: Mark
uid: fdai0000
ou: AI
objectClass: No values
javax.naming.InvalidNameException: Invalid name: fdai0000; remaining name 'fdai0000'
Insertion nicht möglich: ECHEC
connected
at javax.naming.ldap.Rfc2253Parser.doParse(Rfc2253Parser.java:111)
at javax.naming.ldap.Rfc2253Parser.parseDn(Rfc2253Parser.java:70)
at javax.naming.ldap.LdapName.parse(LdapName.java:785)
at javax.naming.ldap.LdapName.<init>(LdapName.java:123)
{java.naming.provider.url=ldap://192.168.0.244:389, java.naming.factory.initial=com.sun.jndi.ldap.LdapCtxFactory, java.naming.security.principal=uid=admin, o=hs-fulda, java.naming.security.authentication=none, java.naming.security.credentials=ToCHange!}
cn: fdai0001
at com.sun.jndi.ldap.LdapCtx.addRdnAttributes(LdapCtx.java:922)
sn: Wagner
at com.sun.jndi.ldap.LdapCtx.c_createSubcontext(LdapCtx.java:804)
fullName: Toma Wagner
givenName: Toma
at com.sun.jndi.toolkit.ctx.ComponentDirContext.p_createSubcontext(ComponentDirContext.java:341)
uid: fdai0001
ou: AI
at com.sun.jndi.toolkit.ctx.PartialCompositeDirContext.createSubcontext(PartialCompositeDirContext.java:268)
at com.sun.jndi.toolkit.ctx.PartialCompositeDirContext.createSubcontext(PartialCompositeDirContext.java:256)
objectClass: No values
at javax.naming.directory.InitialDirContext.createSubcontext(InitialDirContext.java:197)
at hsappldap.HsAppLDAP.main(HsAppLDAP.java:122)
javax.naming.InvalidNameException: Invalid name: fdai0001; remaining name 'fdai0001'
Insertion nicht möglich: ECHEC
at javax.naming.ldap.Rfc2253Parser.doParse(Rfc2253Parser.java:111)
at javax.naming.ldap.Rfc2253Parser.parseDn(Rfc2253Parser.java:70)
at javax.naming.ldap.LdapName.parse(LdapName.java:785)
at javax.naming.ldap.LdapName.<init>(LdapName.java:123)
at com.sun.jndi.ldap.LdapCtx.addRdnAttributes(LdapCtx.java:922)
at com.sun.jndi.ldap.LdapCtx.c_createSubcontext(LdapCtx.java:804)
at com.sun.jndi.toolkit.ctx.ComponentDirContext.p_createSubcontext(ComponentDirContext.java:341)
at com.sun.jndi.toolkit.ctx.PartialCompositeDirContext.createSubcontext(PartialCompositeDirContext.java:268)
at com.sun.jndi.toolkit.ctx.PartialCompositeDirContext.createSubcontext(PartialCompositeDirContext.java:256)
at javax.naming.directory.InitialDirContext.createSubcontext(InitialDirContext.java:197)
at hsappldap.HsAppLDAP.main(HsAppLDAP.java:122)
最佳答案
就像异常消息所说:
javax.naming.InvalidNameException: Invalid name: fdai0000; remaining name 'fdai0000'
您正在尝试在 ldap 中创建一个条目,使用 fdai0000
作为专有名称 - 但这不是有效的专有名称。
关于java - 不明白这个 Java LDAP 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35706154/
我是一名优秀的程序员,十分优秀!