Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>There are a couple of ways you could handle this:</p> <ul> <li>You could write your own AuthenticationProvider using Hibernate for DB access</li> <li>You could use the <code>&lt;jdbc-user-service&gt;</code> and overwrite the SQL queries as mentioned by @zagyi. (<a href="http://static.springsource.org/spring-security/site/docs/current/reference/appendix-namespace.html#nsa-jdbc-user-service" rel="nofollow">http://static.springsource.org/spring-security/site/docs/current/reference/appendix-namespace.html#nsa-jdbc-user-service</a>)</li> <li>Or you can create the your schema to fit the standard <code>&lt;jdbc-user-service&gt;</code></li> </ul> <p>To use the approach you are interested in you have to know that aside from having the fields username, password and enabled spring security expects the username to be a unique identifier. This means that you can use the username property of your entity as Id for your DB and Hibernate. If you don't want to do this a way of approaching this is to set a table wihch defines the authorites using an ID/Name and the authority. And then to set up the use a jointable to map them to the users. Some untested examplecode: <strong>Role:</strong></p> <pre><code>@Entity @DynamicUpdate @Table(name ="authorities") public class Authority{ private String authority; @Id @Column(name="authority") public String getAuthority() { return authority; } </code></pre> <p><strong>User:</strong></p> <pre><code>@Entity @DynamicUpdate @Table(name = "users", uniqueConstraints={ @UniqueConstraint(columnNames={"username"})}) public class User { private String username; private List&lt;Authority&gt; authorities; @Type(type = "numeric_boolean") private boolean enabled; @Id @Column(name="username") public String getUsername() { return username; } @ManyToMany(fetch = FetchType.EAGER) @JoinTable( name = "authorities", joinColumns = @JoinColumn(name = "username"), inverseJoinColumns = @JoinColumn(name = "rolename") ) public List&lt;Authority&gt; getauthorities() { return authorities; } @Column(name="ENABLED") public boolean isEnabled() { return enabled; } </code></pre> <p>When the base is running you can add properties for internal use as u like.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload