package com.ycl.bo; import com.ycl.entity.user.UmsAdmin; import com.ycl.entity.user.UmsMenu; import org.springframework.security.core.GrantedAuthority; import org.springframework.security.core.authority.SimpleGrantedAuthority; import org.springframework.security.core.userdetails.UserDetails; import java.util.Collection; import java.util.List; import java.util.stream.Collectors; /** * SpringSecurity需要的用户详情 */ public class AdminUserDetails implements UserDetails { private UmsAdmin umsAdmin; private List resourceList; public AdminUserDetails(UmsAdmin umsAdmin, List resourceList) { this.umsAdmin = umsAdmin; this.resourceList = resourceList; } @Override public Collection getAuthorities() { //返回当前用户的角色 return resourceList.stream() .map(role -> new SimpleGrantedAuthority(role.getId() + ":" + role.getTitle())) .collect(Collectors.toList()); } @Override public String getPassword() { return umsAdmin.getPassword(); } @Override public String getUsername() { return umsAdmin.getUsername(); } @Override public boolean isAccountNonExpired() { return true; } @Override public boolean isAccountNonLocked() { return true; } @Override public boolean isCredentialsNonExpired() { return true; } @Override public boolean isEnabled() { return umsAdmin.getStatus().equals(1); } public Long getUserId() { return umsAdmin.getId(); } public UmsAdmin getUmsAdmin() { return umsAdmin; } }