title: How to list *all* users and *all* authorities in a Spring Security application
body: <p>Q1) Is there a way (ie a class method) in Spring Security that allows you to list <em>all</em> the users and roles that is in the Sprint Security user &amp; roles tables? (I'm not looking for only logged in users; and I'm not looking for only the authorities for a given user. I'm looking for all users and all authorities.)</p>
  
  <p>Q1b) If there is a way, does the user running this query need special permissions?</p>
  
  <p>(I can hack this by writing my own SQL statement that queries the users and authorities table, but that seems like unecessary work, prone to mistakes, and breaks the Spring Security API.)</p>
  
  <p>In case it helps, my application context setup is fairly standard:</p>
  
  <pre><code>&lt;authentication-manager alias="myAuthenticationManager"&gt;
      &lt;authentication-provider&gt;
          &lt;jdbc-user-service data-source-ref="dataSource"
              users-by-username-query="select username, password, enabled from users where users.username=?"
              authorities-by-username-query="select users.username,authority from users,authorities where users.username=authorities.username and users.username=?" /&gt;
      &lt;/authentication-provider&gt;
  &lt;/authentication-manager&gt;
  </code></pre>
  
  <p>and</p>
  
  <pre><code>&lt;beans:bean id="dataSource"
      class="org.springframework.jdbc.datasource.DriverManagerDataSource"&gt;
      &lt;beans:property name="driverClassName"&gt;
          &lt;beans:value&gt;com.mysql.jdbc.Driver&lt;/beans:value&gt;
      &lt;/beans:property&gt;
      &lt;beans:property name="url"&gt;
          &lt;beans:value&gt;jdbc:mysql://XXXXX:XXXX/XXXXX&lt;/beans:value&gt;
      &lt;/beans:property&gt;
      &lt;beans:property name="username"&gt;
          &lt;beans:value&gt;XXXXX&lt;/beans:value&gt;
      &lt;/beans:property&gt;
      &lt;beans:property name="password"&gt;
          &lt;beans:value&gt;XXXXXX&lt;/beans:value&gt;
      &lt;/beans:property&gt;
  &lt;/beans:bean&gt;
  </code></pre>