Configuring SQL-based security

We configured our wiki application with startup security by using InMemoryUserDetailsService. It's easy to upgrade to database-managed security by simply swapping that component out with DatabaseUserDetailsService.

In the SpringWikiAppContext, we just need to change user_details_service to:

@Object
def user_details_service(self):
service = DatabaseUserDetailsService()
service.dataSource = self.factory()
return service

In this example, we have left out the coding of factory(). This is simply a connection factory used to create a DatabaseTemplate to talk to the database, as covered in the earlier SQL chapter.

DatabaseUserDetailsService defines the following queries to look up user data and granted authorities:

  • To lookup users: SELECT username,password,enabled FROM users WHERE username = ?
  • To lookup authorities: SELECT username,authority FROM authorities WHERE username = ?

Even though these are the default settings, it is easy to support another schema. Just override the variables as shown below.

@Object
def user_details_service(self):
service = DatabaseUserDetailsService()
service.dataSource = self.factory()
service.DEF_USERS_BY_USERNAME_QUERY = "<alt user qry>"
service.DEF_AUTHORITIES_BY_USERNAME_QUERY = "<alt auth qry>"
return service
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.22.66.132