2025-12-18 10:17:43 +08:00

47 lines
941 B
Java

package com.ruoyi.common.utils;
import java.util.Random;
import com.ruoyi.common.core.domain.entity.SysUser;
/**
* shiro 工具类
*
* @author ruoyi
*/
public class ShiroUtils
{
public static SysUser getSysUser()
{
return SecurityUtils.getLoginUser().getUser();
}
public static Long getUserId()
{
return getSysUser().getUserId();
}
public static String getLoginName()
{
return getSysUser().getLoginName();
}
/**
* 生成随机盐
*/
public static String randomSalt()
{
byte[] bytes = new byte[10];
Random r = new Random();
r.nextBytes(bytes);
String hex = new String();
for (int i = 0; i < bytes.length; i++) {
String s = Integer.toHexString(bytes[i] & 0xff);
if (s.length() < 2) {
hex += "0";
}
hex += s;
}
return hex;
}
}