修改了一些代码的注释,方便后期对代码进行维护,修改,以及新功能模块的开发
This commit is contained in:
parent
0db90859ec
commit
465952560f
|
|
@ -9,7 +9,7 @@ import com.ruoyi.framework.web.base.BaseController;
|
|||
import com.ruoyi.framework.web.domain.Server;
|
||||
|
||||
/**
|
||||
* 服务器监控
|
||||
* 服务器监控,获取项目部署的服务器的cpu、内存等情况
|
||||
*
|
||||
* @author ruoyi
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -20,5 +20,5 @@ Spring Boot Version: ${spring-boot.version}
|
|||
// ========`-.____`-.___\_____/___.-`____.-'======== //
|
||||
// `=---=' //
|
||||
// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ //
|
||||
// 佛祖保佑 永不宕机 永无BUG //
|
||||
// 永不宕机 永无BUG //
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
|
@ -1,15 +1,16 @@
|
|||
package com.ruoyi.common.config;
|
||||
|
||||
import com.ruoyi.common.utils.StringUtils;
|
||||
import com.ruoyi.common.utils.YamlUtil;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.io.FileNotFoundException;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import com.ruoyi.common.utils.StringUtils;
|
||||
import com.ruoyi.common.utils.YamlUtil;
|
||||
|
||||
/**
|
||||
* 全局配置类
|
||||
* 全局配置类,读取 application.yml 配置文件的参数
|
||||
*
|
||||
* @author ruoyi
|
||||
*/
|
||||
|
|
@ -43,8 +44,9 @@ public class Global
|
|||
{
|
||||
synchronized (Global.class)
|
||||
{
|
||||
if (global == null)
|
||||
if (global == null) {
|
||||
global = new Global();
|
||||
}
|
||||
}
|
||||
}
|
||||
return global;
|
||||
|
|
|
|||
|
|
@ -1,20 +1,20 @@
|
|||
package com.ruoyi.framework.util;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import org.apache.tomcat.util.http.fileupload.FileUploadBase.FileSizeLimitExceededException;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
import com.ruoyi.common.config.Global;
|
||||
import com.ruoyi.common.exception.file.FileNameLengthLimitExceededException;
|
||||
import com.ruoyi.common.utils.Md5Utils;
|
||||
import org.apache.tomcat.util.http.fileupload.FileUploadBase.FileSizeLimitExceededException;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* 文件上传工具类
|
||||
*
|
||||
*
|
||||
* @author ruoyi
|
||||
*/
|
||||
public class FileUploadUtils
|
||||
{
|
||||
public class FileUploadUtils {
|
||||
/**
|
||||
* 默认大小 50M
|
||||
*/
|
||||
|
|
@ -37,13 +37,11 @@ public class FileUploadUtils
|
|||
|
||||
private static int counter = 0;
|
||||
|
||||
public static void setDefaultBaseDir(String defaultBaseDir)
|
||||
{
|
||||
public static void setDefaultBaseDir(String defaultBaseDir) {
|
||||
FileUploadUtils.defaultBaseDir = defaultBaseDir;
|
||||
}
|
||||
|
||||
public static String getDefaultBaseDir()
|
||||
{
|
||||
public static String getDefaultBaseDir() {
|
||||
return defaultBaseDir;
|
||||
}
|
||||
|
||||
|
|
@ -54,14 +52,10 @@ public class FileUploadUtils
|
|||
* @return 文件名称
|
||||
* @throws Exception
|
||||
*/
|
||||
public static final String upload(MultipartFile file) throws IOException
|
||||
{
|
||||
try
|
||||
{
|
||||
public static final String upload(MultipartFile file) throws IOException {
|
||||
try {
|
||||
return upload(getDefaultBaseDir(), file, FileUploadUtils.IMAGE_JPG_EXTENSION);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
} catch (Exception e) {
|
||||
throw new IOException(e);
|
||||
}
|
||||
}
|
||||
|
|
@ -70,40 +64,35 @@ public class FileUploadUtils
|
|||
* 根据文件路径上传
|
||||
*
|
||||
* @param baseDir 相对应用的基目录
|
||||
* @param file 上传的文件
|
||||
* @param file 上传的文件
|
||||
* @return 文件名称
|
||||
* @throws IOException
|
||||
*/
|
||||
public static final String upload(String baseDir, MultipartFile file) throws IOException
|
||||
{
|
||||
try
|
||||
{
|
||||
public static final String upload(String baseDir, MultipartFile file) throws IOException {
|
||||
try {
|
||||
return upload(baseDir, file, FileUploadUtils.IMAGE_JPG_EXTENSION);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
} catch (Exception e) {
|
||||
throw new IOException(e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 文件上传
|
||||
*
|
||||
* @param baseDir 相对应用的基目录
|
||||
* @param file 上传的文件
|
||||
* 文件上传,先判断文件大小是否是在允许上传的范围内,如果是
|
||||
* 对文件进行编码处理,处理完成后判断是否需要创建文件夹,不需要就创建文件,
|
||||
* 然后上传文件
|
||||
* @param baseDir 相对应用的基目录
|
||||
* @param file 上传的文件
|
||||
* @param extension 上传文件类型
|
||||
* @return 返回上传成功的文件名
|
||||
* @throws FileSizeLimitExceededException 如果超出最大大小
|
||||
* @throws FileSizeLimitExceededException 如果超出最大大小
|
||||
* @throws FileNameLengthLimitExceededException 文件名太长
|
||||
* @throws IOException 比如读写文件出错时
|
||||
* @throws IOException 比如读写文件出错时
|
||||
*/
|
||||
public static final String upload(String baseDir, MultipartFile file, String extension)
|
||||
throws FileSizeLimitExceededException, IOException, FileNameLengthLimitExceededException
|
||||
{
|
||||
throws FileSizeLimitExceededException, IOException, FileNameLengthLimitExceededException {
|
||||
|
||||
int fileNamelength = file.getOriginalFilename().length();
|
||||
if (fileNamelength > FileUploadUtils.DEFAULT_FILE_NAME_LENGTH)
|
||||
{
|
||||
if (fileNamelength > FileUploadUtils.DEFAULT_FILE_NAME_LENGTH) {
|
||||
throw new FileNameLengthLimitExceededException(file.getOriginalFilename(), fileNamelength,
|
||||
FileUploadUtils.DEFAULT_FILE_NAME_LENGTH);
|
||||
}
|
||||
|
|
@ -117,16 +106,21 @@ public class FileUploadUtils
|
|||
return fileName;
|
||||
}
|
||||
|
||||
private static final File getAbsoluteFile(String uploadDir, String filename) throws IOException
|
||||
{
|
||||
/**
|
||||
* 判断文件路径下是否有文件夹,如果有就创建文件,如果没有就创建文件夹然后在创建文件
|
||||
*
|
||||
* @param uploadDir 上传的文文件夹
|
||||
* @param filename 文件名
|
||||
* @return
|
||||
* @throws IOException
|
||||
*/
|
||||
private static final File getAbsoluteFile(String uploadDir, String filename) throws IOException {
|
||||
File desc = new File(File.separator + filename);
|
||||
|
||||
if (!desc.getParentFile().exists())
|
||||
{
|
||||
if (!desc.getParentFile().exists()) {
|
||||
desc.getParentFile().mkdirs();
|
||||
}
|
||||
if (!desc.exists())
|
||||
{
|
||||
if (!desc.exists()) {
|
||||
desc.createNewFile();
|
||||
}
|
||||
return desc;
|
||||
|
|
@ -135,8 +129,7 @@ public class FileUploadUtils
|
|||
/**
|
||||
* 编码文件名
|
||||
*/
|
||||
private static final String encodingFilename(String filename, String extension)
|
||||
{
|
||||
private static final String encodingFilename(String filename, String extension) {
|
||||
filename = filename.replace("_", " ");
|
||||
filename = Md5Utils.hash(filename + System.nanoTime() + counter++) + extension;
|
||||
return filename;
|
||||
|
|
@ -149,11 +142,9 @@ public class FileUploadUtils
|
|||
* @return
|
||||
* @throws FileSizeLimitExceededException 如果超出最大大小
|
||||
*/
|
||||
public static final void assertAllowed(MultipartFile file) throws FileSizeLimitExceededException
|
||||
{
|
||||
public static final void assertAllowed(MultipartFile file) throws FileSizeLimitExceededException {
|
||||
long size = file.getSize();
|
||||
if (DEFAULT_MAX_SIZE != -1 && size > DEFAULT_MAX_SIZE)
|
||||
{
|
||||
if (DEFAULT_MAX_SIZE != -1 && size > DEFAULT_MAX_SIZE) {
|
||||
throw new FileSizeLimitExceededException("not allowed upload upload", size, DEFAULT_MAX_SIZE);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,33 +1,34 @@
|
|||
package com.ruoyi.framework.util;
|
||||
|
||||
import java.io.PrintWriter;
|
||||
import java.io.StringWriter;
|
||||
import java.util.Map;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import com.ruoyi.common.json.JSON;
|
||||
import com.ruoyi.common.utils.IpUtils;
|
||||
import org.apache.shiro.SecurityUtils;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import com.ruoyi.common.json.JSON;
|
||||
import com.ruoyi.common.utils.IpUtils;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.io.PrintWriter;
|
||||
import java.io.StringWriter;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 处理并记录日志文件
|
||||
*
|
||||
* 处理并记录日志文件,
|
||||
* 日志的工具类
|
||||
*
|
||||
* @author ruoyi
|
||||
*/
|
||||
public class LogUtils
|
||||
{
|
||||
public class LogUtils {
|
||||
public static final Logger ERROR_LOG = LoggerFactory.getLogger("sys-error");
|
||||
public static final Logger ACCESS_LOG = LoggerFactory.getLogger("sys-access");
|
||||
|
||||
/**
|
||||
* 记录访问日志 [username][jsessionid][ip][accept][UserAgent][url][params][Referer]
|
||||
* 获取用户名、seessionId、ip、accept、url、paramas等参数
|
||||
*
|
||||
* @param request
|
||||
* @throws Exception
|
||||
*/
|
||||
public static void logAccess(HttpServletRequest request) throws Exception
|
||||
{
|
||||
public static void logAccess(HttpServletRequest request) throws Exception {
|
||||
String username = getUsername();
|
||||
String jsessionId = request.getRequestedSessionId();
|
||||
String ip = IpUtils.getIpAddr(request);
|
||||
|
|
@ -54,8 +55,7 @@ public class LogUtils
|
|||
* @param message
|
||||
* @param e
|
||||
*/
|
||||
public static void logError(String message, Throwable e)
|
||||
{
|
||||
public static void logError(String message, Throwable e) {
|
||||
String username = getUsername();
|
||||
StringBuilder s = new StringBuilder();
|
||||
s.append(getBlock("exception"));
|
||||
|
|
@ -69,8 +69,7 @@ public class LogUtils
|
|||
*
|
||||
* @param request
|
||||
*/
|
||||
public static void logPageError(HttpServletRequest request)
|
||||
{
|
||||
public static void logPageError(HttpServletRequest request) {
|
||||
String username = getUsername();
|
||||
|
||||
Integer statusCode = (Integer) request.getAttribute("javax.servlet.error.status_code");
|
||||
|
|
@ -78,8 +77,7 @@ public class LogUtils
|
|||
String uri = (String) request.getAttribute("javax.servlet.error.request_uri");
|
||||
Throwable t = (Throwable) request.getAttribute("javax.servlet.error.exception");
|
||||
|
||||
if (statusCode == null)
|
||||
{
|
||||
if (statusCode == null) {
|
||||
statusCode = 0;
|
||||
}
|
||||
|
||||
|
|
@ -94,8 +92,7 @@ public class LogUtils
|
|||
s.append(getBlock(request.getHeader("Referer")));
|
||||
StringWriter sw = new StringWriter();
|
||||
|
||||
while (t != null)
|
||||
{
|
||||
while (t != null) {
|
||||
t.printStackTrace(new PrintWriter(sw));
|
||||
t = t.getCause();
|
||||
}
|
||||
|
|
@ -104,33 +101,55 @@ public class LogUtils
|
|||
|
||||
}
|
||||
|
||||
public static String getBlock(Object msg)
|
||||
{
|
||||
if (msg == null)
|
||||
{
|
||||
/**
|
||||
* 获取代码块
|
||||
*
|
||||
* @param msg
|
||||
* @return
|
||||
*/
|
||||
public static String getBlock(Object msg) {
|
||||
if (msg == null) {
|
||||
msg = "";
|
||||
}
|
||||
return "[" + msg.toString() + "]";
|
||||
}
|
||||
|
||||
protected static String getParams(HttpServletRequest request) throws Exception
|
||||
{
|
||||
/**
|
||||
* 获取参数并将参数转成Json格式
|
||||
*
|
||||
* @param request
|
||||
* @return
|
||||
* @throws Exception
|
||||
*/
|
||||
protected static String getParams(HttpServletRequest request) throws Exception {
|
||||
Map<String, String[]> params = request.getParameterMap();
|
||||
return JSON.marshal(params);
|
||||
}
|
||||
|
||||
protected static String getUsername()
|
||||
{
|
||||
/**
|
||||
* 获取用户名
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
protected static String getUsername() {
|
||||
return (String) SecurityUtils.getSubject().getPrincipal();
|
||||
}
|
||||
|
||||
public static Logger getAccessLog()
|
||||
{
|
||||
/**
|
||||
* 获取数据库访问日志
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public static Logger getAccessLog() {
|
||||
return ACCESS_LOG;
|
||||
}
|
||||
|
||||
public static Logger getErrorLog()
|
||||
{
|
||||
/**
|
||||
* 获取错误日志
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public static Logger getErrorLog() {
|
||||
return ERROR_LOG;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,21 +3,19 @@ package com.ruoyi.framework.util;
|
|||
import org.springframework.context.MessageSource;
|
||||
|
||||
/**
|
||||
* 获取i18n资源文件
|
||||
*
|
||||
* 获取i18n资源文件,代码国际化处理
|
||||
*
|
||||
* @author ruoyi
|
||||
*/
|
||||
public class MessageUtils
|
||||
{
|
||||
public class MessageUtils {
|
||||
/**
|
||||
* 根据消息键和参数 获取消息 委托给spring messageSource
|
||||
*
|
||||
* @param code 消息键
|
||||
* @param args 参数
|
||||
* @return
|
||||
* @return message
|
||||
*/
|
||||
public static String message(String code, Object... args)
|
||||
{
|
||||
public static String message(String code, Object... args) {
|
||||
MessageSource messageSource = SpringUtils.getBean(MessageSource.class);
|
||||
return messageSource.getMessage(code, args, null);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,44 +1,34 @@
|
|||
package com.ruoyi.framework.util;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import com.ruoyi.common.constant.PermissionConstants;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
/**
|
||||
* permission 工具类
|
||||
*
|
||||
*
|
||||
* @author ruoyi
|
||||
*/
|
||||
public class PermissionUtils
|
||||
{
|
||||
public class PermissionUtils {
|
||||
/**
|
||||
* 权限错误消息提醒
|
||||
*
|
||||
* 权限错误消息提醒,联合权限通用配置常量,对权限消息进行有效的提醒
|
||||
*
|
||||
* @param permissionsStr 错误信息
|
||||
* @return
|
||||
*/
|
||||
public static String getMsg(String permissionsStr)
|
||||
{
|
||||
public static String getMsg(String permissionsStr) {
|
||||
//获取中间的字符串
|
||||
String permission = StringUtils.substringBetween(permissionsStr, "[", "]");
|
||||
String msg = MessageUtils.message("no.view.permission", permission);
|
||||
if (StringUtils.endsWithIgnoreCase(permission, PermissionConstants.ADD_PERMISSION))
|
||||
{
|
||||
if (StringUtils.endsWithIgnoreCase(permission, PermissionConstants.ADD_PERMISSION)) {
|
||||
msg = MessageUtils.message("no.create.permission", permission);
|
||||
}
|
||||
else if (StringUtils.endsWithIgnoreCase(permission, PermissionConstants.EDIT_PERMISSION))
|
||||
{
|
||||
} else if (StringUtils.endsWithIgnoreCase(permission, PermissionConstants.EDIT_PERMISSION)) {
|
||||
msg = MessageUtils.message("no.update.permission", permission);
|
||||
}
|
||||
else if (StringUtils.endsWithIgnoreCase(permission, PermissionConstants.REMOVE_PERMISSION))
|
||||
{
|
||||
} else if (StringUtils.endsWithIgnoreCase(permission, PermissionConstants.REMOVE_PERMISSION)) {
|
||||
msg = MessageUtils.message("no.delete.permission", permission);
|
||||
}
|
||||
else if (StringUtils.endsWithIgnoreCase(permission, PermissionConstants.EXPORT_PERMISSION))
|
||||
{
|
||||
} else if (StringUtils.endsWithIgnoreCase(permission, PermissionConstants.EXPORT_PERMISSION)) {
|
||||
msg = MessageUtils.message("no.export.permission", permission);
|
||||
}
|
||||
else if (StringUtils.endsWithAny(permission,
|
||||
new String[] { PermissionConstants.VIEW_PERMISSION, PermissionConstants.LIST_PERMISSION }))
|
||||
{
|
||||
} else if (StringUtils.endsWithAny(permission,
|
||||
new String[]{PermissionConstants.VIEW_PERMISSION, PermissionConstants.LIST_PERMISSION})) {
|
||||
msg = MessageUtils.message("no.view.permission", permission);
|
||||
}
|
||||
return msg;
|
||||
|
|
|
|||
|
|
@ -1,101 +1,89 @@
|
|||
package com.ruoyi.framework.util;
|
||||
|
||||
import java.io.IOException;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import javax.servlet.http.HttpSession;
|
||||
import com.ruoyi.common.support.Convert;
|
||||
import com.ruoyi.common.utils.StringUtils;
|
||||
import org.springframework.web.context.request.RequestAttributes;
|
||||
import org.springframework.web.context.request.RequestContextHolder;
|
||||
import org.springframework.web.context.request.ServletRequestAttributes;
|
||||
import com.ruoyi.common.support.Convert;
|
||||
import com.ruoyi.common.utils.StringUtils;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import javax.servlet.http.HttpSession;
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* 客户端工具类
|
||||
*
|
||||
*
|
||||
* @author ruoyi
|
||||
*/
|
||||
public class ServletUtils
|
||||
{
|
||||
public class ServletUtils {
|
||||
/**
|
||||
* 获取String参数
|
||||
*/
|
||||
public static String getParameter(String name)
|
||||
{
|
||||
public static String getParameter(String name) {
|
||||
return getRequest().getParameter(name);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取String参数
|
||||
*/
|
||||
public static String getParameter(String name, String defaultValue)
|
||||
{
|
||||
public static String getParameter(String name, String defaultValue) {
|
||||
return Convert.toStr(getRequest().getParameter(name), defaultValue);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取Integer参数
|
||||
*/
|
||||
public static Integer getParameterToInt(String name)
|
||||
{
|
||||
public static Integer getParameterToInt(String name) {
|
||||
return Convert.toInt(getRequest().getParameter(name));
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取Integer参数
|
||||
*/
|
||||
public static Integer getParameterToInt(String name, Integer defaultValue)
|
||||
{
|
||||
public static Integer getParameterToInt(String name, Integer defaultValue) {
|
||||
return Convert.toInt(getRequest().getParameter(name), defaultValue);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取request
|
||||
*/
|
||||
public static HttpServletRequest getRequest()
|
||||
{
|
||||
public static HttpServletRequest getRequest() {
|
||||
return getRequestAttributes().getRequest();
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取response
|
||||
*/
|
||||
public static HttpServletResponse getResponse()
|
||||
{
|
||||
public static HttpServletResponse getResponse() {
|
||||
return getRequestAttributes().getResponse();
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取session
|
||||
*/
|
||||
public static HttpSession getSession()
|
||||
{
|
||||
public static HttpSession getSession() {
|
||||
return getRequest().getSession();
|
||||
}
|
||||
|
||||
public static ServletRequestAttributes getRequestAttributes()
|
||||
{
|
||||
public static ServletRequestAttributes getRequestAttributes() {
|
||||
RequestAttributes attributes = RequestContextHolder.getRequestAttributes();
|
||||
return (ServletRequestAttributes) attributes;
|
||||
}
|
||||
|
||||
/**
|
||||
* 将字符串渲染到客户端
|
||||
*
|
||||
*
|
||||
* @param response 渲染对象
|
||||
* @param string 待渲染的字符串
|
||||
* @param string 待渲染的字符串
|
||||
* @return null
|
||||
*/
|
||||
public static String renderString(HttpServletResponse response, String string)
|
||||
{
|
||||
try
|
||||
{
|
||||
public static String renderString(HttpServletResponse response, String string) {
|
||||
try {
|
||||
response.setContentType("application/json");
|
||||
response.setCharacterEncoding("utf-8");
|
||||
response.getWriter().print(string);
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
|
|
@ -103,33 +91,29 @@ public class ServletUtils
|
|||
|
||||
/**
|
||||
* 是否是Ajax异步请求
|
||||
*
|
||||
*
|
||||
* @param request
|
||||
*/
|
||||
public static boolean isAjaxRequest(HttpServletRequest request)
|
||||
{
|
||||
public static boolean isAjaxRequest(HttpServletRequest request) {
|
||||
|
||||
String accept = request.getHeader("accept");
|
||||
if (accept != null && accept.indexOf("application/json") != -1)
|
||||
{
|
||||
// 不存在为-1,存在为0
|
||||
if (accept != null && accept.indexOf("application/json") != -1) {
|
||||
return true;
|
||||
}
|
||||
|
||||
String xRequestedWith = request.getHeader("X-Requested-With");
|
||||
if (xRequestedWith != null && xRequestedWith.indexOf("XMLHttpRequest") != -1)
|
||||
{
|
||||
if (xRequestedWith != null && xRequestedWith.indexOf("XMLHttpRequest") != -1) {
|
||||
return true;
|
||||
}
|
||||
|
||||
String uri = request.getRequestURI();
|
||||
if (StringUtils.inStringIgnoreCase(uri, ".json", ".xml"))
|
||||
{
|
||||
if (StringUtils.inStringIgnoreCase(uri, ".json", ".xml")) {
|
||||
return true;
|
||||
}
|
||||
|
||||
String ajax = request.getParameter("__ajax");
|
||||
if (StringUtils.inStringIgnoreCase(ajax, "json", "xml"))
|
||||
{
|
||||
if (StringUtils.inStringIgnoreCase(ajax, "json", "xml")) {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,54 +1,58 @@
|
|||
package com.ruoyi.framework.util;
|
||||
|
||||
import org.apache.shiro.SecurityUtils;
|
||||
import org.apache.shiro.crypto.SecureRandomNumberGenerator;
|
||||
import org.apache.shiro.mgt.RealmSecurityManager;
|
||||
import org.apache.shiro.session.Session;
|
||||
import org.apache.shiro.subject.Subject;
|
||||
import org.apache.shiro.subject.PrincipalCollection;
|
||||
import org.apache.shiro.subject.SimplePrincipalCollection;
|
||||
import com.ruoyi.common.utils.StringUtils;
|
||||
import com.ruoyi.common.utils.bean.BeanUtils;
|
||||
import com.ruoyi.framework.shiro.realm.UserRealm;
|
||||
import com.ruoyi.system.domain.SysUser;
|
||||
import org.apache.shiro.SecurityUtils;
|
||||
import org.apache.shiro.crypto.SecureRandomNumberGenerator;
|
||||
import org.apache.shiro.mgt.RealmSecurityManager;
|
||||
import org.apache.shiro.session.Session;
|
||||
import org.apache.shiro.subject.PrincipalCollection;
|
||||
import org.apache.shiro.subject.SimplePrincipalCollection;
|
||||
import org.apache.shiro.subject.Subject;
|
||||
|
||||
/**
|
||||
* shiro 工具类
|
||||
*
|
||||
*
|
||||
* @author ruoyi
|
||||
*/
|
||||
public class ShiroUtils
|
||||
{
|
||||
public static Subject getSubject()
|
||||
{
|
||||
public class ShiroUtils {
|
||||
public static Subject getSubject() {
|
||||
return SecurityUtils.getSubject();
|
||||
}
|
||||
|
||||
public static Session getSession()
|
||||
{
|
||||
public static Session getSession() {
|
||||
return SecurityUtils.getSubject().getSession();
|
||||
}
|
||||
|
||||
public static void logout()
|
||||
{
|
||||
public static void logout() {
|
||||
getSubject().logout();
|
||||
}
|
||||
|
||||
public static SysUser getSysUser()
|
||||
{
|
||||
/**
|
||||
* 获取到用户
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public static SysUser getSysUser() {
|
||||
SysUser user = null;
|
||||
Object obj = getSubject().getPrincipal();
|
||||
if (StringUtils.isNotNull(obj))
|
||||
{
|
||||
if (StringUtils.isNotNull(obj)) {
|
||||
user = new SysUser();
|
||||
BeanUtils.copyBeanProp(user, obj);
|
||||
}
|
||||
return user;
|
||||
}
|
||||
|
||||
public static void setSysUser(SysUser user)
|
||||
{
|
||||
/**
|
||||
* 设置用户名
|
||||
*
|
||||
* @param user
|
||||
*/
|
||||
public static void setSysUser(SysUser user) {
|
||||
Subject subject = getSubject();
|
||||
//获取当事人的信息
|
||||
PrincipalCollection principalCollection = subject.getPrincipals();
|
||||
String realmName = principalCollection.getRealmNames().iterator().next();
|
||||
PrincipalCollection newPrincipalCollection = new SimplePrincipalCollection(user, realmName);
|
||||
|
|
@ -56,38 +60,55 @@ public class ShiroUtils
|
|||
subject.runAs(newPrincipalCollection);
|
||||
}
|
||||
|
||||
public static void clearCachedAuthorizationInfo()
|
||||
{
|
||||
/***
|
||||
* 清除缓存授权信息
|
||||
*/
|
||||
public static void clearCachedAuthorizationInfo() {
|
||||
RealmSecurityManager rsm = (RealmSecurityManager) SecurityUtils.getSecurityManager();
|
||||
UserRealm realm = (UserRealm) rsm.getRealms().iterator().next();
|
||||
realm.clearCachedAuthorizationInfo();
|
||||
}
|
||||
|
||||
public static Long getUserId()
|
||||
{
|
||||
/**
|
||||
* 获取用户id
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public static Long getUserId() {
|
||||
return getSysUser().getUserId().longValue();
|
||||
}
|
||||
|
||||
public static String getLoginName()
|
||||
{
|
||||
/**
|
||||
* 获取登录名
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public static String getLoginName() {
|
||||
return getSysUser().getLoginName();
|
||||
}
|
||||
|
||||
public static String getIp()
|
||||
{
|
||||
/**
|
||||
* 获取ip
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public static String getIp() {
|
||||
return getSubject().getSession().getHost();
|
||||
}
|
||||
|
||||
public static String getSessionId()
|
||||
{
|
||||
/**
|
||||
* 获取sessionId
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public static String getSessionId() {
|
||||
return String.valueOf(getSubject().getSession().getId());
|
||||
}
|
||||
|
||||
/**
|
||||
* 生成随机盐
|
||||
*/
|
||||
public static String randomSalt()
|
||||
{
|
||||
public static String randomSalt() {
|
||||
// 一个Byte占两个字节,此处生成的3字节,字符串长度为6
|
||||
SecureRandomNumberGenerator secureRandom = new SecureRandomNumberGenerator();
|
||||
String hex = secureRandom.nextBytes(3).toHex();
|
||||
|
|
|
|||
Loading…
Reference in New Issue