title: spring security authorization only
body: <p>I am trying to develop a User management tool using Waffle to perform windows authentication with Spring Security. Unfortunately, The only thing that provides me is the authentication part. </p>
  
  <p>I would like to assign a Role to a particular user session in order to limit a users privileges. Each username is stored in a database along with their associated role. How can I get Spring Security to query my database and load the associated role to the session, so that I can use the @PreAuthorize(hasRole(role)) annotation in my controller to restrict access to certain actions?</p>
  
  <p>Edit:
  Thanks for your answer but I don't think thats quite what I am looking for.
  So I have made some progress(I think). For my Authentication provider I have created my own  custom GrantedAuthorityFactory as a property of my waffleSpringAuthenticationProvider as follows:</p>
  
  <pre><code>&lt;bean id="waffleSpringAuthenticationProvider" class="waffle.spring.WindowsAuthenticationProvider"&gt;
      &lt;property name="AllowGuestLogin" value="false" /&gt;
      &lt;property name="PrincipalFormat" value="fqn" /&gt;
      &lt;property name="RoleFormat" value="both" /&gt;
      &lt;property name="AuthProvider" ref="waffleWindowsAuthProvider" /&gt;
      &lt;property name="grantedAuthorityFactory" ref ="simpleGrantedAuthorityFactory"/&gt;
      &lt;!--  --&gt;
  
  &lt;/bean&gt;
  </code></pre>
  
  <p>The grantedAuthorityFactory code is as follows:</p>
  
  <pre><code>import org.springframework.beans.factory.annotation.Autowired;
  import org.springframework.beans.factory.annotation.Qualifier;
  import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate;
  import org.springframework.security.core.GrantedAuthority;
  
  import waffle.spring.GrantedAuthorityFactory;
  import waffle.windows.auth.WindowsAccount;
  
  public class SimpleGrantedAuthorityFactory implements GrantedAuthorityFactory{
  
      private final String PREFIX;
      private final boolean CONVERT_TO_UPPER_CASE;
  
      @Autowired
      @Qualifier(value = "jdbcRoleDao")
      private JdbcRoleDao jdbcRoleDao;
  
  
      public SimpleGrantedAuthorityFactory(String prefix, boolean convertToUpperCase)
      {
          PREFIX = prefix;
          CONVERT_TO_UPPER_CASE = convertToUpperCase;
      }
  
      @Override
      public GrantedAuthority createGrantedAuthority(WindowsAccount windowsAccount) {
  
          System.out.println("Username: "+windowsAccount.getFqn());
          String grantedAuthorityString = windowsAccount.getFqn();
  
          String grantedAuthority = jdbcRoleDao.getRole(grantedAuthorityString);
          return new SimpleGrantedAuthority(PREFIX+grantedAuthority);
      }
  
  }
  </code></pre>
  
  <p>Now when I run the program and try to log in, the login fails. When I remove my custom factory property from the config file, the login is completed successfully with no assigned roles. I'm not sure if this is important, but windowsAccount.getFqn() is not returning the correct username that I enter on my login form.
  Is there something I'm missing from my factory class?</p>