content: package com.os.china.entity;
  
  import org.springframework.security.core.GrantedAuthority;
  import org.springframework.security.core.authority.SimpleGrantedAuthority;
  import org.springframework.security.core.userdetails.UserDetails;
  
  import javax.persistence.*;
  import java.util.ArrayList;
  import java.util.Collection;
  import java.util.List;
  
  /**
   * @author ZhangPengFei
   * @Discription
   * @Data 2017-3-17
   * @Version 1.0.0
   */
  @Entity
  public class SysUser implements UserDetails {
  
  	@Id
  	@GeneratedValue
  	private Long id;
  	private String username;
  	private String password;
  	@ManyToMany(cascade = {CascadeType.REFRESH}, fetch = FetchType.EAGER)
  	private List<SysRole> roles;
  
  	@Override
  	public Collection<? extends GrantedAuthority> getAuthorities() {
  		List<GrantedAuthority> auths = new ArrayList<GrantedAuthority>();
  		List<SysRole> roles = this.getRoles();
  		for (SysRole role : roles) {
  			auths.add(new SimpleGrantedAuthority(role.getName()));
  		}
  		return auths;
  	}
  
  	@Override
  	public String getPassword() {
  		return password;
  	}
  
  	@Override
  	public String getUsername() {
  		return null;
  	}
  
  	@Override
  	public boolean isAccountNonExpired() {
  		return true;
  	}
  
  	@Override
  	public boolean isAccountNonLocked() {
  		return true;
  	}
  
  	@Override
  	public boolean isCredentialsNonExpired() {
  		return true;
  	}
  
  	@Override
  	public boolean isEnabled() {
  		return true;
  	}
  
  	public Long getId() {
  		return id;
  	}
  
  	public void setId(Long id) {
  		this.id = id;
  	}
  
  	public void setUsername(String username) {
  		this.username = username;
  	}
  
  	public void setPassword(String password) {
  		this.password = password;
  	}
  
  	public List<SysRole> getRoles() {
  		return roles;
  	}
  
  	public void setRoles(List<SysRole> roles) {
  		this.roles = roles;
  	}
  }
  