Class JdbcUserDetailsService

java.lang.Object
org.springframework.dao.support.DaoSupport
org.springframework.jdbc.core.support.JdbcDaoSupport
org.springframework.security.core.userdetails.jdbc.JdbcDaoImpl
net.solarnetwork.central.security.jdbc.JdbcUserDetailsService
All Implemented Interfaces:
org.springframework.beans.factory.Aware, org.springframework.beans.factory.InitializingBean, org.springframework.context.MessageSourceAware, org.springframework.security.core.userdetails.UserDetailsService

public class JdbcUserDetailsService extends org.springframework.security.core.userdetails.jdbc.JdbcDaoImpl implements org.springframework.security.core.userdetails.UserDetailsService
Extension of JdbcDaoImpl that returns AuthenticatedUser objects.

The SQL required by this implementation adds the following additional column requirements to the base JdbcDaoImpl requirements:

  1. User ID (Long) - the User primary key
  2. Display Name (String) - the User's display name
  3. Token (Boolean) - true if this represents a token
  4. Token type (String) - if Token is true, this should be the token type
  5. Token IDs (String) - if Token is true, this is an optional set of IDs
  • Field Summary

    Fields

    Fields inherited from class org.springframework.security.core.userdetails.jdbc.JdbcDaoImpl

    DEF_AUTHORITIES_BY_USERNAME_QUERY, DEF_GROUP_AUTHORITIES_BY_USERNAME_QUERY, DEF_USERS_BY_USERNAME_QUERY, DEFAULT_USER_SCHEMA_DDL_LOCATION, messages

    Fields inherited from class org.springframework.dao.support.DaoSupport

    logger
  • Constructor Summary

    Constructors
    Constructor
    Description
     
    JdbcUserDetailsService(com.fasterxml.jackson.databind.ObjectMapper objectMapper)
     
  • Method Summary

    Modifier and Type
    Method
    Description
    protected void
    addCustomAuthorities(String username, List<org.springframework.security.core.GrantedAuthority> authorities)
     
    protected org.springframework.security.core.userdetails.UserDetails
    createUserDetails(String username, org.springframework.security.core.userdetails.UserDetails userFromUserQuery, List<org.springframework.security.core.GrantedAuthority> combinedAuthorities)
     
    protected List<org.springframework.security.core.userdetails.UserDetails>
     
    void
    Set a list of statically assigned authorities based on a list of role names.

    Methods inherited from class org.springframework.security.core.userdetails.jdbc.JdbcDaoImpl

    getAuthoritiesByUsernameQuery, getEnableAuthorities, getEnableGroups, getMessages, getRolePrefix, getUsersByUsernameQuery, initDao, isUsernameBasedPrimaryKey, loadGroupAuthorities, loadUserAuthorities, loadUserByUsername, setAuthoritiesByUsernameQuery, setEnableAuthorities, setEnableGroups, setGroupAuthoritiesByUsernameQuery, setMessageSource, setRolePrefix, setUsernameBasedPrimaryKey, setUsersByUsernameQuery

    Methods inherited from class org.springframework.jdbc.core.support.JdbcDaoSupport

    checkDaoConfig, createJdbcTemplate, getConnection, getDataSource, getExceptionTranslator, getJdbcTemplate, initTemplateConfig, releaseConnection, setDataSource, setJdbcTemplate

    Methods inherited from class org.springframework.dao.support.DaoSupport

    afterPropertiesSet

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

    Methods inherited from interface org.springframework.security.core.userdetails.UserDetailsService

    loadUserByUsername
  • Field Details

  • Constructor Details

    • JdbcUserDetailsService

      public JdbcUserDetailsService()
    • JdbcUserDetailsService

      public JdbcUserDetailsService(com.fasterxml.jackson.databind.ObjectMapper objectMapper)
  • Method Details

    • createUserDetails

      protected org.springframework.security.core.userdetails.UserDetails createUserDetails(String username, org.springframework.security.core.userdetails.UserDetails userFromUserQuery, List<org.springframework.security.core.GrantedAuthority> combinedAuthorities)
      Overrides:
      createUserDetails in class org.springframework.security.core.userdetails.jdbc.JdbcDaoImpl
    • loadUsersByUsername

      @Transactional(readOnly=true, propagation=REQUIRED) protected List<org.springframework.security.core.userdetails.UserDetails> loadUsersByUsername(String username)
      Overrides:
      loadUsersByUsername in class org.springframework.security.core.userdetails.jdbc.JdbcDaoImpl
    • addCustomAuthorities

      protected void addCustomAuthorities(String username, List<org.springframework.security.core.GrantedAuthority> authorities)
      Overrides:
      addCustomAuthorities in class org.springframework.security.core.userdetails.jdbc.JdbcDaoImpl
    • setStaticRoles

      public void setStaticRoles(List<String> roles)
      Set a list of statically assigned authorities based on a list of role names.

      All users will be automatically granted these authorities.

      Parameters:
      roles - the role names to grant