All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.nerv.security.domain.JwtUserFactory Maven / Gradle / Ivy

There is a newer version: 3.0.0
Show newest version
package io.nerv.security.domain;

import io.nerv.core.enums.LockEnumm;
import io.nerv.core.security.domain.JwtUserDetail;
import io.nerv.web.sys.role.entity.RoleEntity;
import io.nerv.web.sys.user.entity.UserEntity;

import java.util.List;
import java.util.stream.Collectors;

/**
 * JwtUser 工厂
 */
public final class JwtUserFactory {

    private JwtUserFactory() {
    }

    public static JwtUserDetail create(UserEntity user) {
        return new JwtUserDetail(
                String.valueOf(user.getId()),
                user.getAccount(),
                user.getPassword(),
                user.getDeptId(),
                user.getDeptName(),
                user.getName(),
                user.getNickName(),
                LockEnumm.LOCK.getIndex().equals(user.getLocked()),
                mapToGrantedAuthorities(user.getRoles())
        );
    }

    private static List mapToGrantedAuthorities(List authorities) {
        return authorities.stream()
                .map(item -> new JwtGrantedAuthority(item.getCode(), item))
                .collect(Collectors.toList());
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy