// Path: src/main/java/org/myazure/weixin/domain/MaUser.java
// @Entity
// @Table(name = "myazure_weixin_user")
// public class MaUser extends BaseEntity {
// 
//     @Id
//     @GeneratedValue(strategy = GenerationType.AUTO)
//     @Column(name = "user_id")
//     private long id;
// 
//     @Column(name = "username", nullable = false, unique = true)
//     private String userName;
// 
//     @Column(name = "password", nullable = false)
//     private String password;
// 
//     @Column(name = "role", nullable = false)
//     @Enumerated(EnumType.STRING)
//     private MaRole role;
// 
//     @Column(name = "active", columnDefinition = "BIT", length = 1)
//     private boolean active = false;
//     
//     public MaUser() {
// 
//     }
// 
//     public MaUser(String userName, String password, MaRole role) {
//         this.userName = userName;
//         this.password = password;
//         this.role = role;
//     }
// 
//     public long getId() {
//         return id;
//     }
// 
//     public void setId(long id) {
//         this.id = id;
//     }
// 
//     public String getUserName() {
//         return userName;
//     }
// 
//     public void setUserName(String userName) {
//         this.userName = userName;
//     }
// 
//     public String getPassword() {
//         return password;
//     }
// 
//     public void setPassword(String password) {
//         this.password = password;
//     }
// 
//     public MaRole getRole() {
//         return role;
//     }
// 
//     public void setRole(MaRole role) {
//         this.role = role;
//     }
// 
// 	public boolean isActive() {
// 		return active;
// 	}
// 
// 	public void setActive(boolean active) {
// 		this.active = active;
// 	}
// }
// 
// Path: src/main/java/org/myazure/weixin/domain/CurrentUser.java
// public class CurrentUser extends org.springframework.security.core.userdetails.User {
// 
//     /**
// 	 * 
// 	 */
// 	private static final long serialVersionUID = 1L;
// 	private MaUser user;
// 
//     public CurrentUser(MaUser user) {
//         super(user.getUserName(), user.getPassword(), AuthorityUtils.createAuthorityList(user.getRole().toString()));
//         this.user = user;
//     }
// 
//     public MaUser getUser() {
//         return user;
//     }
// 
//     public Long getId() {
//         return user.getId();
//     }
// 
//     public MaRole getRole() {
//         return user.getRole();
//     }
// 
//     @Override
//     public String toString() {
//         return "CurrentUser{" +
//                 "user=" + user +
//                 "} " + super.toString();
//     }
// }
// 
// Path: src/main/java/org/myazure/weixin/service/MaUserService.java
// public interface MaUserService {
// 
//     MaUser getMaUserById(long id);
// 
//     MaUser getMaUserByName(String name);
// 
//     Collection<MaUser> getAllMaUsers();
// 
//     MaUser create(MaUserEntity form);
// }


import org.myazure.weixin.domain.MaUser;
import org.myazure.weixin.domain.CurrentUser;
import org.myazure.weixin.service.MaUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Service;
package org.myazure.weixin.service.currentUser;


/**
 * @author WangZhen
 */
@Service
public class CurrentUserDetailsService implements UserDetailsService {

    private final MaUserService userService;

    @Autowired
    public CurrentUserDetailsService(MaUserService userService) {
        this.userService = userService;
    }


    @Override
    public UserDetails loadUserByUsername(String name) throws UsernameNotFoundException {
        MaUser user = userService.getMaUserByName(name);
        if(user == null) {
            throw new UsernameNotFoundException(name + " not found");
        }
// Path: src/main/java/org/myazure/weixin/domain/MaUser.java
// @Entity
// @Table(name = "myazure_weixin_user")
// public class MaUser extends BaseEntity {
// 
//     @Id
//     @GeneratedValue(strategy = GenerationType.AUTO)
//     @Column(name = "user_id")
//     private long id;
// 
//     @Column(name = "username", nullable = false, unique = true)
//     private String userName;
// 
//     @Column(name = "password", nullable = false)
//     private String password;
// 
//     @Column(name = "role", nullable = false)
//     @Enumerated(EnumType.STRING)
//     private MaRole role;
// 
//     @Column(name = "active", columnDefinition = "BIT", length = 1)
//     private boolean active = false;
//     
//     public MaUser() {
// 
//     }
// 
//     public MaUser(String userName, String password, MaRole role) {
//         this.userName = userName;
//         this.password = password;
//         this.role = role;
//     }
// 
//     public long getId() {
//         return id;
//     }
// 
//     public void setId(long id) {
//         this.id = id;
//     }
// 
//     public String getUserName() {
//         return userName;
//     }
// 
//     public void setUserName(String userName) {
//         this.userName = userName;
//     }
// 
//     public String getPassword() {
//         return password;
//     }
// 
//     public void setPassword(String password) {
//         this.password = password;
//     }
// 
//     public MaRole getRole() {
//         return role;
//     }
// 
//     public void setRole(MaRole role) {
//         this.role = role;
//     }
// 
// 	public boolean isActive() {
// 		return active;
// 	}
// 
// 	public void setActive(boolean active) {
// 		this.active = active;
// 	}
// }
// 
// Path: src/main/java/org/myazure/weixin/domain/CurrentUser.java
// public class CurrentUser extends org.springframework.security.core.userdetails.User {
// 
//     /**
// 	 * 
// 	 */
// 	private static final long serialVersionUID = 1L;
// 	private MaUser user;
// 
//     public CurrentUser(MaUser user) {
//         super(user.getUserName(), user.getPassword(), AuthorityUtils.createAuthorityList(user.getRole().toString()));
//         this.user = user;
//     }
// 
//     public MaUser getUser() {
//         return user;
//     }
// 
//     public Long getId() {
//         return user.getId();
//     }
// 
//     public MaRole getRole() {
//         return user.getRole();
//     }
// 
//     @Override
//     public String toString() {
//         return "CurrentUser{" +
//                 "user=" + user +
//                 "} " + super.toString();
//     }
// }
// 
// Path: src/main/java/org/myazure/weixin/service/MaUserService.java
// public interface MaUserService {
// 
//     MaUser getMaUserById(long id);
// 
//     MaUser getMaUserByName(String name);
// 
//     Collection<MaUser> getAllMaUsers();
// 
//     MaUser create(MaUserEntity form);
// }


// Path: src/main/java/org/myazure/weixin/service/currentUser/CurrentUserDetailsService.java
import org.myazure.weixin.domain.MaUser;
import org.myazure.weixin.domain.CurrentUser;
import org.myazure.weixin.service.MaUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Service;

package org.myazure.weixin.service.currentUser;


/**
 * @author WangZhen
 */
@Service
public class CurrentUserDetailsService implements UserDetailsService {

    private final MaUserService userService;

    @Autowired
    public CurrentUserDetailsService(MaUserService userService) {
        this.userService = userService;
    }


    @Override
    public UserDetails loadUserByUsername(String name) throws UsernameNotFoundException {
        MaUser user = userService.getMaUserByName(name);
        if(user == null) {
            throw new UsernameNotFoundException(name + " not found");
        }
        return new CurrentUser(user);