Class LdapConnection
java.lang.Object
com.codename1.backend.security.ldap.LdapConnection
- All Implemented Interfaces:
AutoCloseable
One LDAPv3 session (RFC 4511) on one socket: simple bind, search, StartTLS
and unbind -- what signing users in against a directory needs, and no more.
Not shared between threads; open one per sign-in, as LdapContextSource
does, and close it.
Only simple binds are made, so the password travels as the server reads
it: over plain ldap:// without StartTLS, anyone on the network path reads
every password. Use ldaps://, or StartTLS.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intThe scope of a search: the base entry alone.static final intThe scope of a search: the base entry's children.static final intThe scope of a search: the base entry and everything under it. -
Method Summary
Modifier and TypeMethodDescriptionvoidA simple bind asdn.voidclose()Says goodbye and closes the socket.booleanisSecure()Whether the session is encrypted.static LdapConnectionsearch(String base, int scope, String filter, int sizeLimit, int timeLimitSeconds, String... attributes) Searchesbaseforfilterand answers the entries found, with theattributesasked for (none: all user attributes).
-
Field Details
-
SCOPE_BASE
public static final int SCOPE_BASEThe scope of a search: the base entry alone.- See Also:
-
SCOPE_ONE_LEVEL
public static final int SCOPE_ONE_LEVELThe scope of a search: the base entry's children.- See Also:
-
SCOPE_SUBTREE
public static final int SCOPE_SUBTREEThe scope of a search: the base entry and everything under it.- See Also:
-
-
Method Details
-
open
public static LdapConnection open(String url, boolean startTls, String caFile, int connectTimeoutMillis, int readTimeoutMillis) throws IOException - Parameters:
readTimeoutMillis- how long an answer may take; zero waits forever- Throws:
IOException
-
isSecure
public boolean isSecure()Whether the session is encrypted. -
bind
A simple bind as
dn.An empty password is refused here rather than sent: RFC 4513 section 5.1.2 makes a name with no password an unauthenticated bind, which many directories answer with success -- and a sign-in that checked only that would let anyone in as anyone.
- Throws:
LdapException- withLdapException.INVALID_CREDENTIALSwhen the directory refuses the passwordIOException
-
search
public List<LdapEntry> search(String base, int scope, String filter, int sizeLimit, int timeLimitSeconds, String... attributes) throws IOException Searchesbaseforfilterand answers the entries found, with theattributesasked for (none: all user attributes).- Parameters:
filter- an RFC 4515 filter; escape what a user typed withLdapEncoder.filterEncode(String)sizeLimit- the most entries wanted; zero for the server's limit. More than that isLdapException.SIZE_LIMIT_EXCEEDED.- Throws:
IOException
-
close
public void close()Says goodbye and closes the socket. Never throws.- Specified by:
closein interfaceAutoCloseable
-