title: How to Map AD Groups to User Role Spring Security LDAP
body: <p>I have a web application built using Java Spring MVC.</p>
  
  <p>I'm just setting up spring security connecting to an LDAP server for authentication.</p>
  
  <p>I've successfully set it up so that I am able to login to my application but I can't find anything to help me in mapping an AD group to a user role within Java as I can only get a 403 forbidden page i.e. I've been authenticated but don't have permissions yet.</p>
  
  <p>I currently have:</p>
  
  <pre><code>&lt;http auto-config="true"&gt;
      &lt;intercept-url pattern="/**" access="ROLE_USER" /&gt;      
  &lt;/http&gt;
  
  &lt;ldap-server id="ldapServer" url="LDAPURL" manager-dn="USER" manager-password="PASSWORD"  /&gt;
  
  &lt;authentication-manager &gt; 
      &lt;ldap-authentication-provider           
          group-search-base="OU=GROUPS"
          group-search-filter="sAMAccountName={0}"
  
          user-search-base="OU=USERS"
          user-search-filter="sAMAccountName={0}" 
  
          /&gt;
  &lt;/authentication-manager&gt;
  </code></pre>
  
  <p>Say that user was a part of the AD group g-group-UK-user I then want to be able to map that AD group to ROLE_USER so that user can then see the whole web app.</p>
  
  <p>I can only seem to find very simple examples where the groups are either ADMIN or USER in which case the prefix ROLE is just added to the group or the other method seems to be using UserDetailContextMapper but I can't find a clear use of this.</p>