package ldaptive;
import java.util.Collection;
import org.ldaptive.AddOperation;
import org.ldaptive.AddRequest;
import org.ldaptive.BindOperation;
import org.ldaptive.BindRequest;
import org.ldaptive.Connection;
import org.ldaptive.Credential;
import org.ldaptive.DefaultConnectionFactory;
import org.ldaptive.LdapAttribute;
import org.ldaptive.LdapEntry;
import org.ldaptive.LdapException;
import org.ldaptive.SearchFilter;
import org.ldaptive.SearchOperation;
import org.ldaptive.SearchRequest;
import org.ldaptive.SearchResult;
public class LdapTiveTest {
public static void main(String[] args) throws LdapException {
Connection conn = DefaultConnectionFactory.getConnection("ldap://192.168.1.152");
try {
conn.open();
BindOperation bind = new BindOperation(conn);
bind.execute(new BindRequest("cn=Manager,dc=srv,dc=world", new Credential("c2VjcmV0")));
SearchOperation search = new SearchOperation(conn);
SearchFilter filter = new SearchFilter("(|(mail={mail}))");
filter.setParameter("mail", "baxu...@163.com");
SearchResult result = search.execute(
new SearchRequest(
"ou=People,dc=srv,dc=world",filter, "mail", "displayName", "userPassword")).getResult();
//result.getEntry(); // if you're expecting a single entry
for (LdapEntry entry : result.getEntries()) { // if you're expecting multiple entries
System.out.println(entry.getAttribute("displayName").getStringValue());
System.out.println(entry.getAttribute("userPassword").getStringValue());
}
LdapEntry addentry = new LdapEntry(
"dc=srv,dc=world",
new LdapAttribute("gidNumber", "0"),
new LdapAttribute("uid", "hehe"),
new LdapAttribute("cn", "hehe"),
new LdapAttribute("sn", "he"));
AddOperation add = new AddOperation(conn);
String adn = addentry.getDn();
Collection<LdapAttribute> aco = addentry.getAttributes();
add.execute(new AddRequest(adn,aco));
} finally {
conn.close();
}
}
}
SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
baxuelong
MTIzNDU2
Exception in thread "main" [org.ldaptive.LdapException@204349222::resultCode=OBJECT_CLASS_VIOLATION, matchedDn=null, responseControls=null, referralURLs=null, messageId=-1, message=javax.naming.directory.SchemaViolationException: [LDAP: error code 65 - no objectClass attribute]; remaining name 'dc=srv,dc=world', providerException=javax.naming.directory.SchemaViolationException: [LDAP: error code 65 - no objectClass attribute]; remaining name 'dc=srv,dc=world']
at org.ldaptive.provider.ProviderUtils.throwOperationException(ProviderUtils.java:55)
at org.ldaptive.provider.jndi.JndiConnection.processNamingException(JndiConnection.java:619)
at org.ldaptive.provider.jndi.JndiConnection.add(JndiConnection.java:326)
at org.ldaptive.AddOperation.invoke(AddOperation.java:28)
at org.ldaptive.AddOperation.invoke(AddOperation.java:9)
at org.ldaptive.AbstractOperation.execute(AbstractOperation.java:126)
at ldaptive.LdapTiveTest.main(LdapTiveTest.java:57)
Caused by: javax.naming.directory.SchemaViolationException: [LDAP: error code 65 - no objectClass attribute]; remaining name 'dc=srv,dc=world'
at com.sun.jndi.ldap.LdapCtx.mapErrorCode(LdapCtx.java:3166)
at com.sun.jndi.ldap.LdapCtx.processReturnCode(LdapCtx.java:3081)
at com.sun.jndi.ldap.LdapCtx.processReturnCode(LdapCtx.java:2888)
at com.sun.jndi.ldap.LdapCtx.c_createSubcontext(LdapCtx.java:812)
at com.sun.jndi.toolkit.ctx.ComponentDirContext.p_createSubcontext(ComponentDirContext.java:341)
at com.sun.jndi.toolkit.ctx.PartialCompositeDirContext.createSubcontext(PartialCompositeDirContext.java:268)
at org.ldaptive.provider.jndi.JndiConnection.add(JndiConnection.java:315)
... 4 more
The below picture is ldap admin
Caused by: javax.naming.directory.SchemaViolationException: [LDAP: error code 65 - no objectClass attribute]; remaining name 'dc=srv,dc=world'
LdapEntry addentry = new LdapEntry(
"dc=srv,dc=world",
--
You received this message because you are subscribed to the Google Groups "ldaptive" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ldaptive+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.