package com.patzn.lims.security;//package ops.china.service.upms.security;
//
//import java.util.Collection;
//
//import org.joda.time.DateTime;
//import org.springframework.security.core.GrantedAuthority;
//import org.springframework.security.core.userdetails.UserDetails;
//
//import com.fasterxml.jackson.annotation.JsonIgnore;
//
//import lombok.Data;
//import com.patzn.lims.sys.entity.SysUser;
//
///**
// * <p>
// * 用户授权凭证
// * </p>
// *
// * @author hubin
// * @since 2019-03-19
// */
//@Data
//public class UserPrincipal implements UserDetails {
//    private Long companyId;
//    private Long id;
//    private String username;
//    @JsonIgnore
//    private String password;
//    @JsonIgnore
//    private String clientIp;
//    @JsonIgnore
//    private boolean accountNonExpired = true;
//    @JsonIgnore
//    private boolean credentialsNonExpired = true;
//    @JsonIgnore
//    private boolean accountNonLocked;
//    @JsonIgnore
//    private boolean enabled;
//
//    public UserPrincipal(Long companyId, Long id, String username, String password){
//        this.companyId = companyId;
//        this.id = id;
//        this.username = username;
//        this.password = password;
//    }
//
//    public static UserPrincipal create(final SysUser sysUser) {
////        final String[] roleNames = { "USER", "ADMIN" };
////        final List<GrantedAuthority> authorities = Arrays.asList(roleNames).stream()
////                .map(roleName -> new SimpleGrantedAuthority(roleName)).collect(Collectors.toList());
//        UserPrincipal userPrincipal = new UserPrincipal(sysUser.getCompanyId(),
//                sysUser.getId(), sysUser.getUsername(), sysUser.getPassword());
//        userPrincipal.setAccountNonLocked(sysUser.getAccountLocked() == 0);
//        userPrincipal.setEnabled(sysUser.getAccountEnabled() == 1);
//        if (null != sysUser.getAccountExpired()) {
//            userPrincipal.setAccountNonExpired(DateTime.now()
//                    .isBefore(sysUser.getAccountExpired().getTime()));
//        }
//        if (null != sysUser.getPasswordExpired()) {
//            userPrincipal.setCredentialsNonExpired(DateTime.now()
//                    .isBefore(sysUser.getPasswordExpired().getTime()));
//        }
//        return userPrincipal;
//    }
//
//    @Override
//    public Collection<? extends GrantedAuthority> getAuthorities() {
//        return null;
//    }
//
//    @Override
//    public String getPassword() {
//        return this.password;
//    }
//
//    @Override
//    public boolean isAccountNonExpired() {
//        return this.accountNonExpired;
//    }
//
//    @Override
//    public boolean isAccountNonLocked() {
//        return this.accountNonLocked;
//    }
//
//    @Override
//    public boolean isCredentialsNonExpired() {
//        return this.credentialsNonExpired;
//    }
//
//    @Override
//    public boolean isEnabled() {
//        return this.enabled;
//    }
//}
