简体   繁体   中英

Spring security UserDetailsService configuration

I added a custom UserDetails and UserDetailsService class to my spring project and want to use them in combination with httpbasic. How can I configure spring to use my custom classes?

My application.yml looks like this:

security:
  basic:
    enabled: false
  require_ssl: false
  enable_csrf: false
  ignored:
    - /register/**
    - /acitivate/**
  headers:
    hsts: domain
  sessions: stateless

UserDetailsService:

@Service
@Transactional(readOnly = true)
public class UserDetailsServiceAdapter implements UserDetailsService {

    @Override
    public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
      //...
    }

}

Do I have to define Beans, or is it possible to set it within my application.yml?

You do not have to define the bean for the " UserDetails " in your XML. The fact that your config file is in YAML does not make things any different.

so in your case, you can derive from it (extend it) and it will be OK. Remember to call "super.loadUserByUsername()" in your impl, and in the class where you use it you will have to down-cast.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM