47 lines
1.4 KiB
Java
47 lines
1.4 KiB
Java
package net.alawn.bill.security;
|
|
|
|
import net.alawn.bill.entity.po.Authority;
|
|
import net.alawn.bill.entity.po.User;
|
|
import org.springframework.security.core.GrantedAuthority;
|
|
import org.springframework.security.core.authority.SimpleGrantedAuthority;
|
|
|
|
import java.util.Arrays;
|
|
import java.util.List;
|
|
import java.util.Set;
|
|
import java.util.stream.Collectors;
|
|
|
|
/**
|
|
* @Author: Alawn
|
|
* @Description:
|
|
* @Date: Create in 16:45 2019-05-20
|
|
*/
|
|
public class UserFactory {
|
|
|
|
private UserFactory() {
|
|
}
|
|
|
|
public static AuthUser createAuthUser(User user) {
|
|
// user.toUserDetails();
|
|
return new AuthUser(
|
|
user.getId(),
|
|
user.getUsername(),
|
|
user.getPassword(),
|
|
user.getEmail(),
|
|
user.isEnabled(),
|
|
mapToGrantedAuthorities(user.getAuthorities()),
|
|
user.getLastPasswordResetDate()
|
|
);
|
|
}
|
|
|
|
private static Set<GrantedAuthority> mapToGrantedAuthorities(Set<Authority> authorities) {
|
|
return authorities.stream()
|
|
.map(authority -> new SimpleGrantedAuthority(authority.getId().getAuthority()))
|
|
.collect(Collectors.toSet());
|
|
}
|
|
// private static List<GrantedAuthority> mapToGrantedAuthorities(List<String> authorities) {
|
|
// return authorities.stream()
|
|
// .map(SimpleGrantedAuthority::new)
|
|
// .collect(Collectors.toList());
|
|
// }
|
|
}
|