django with apache ldap backend auth, get logged in username and ldap group & hide detail based on group (mod_ldap)
<p>im using Django with Apache and LDAP backend auth, my http conf is as below:</p>

<pre><code>LoadModule ldap_module modules/mod_ldap.so
LoadModule authnz_ldap_module modules/mod_authnz_ldap.so
#
&lt;Location /&gt;
  AuthName "Please enter your domain credentials."
  AuthBasicProvider ldap
  AuthType basic
  AuthLDAPUrl "ldap://example.com:389/DC=example,DC=com?sAMAccountName"
  AuthLDAPBindDN "CN=serv,OU=Service Accounts,DC=example,DC=com"
  AuthLDAPBindPassword XXXX
  AuthLDAPBindAuthoritative off
  LDAPReferrals off
  Require valid-user
&lt;/Location&gt;
</code></pre>

<p>Which when i now load my site i get a basic auth prompt which is great, what id like to be able to do now is to receive the logged in username, ive searched and tried a few things such as:</p>

<pre><code>LoggedInUser = request.user.username
</code></pre>

<p>which gives me a request is not defined message (i have import requests at the top)</p>

<pre><code>LoggedInUser = os.getenv["REMOTE_USER"]
</code></pre>

<p>which gives me TypeError: 'function' object has no attribute '<strong>getitem</strong>'</p>

<p>does anyone know what i need to be using?</p>

<p>i also need to hide certain urls from users if they are not in the correct ldap group, so would need to get the users AD groups aswell from the session</p>

<p>Thanks</p>