Verified Commit e5bb46e0 authored by Jakob Moser's avatar Jakob Moser
Browse files

Add info on which information you can get out of LDAP

parent 83f4ab4d
Loading
Loading
Loading
Loading
+27 −1
Original line number Diff line number Diff line
@@ -160,13 +160,39 @@ If you are okay with manually determining a users distinguished name, you can co
```python
from ldap3 import Connection

Connection(server, user=dn, password=password).bind()
conn = Connection(server, user=dn, password=password)
conn.bind()
```

The return value will be `True` if and only if the user provided the correct username and password.

The Portal implementation [provides an alternative way](https://gitlab.cl.uni-heidelberg.de/fachschaft/portal/-/blob/7018a073252860493fa2b2a0c62743e4bcb12ee8/ldap/Directory.py#L62) using context managers.

## Accessing account data

### Uni ID

To just search for everything you can get, try:

```python
conn.search("dc=ad,dc=uni-heidelberg,dc=de", "(objectclass=person)");
conn.entries
```

Search for a particular user (e.g. yourself):

```python
conn.search("dc=ad,dc=uni-heidelberg,dc=de", f"(cn={escape_rdn(user)})")
conn.entries
```

And to get all the attributes you can access:

```python
conn.search("dc=ad,dc=uni-heidelberg,dc=de", f"(cn={escape_rdn(user)})", attributes=["*"])
conn.entries
```

## Further reading

* [`portal/ldap/Directory.py`](https://gitlab.cl.uni-heidelberg.de/fachschaft/portal/-/blob/master/ldap/Directory.py?ref_type=heads): LDAP implementation for another project from which I self-plagiarized many of the instructions here