Java Code Examples for org.jeecg.common.util.SpringContextUtils#getHttpServletRequest()

The following examples show how to use org.jeecg.common.util.SpringContextUtils#getHttpServletRequest() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: JwtUtil.java    From jeecg-cloud with Apache License 2.0 6 votes vote down vote up
/**
 * 根据request中的token获取用户信息
 *
 * @return
 * @throws JeecgBootException
 */
public static LoginUser getLoginUser() throws JeecgBootException {
	HttpServletRequest request = SpringContextUtils.getHttpServletRequest();
	if(request==null){
		log.warn(" 非request方式访问!! ");
		return null;
	}
	String accessToken = request.getHeader("X-Access-Token");
	if(oConvertUtils.isEmpty(accessToken)){
		return null;
	}
	String username = getUsername(accessToken);
	if (oConvertUtils.isEmpty(username)) {
		throw new JeecgBootException("未获取到用户");
	}
	RedisUtil redisUtil = SpringContextUtils.getApplicationContext().getBean(RedisUtil.class);
	LoginUser sysUser = (LoginUser) redisUtil.get(CacheConstant.SYS_USERS_CACHE_JWT +":" +username);
	return sysUser;
}
 
Example 2
Source File: PermissionDataAspect.java    From jeecg-cloud with Apache License 2.0 5 votes vote down vote up
@Around("pointCut()")
public Object arround(ProceedingJoinPoint point) throws  Throwable{
	HttpServletRequest request = SpringContextUtils.getHttpServletRequest();
	MethodSignature signature = (MethodSignature) point.getSignature();
	Method method = signature.getMethod();
	PermissionData pd = method.getAnnotation(PermissionData.class);
	String component = pd.pageComponent();
	authDataHandler(request, component);
	return  point.proceed();
}
 
Example 3
Source File: SysBaseApiImpl.java    From jeecg-boot-with-activiti with MIT License 5 votes vote down vote up
@Override
public void addLog(String LogContent, Integer logType, Integer operatetype) {
	SysLog sysLog = new SysLog();
	//注解上的描述,操作日志内容
	sysLog.setLogContent(LogContent);
	sysLog.setLogType(logType);
	sysLog.setOperateType(operatetype);

	//请求的方法名
	//请求的参数

	try {
		//获取request
		HttpServletRequest request = SpringContextUtils.getHttpServletRequest();
		//设置IP地址
		sysLog.setIp(IPUtils.getIpAddr(request));
	} catch (Exception e) {
		sysLog.setIp("127.0.0.1");
	}

	//获取登录用户信息
	LoginUser sysUser = (LoginUser)SecurityUtils.getSubject().getPrincipal();
	if(sysUser!=null){
		sysLog.setUserid(sysUser.getUsername());
		sysLog.setUsername(sysUser.getRealname());

	}
	sysLog.setCreateTime(new Date());
	//保存系统日志
	sysLogMapper.insert(sysLog);
}
 
Example 4
Source File: SysBaseApiImpl.java    From teaching with Apache License 2.0 5 votes vote down vote up
@Override
public void addLog(String LogContent, Integer logType, Integer operatetype) {
	SysLog sysLog = new SysLog();
	//注解上的描述,操作日志内容
	sysLog.setLogContent(LogContent);
	sysLog.setLogType(logType);
	sysLog.setOperateType(operatetype);

	//请求的方法名
	//请求的参数

	try {
		//获取request
		HttpServletRequest request = SpringContextUtils.getHttpServletRequest();
		//设置IP地址
		sysLog.setIp(IPUtils.getIpAddr(request));
	} catch (Exception e) {
		sysLog.setIp("127.0.0.1");
	}

	//获取登录用户信息
	LoginUser sysUser = (LoginUser)SecurityUtils.getSubject().getPrincipal();
	if(sysUser!=null){
		sysLog.setUserid(sysUser.getUsername());
		sysLog.setUsername(sysUser.getRealname());

	}
	sysLog.setCreateTime(new Date());
	//保存系统日志
	sysLogMapper.insert(sysLog);
}
 
Example 5
Source File: AutoLogAspect.java    From jeecg-cloud with Apache License 2.0 4 votes vote down vote up
private void saveSysLog(ProceedingJoinPoint joinPoint, long time) {
	MethodSignature signature = (MethodSignature) joinPoint.getSignature();
	Method method = signature.getMethod();

	SysLog sysLog = new SysLog();
	AutoLog syslog = method.getAnnotation(AutoLog.class);
	if(syslog != null){
		//注解上的描述,操作日志内容
		sysLog.setLogContent(syslog.value());
		sysLog.setLogType(syslog.logType());

	}

	//请求的方法名
	String className = joinPoint.getTarget().getClass().getName();
	String methodName = signature.getName();
	sysLog.setMethod(className + "." + methodName + "()");


	//设置操作类型
	if (sysLog.getLogType() == CommonConstant.LOG_TYPE_2) {
		sysLog.setOperateType(getOperateType(methodName, syslog.operateType()));
	}

	//获取request
	HttpServletRequest request = SpringContextUtils.getHttpServletRequest();
	//请求的参数
	sysLog.setRequestParam(getReqestParams(request,joinPoint));

	//设置IP地址
	sysLog.setIp(IPUtils.getIpAddr(request));

	//获取登录用户信息
	LoginUser sysUser = (LoginUser)SecurityUtils.getSubject().getPrincipal();
	if(sysUser!=null){
		sysLog.setUserid(sysUser.getUsername());
		sysLog.setUsername(sysUser.getRealname());

	}
	//耗时
	sysLog.setCostTime(time);
	sysLog.setCreateTime(new Date());
	//保存系统日志
	JSONObject jsonObject = (JSONObject) JSONObject.toJSON(sysLog);
	sysBaseRemoteApi.saveSysLog(jsonObject);
}
 
Example 6
Source File: AutoLogAspect.java    From jeecg-boot-with-activiti with MIT License 4 votes vote down vote up
private void saveSysLog(ProceedingJoinPoint joinPoint, long time) {
	MethodSignature signature = (MethodSignature) joinPoint.getSignature();
	Method method = signature.getMethod();

	SysLog sysLog = new SysLog();
	AutoLog syslog = method.getAnnotation(AutoLog.class);
	if(syslog != null){
		//注解上的描述,操作日志内容
		sysLog.setLogContent(syslog.value());
		sysLog.setLogType(syslog.logType());
		
	}

	//请求的方法名
	String className = joinPoint.getTarget().getClass().getName();
	String methodName = signature.getName();
	sysLog.setMethod(className + "." + methodName + "()");
	
	
	//设置操作类型
	if (sysLog.getLogType() == CommonConstant.LOG_TYPE_2) {
		sysLog.setOperateType(getOperateType(methodName, syslog.operateType()));
	}

	//请求的参数
	Object[] args = joinPoint.getArgs();
	try{
		String params = JSONObject.toJSONString(args);
		sysLog.setRequestParam(params);
	}catch (Exception e){

	}

	//获取request
	HttpServletRequest request = SpringContextUtils.getHttpServletRequest();
	//设置IP地址
	sysLog.setIp(IPUtils.getIpAddr(request));

	//获取登录用户信息
	LoginUser sysUser = (LoginUser)SecurityUtils.getSubject().getPrincipal();
	if(sysUser!=null){
		sysLog.setUserid(sysUser.getUsername());
		sysLog.setUsername(sysUser.getRealname());

	}
	//耗时
	sysLog.setCostTime(time);
	sysLog.setCreateTime(new Date());
	//保存系统日志
	sysLogService.save(sysLog);
}
 
Example 7
Source File: AutoLogAspect.java    From teaching with Apache License 2.0 4 votes vote down vote up
private void saveSysLog(ProceedingJoinPoint joinPoint, long time) {
	MethodSignature signature = (MethodSignature) joinPoint.getSignature();
	Method method = signature.getMethod();

	SysLog sysLog = new SysLog();
	AutoLog syslog = method.getAnnotation(AutoLog.class);
	if(syslog != null){
		//注解上的描述,操作日志内容
		sysLog.setLogContent(syslog.value());
		sysLog.setLogType(syslog.logType());
		
	}

	//请求的方法名
	String className = joinPoint.getTarget().getClass().getName();
	String methodName = signature.getName();
	sysLog.setMethod(className + "." + methodName + "()");
	
	
	//设置操作类型
	if (sysLog.getLogType() == CommonConstant.LOG_TYPE_2) {
		sysLog.setOperateType(getOperateType(methodName, syslog.operateType()));
	}

	//请求的参数
	Object[] args = joinPoint.getArgs();
	try{
		String params = JSONObject.toJSONString(args);
		sysLog.setRequestParam(params);
	}catch (Exception e){

	}

	//获取request
	HttpServletRequest request = SpringContextUtils.getHttpServletRequest();
	//设置IP地址
	sysLog.setIp(IPUtils.getIpAddr(request));

	//获取登录用户信息
	LoginUser sysUser = (LoginUser)SecurityUtils.getSubject().getPrincipal();
	if(sysUser!=null){
		sysLog.setUserid(sysUser.getUsername());
		sysLog.setUsername(sysUser.getRealname());

	}
	//耗时
	sysLog.setCostTime(time);
	sysLog.setCreateTime(new Date());
	//保存系统日志
	sysLogService.save(sysLog);
}
 
Example 8
Source File: AutoLogAspect.java    From jeecg-boot with Apache License 2.0 4 votes vote down vote up
private void saveSysLog(ProceedingJoinPoint joinPoint, long time) {
	MethodSignature signature = (MethodSignature) joinPoint.getSignature();
	Method method = signature.getMethod();

	SysLog sysLog = new SysLog();
	AutoLog syslog = method.getAnnotation(AutoLog.class);
	if(syslog != null){
		//注解上的描述,操作日志内容
		sysLog.setLogContent(syslog.value());
		sysLog.setLogType(syslog.logType());
		
	}

	//请求的方法名
	String className = joinPoint.getTarget().getClass().getName();
	String methodName = signature.getName();
	sysLog.setMethod(className + "." + methodName + "()");
	
	
	//设置操作类型
	if (sysLog.getLogType() == CommonConstant.LOG_TYPE_2) {
		sysLog.setOperateType(getOperateType(methodName, syslog.operateType()));
	}

	//获取request
	HttpServletRequest request = SpringContextUtils.getHttpServletRequest();
	//请求的参数
	sysLog.setRequestParam(getReqestParams(request,joinPoint));

	//设置IP地址
	sysLog.setIp(IPUtils.getIpAddr(request));

	//获取登录用户信息
	LoginUser sysUser = (LoginUser)SecurityUtils.getSubject().getPrincipal();
	if(sysUser!=null){
		sysLog.setUserid(sysUser.getUsername());
		sysLog.setUsername(sysUser.getRealname());

	}
	//耗时
	sysLog.setCostTime(time);
	sysLog.setCreateTime(new Date());
	//保存系统日志
	sysLogService.save(sysLog);
}