-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathmain.dart
65 lines (50 loc) · 1.57 KB
/
main.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
import 'dart:async';
import 'package:dartdap/dartdap.dart';
import 'package:logging/logging.dart';
Future<void> main() async {
Logger.root.onRecord.listen((LogRecord r) {
print('${r.time}: ${r.loggerName}: ${r.level.name}: ${r.message}');
});
Logger.root.level = Level.FINE;
await example();
}
var base = 'dc=example,dc=com';
var filter = Filter.present('objectClass');
var attrs = ['dn', 'objectclass'];
Future example() async {
var host = 'localhost';
var bindDN = 'uid=admin';
var password = 'password';
var connection = LdapConnection(
host: host, ssl: false, port: 1389, bindDN: bindDN, password: password);
try {
await connection.open();
// Perform search operation
await connection.bind();
print('Bind OK');
print('******* before search');
await _doSearch(connection);
print('******* after search');
} catch (e, stacktrace) {
print('********* Exception: $e $stacktrace');
} finally {
// Close the connection when finished with it
print('Closing');
await connection.close();
}
}
Future<void> _doSearch(LdapConnection connection) async {
var searchResult = await connection.search(base, filter, attrs, sizeLimit: 5);
print('Search returned ${searchResult.stream}');
await for (var entry in searchResult.stream) {
// Processing stream of SearchEntry
print('dn: ${entry.dn}');
// Getting all attributes returned
for (var attr in entry.attributes.values) {
for (var value in attr.values) {
// attr.values is a Set
print(' ${attr.name}: $value');
}
}
}
}