// Path: auth-server/src/main/java/com/lanshiqin/authserver/core/security/DomainUserDetailsService.java
// @Service
// public class DomainUserDetailsService implements UserDetailsService {
// 
//     @Autowired
//     private AccountRepository accountRepository;    // 账户数据操作接口
// 
//     /**
//      * 根据用户名查找账户信息并返回用户信息实体
//      * @param username 用户名
//      * @return 用于身份认证的 UserDetails 用户信息实体
//      * @throws UsernameNotFoundException
//      */
//     @Override
//     public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
//         Account account = accountRepository.findByUserName(username);
//         if (account!=null){
//             return new User(account.getUserName(),account.getPassWord(), AuthorityUtils.createAuthorityList(account.getRoles()));
//         }else {
//             throw  new UsernameNotFoundException("用户["+username+"]不存在");
//         }
//     }
// }


import com.lanshiqin.authserver.core.security.DomainUserDetailsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.HttpMethod;
import org.springframework.security.authentication.AuthenticationManager;
import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
import org.springframework.security.config.annotation.method.configuration.EnableGlobalMethodSecurity;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
import org.springframework.security.core.userdetails.UserDetailsService;
package com.lanshiqin.authserver.core.config;


/**
 * 安全配置
 * @ EnableWebSecurity 启用web安全配置
 * @ EnableGlobalMethodSecurity 启用全局方法安全注解，就可以在方法上使用注解来对请求进行过滤
 */
@Configuration
@EnableWebSecurity
@EnableGlobalMethodSecurity(prePostEnabled = true)
public class SecurityConfig extends WebSecurityConfigurerAdapter {

    /**
     * 注入用户信息服务
     * @return 用户信息服务对象
     */
    @Bean
    public UserDetailsService userDetailsService() {
// Path: auth-server/src/main/java/com/lanshiqin/authserver/core/security/DomainUserDetailsService.java
// @Service
// public class DomainUserDetailsService implements UserDetailsService {
// 
//     @Autowired
//     private AccountRepository accountRepository;    // 账户数据操作接口
// 
//     /**
//      * 根据用户名查找账户信息并返回用户信息实体
//      * @param username 用户名
//      * @return 用于身份认证的 UserDetails 用户信息实体
//      * @throws UsernameNotFoundException
//      */
//     @Override
//     public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
//         Account account = accountRepository.findByUserName(username);
//         if (account!=null){
//             return new User(account.getUserName(),account.getPassWord(), AuthorityUtils.createAuthorityList(account.getRoles()));
//         }else {
//             throw  new UsernameNotFoundException("用户["+username+"]不存在");
//         }
//     }
// }


// Path: auth-server/src/main/java/com/lanshiqin/authserver/core/config/SecurityConfig.java
import com.lanshiqin.authserver.core.security.DomainUserDetailsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.HttpMethod;
import org.springframework.security.authentication.AuthenticationManager;
import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
import org.springframework.security.config.annotation.method.configuration.EnableGlobalMethodSecurity;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
import org.springframework.security.core.userdetails.UserDetailsService;

package com.lanshiqin.authserver.core.config;


/**
 * 安全配置
 * @ EnableWebSecurity 启用web安全配置
 * @ EnableGlobalMethodSecurity 启用全局方法安全注解，就可以在方法上使用注解来对请求进行过滤
 */
@Configuration
@EnableWebSecurity
@EnableGlobalMethodSecurity(prePostEnabled = true)
public class SecurityConfig extends WebSecurityConfigurerAdapter {

    /**
     * 注入用户信息服务
     * @return 用户信息服务对象
     */
    @Bean
    public UserDetailsService userDetailsService() {
        return new DomainUserDetailsService();