Active Directory/Search for a user: Difference between revisions
Content added Content deleted
(Scala contribution added.) |
|||
Line 629: | Line 629: | ||
7 Dir(s) 952,183,820,288 bytes free</pre> |
7 Dir(s) 952,183,820,288 bytes free</pre> |
||
=={{header|Scala}}== |
|||
<lang Scala>import org.apache.directory.api.ldap.model.message.SearchScope |
|||
import org.apache.directory.ldap.client.api.{LdapConnection, LdapNetworkConnection} |
|||
object LdapSearchDemo extends App { |
|||
class LdapSearch { |
|||
def demonstrateSearch(): Unit = { |
|||
val conn = new LdapNetworkConnection("localhost", 11389) |
|||
try { |
|||
conn.bind("uid=admin,ou=system", "********") |
|||
search(conn, "*mil*") |
|||
conn.unBind() |
|||
} finally if (conn != null) conn.close() |
|||
} |
|||
private def search(connection: LdapConnection, uid: String): Unit = { |
|||
val baseDn = "ou=users,o=mojo" |
|||
val filter = "(&(objectClass=person)(&(uid=" + uid + ")))" |
|||
val scope = SearchScope.SUBTREE |
|||
val attributes = List("dn", "cn", "sn", "uid") |
|||
var ksearch = 0 |
|||
val cursor = connection.search(baseDn, filter, scope, attributes: _*) |
|||
while (cursor.next) { |
|||
ksearch += 1 |
|||
val entry = cursor.get |
|||
printf("Search entry %d = %s%n", ksearch, entry) |
|||
} |
|||
} |
|||
} |
|||
new LdapSearch().demonstrateSearch() |
|||
}</lang> |
|||
=={{header|Tcl}}== |
=={{header|Tcl}}== |
||
One can do it with the low level [[Connect to Active Directory]] based handle with this code: |
One can do it with the low level [[Connect to Active Directory]] based handle with this code: |