org.jeecg.common.system.api.ISysBaseAPI Java Examples

The following examples show how to use org.jeecg.common.system.api.ISysBaseAPI. 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: TokenUtils.java    From jeecg-boot-with-activiti with MIT License 6 votes vote down vote up
/**
 * 验证Token
 */
public static boolean verifyToken(HttpServletRequest request, ISysBaseAPI sysBaseAPI, RedisUtil redisUtil) {
    String token = request.getParameter("token");

    // 解密获得username,用于和数据库进行对比
    String username = JwtUtil.getUsername(token);
    if (username == null) {
        throw new AuthenticationException("token非法无效!");
    }

    // 查询用户信息
    LoginUser user = sysBaseAPI.getUserByName(username);
    if (user == null) {
        throw new AuthenticationException("用户不存在!");
    }
    // 判断用户状态
    if (user.getStatus() != 1) {
        throw new AuthenticationException("账号已被锁定,请联系管理员!");
    }
    // 校验token是否超时失效 & 或者账号密码是否错误
    if (!jwtTokenRefresh(token, username, user.getPassword(), redisUtil)) {
        throw new AuthenticationException("Token失效,请重新登录!");
    }
    return true;
}
 
Example #2
Source File: TokenUtils.java    From jeecg-cloud with Apache License 2.0 5 votes vote down vote up
/**
 * 验证Token
 */
public static boolean verifyToken(HttpServletRequest request, ISysBaseAPI sysBaseAPI, RedisUtil redisUtil) {
    log.info(" -- url --" + request.getRequestURL());
    String token = getTokenByRequest(request);

    if (StringUtils.isBlank(token)) {
        throw new AuthenticationException("token不能为空!");
    }

    // 解密获得username,用于和数据库进行对比
    String username = JwtUtil.getUsername(token);
    if (username == null) {
        throw new AuthenticationException("token非法无效!");
    }

    // 查询用户信息
    LoginUser user = sysBaseAPI.getUserByName(username);
    if (user == null) {
        throw new AuthenticationException("用户不存在!");
    }
    // 判断用户状态
    if (user.getStatus() != 1) {
        throw new AuthenticationException("账号已被锁定,请联系管理员!");
    }
    // 校验token是否超时失效 & 或者账号密码是否错误
    if (!jwtTokenRefresh(token, username, user.getPassword(), redisUtil)) {
        throw new AuthenticationException("Token失效,请重新登录!");
    }
    return true;
}
 
Example #3
Source File: DataSourceCachePool.java    From jeecg-cloud with Apache License 2.0 5 votes vote down vote up
/**
 * 获取多数据源缓存
 *
 * @param dbKey
 * @return
 */
public static DynamicDataSourceModel getCacheDynamicDataSourceModel(String dbKey) {
    String redisCacheKey = CacheConstant.SYS_DYNAMICDB_CACHE + dbKey;
    if (getRedisTemplate().hasKey(redisCacheKey)) {
        return (DynamicDataSourceModel) getRedisTemplate().opsForValue().get(redisCacheKey);
    }
    ISysBaseAPI sysBaseAPI = SpringContextUtils.getBean(ISysBaseAPI.class);
    DynamicDataSourceModel dbSource = sysBaseAPI.getDynamicDbSourceByCode(dbKey);
    if (dbSource != null) {
        getRedisTemplate().opsForValue().set(redisCacheKey, dbSource);
    }
    return dbSource;
}
 
Example #4
Source File: TokenUtils.java    From teaching with Apache License 2.0 5 votes vote down vote up
/**
 * 验证Token
 */
public static boolean verifyToken(HttpServletRequest request, ISysBaseAPI sysBaseAPI, RedisUtil redisUtil) {
    log.info(" -- url --" + request.getRequestURL());
    String token = getTokenByRequest(request);

    if (StringUtils.isBlank(token)) {
        throw new AuthenticationException("token不能为空!");
    }

    // 解密获得username,用于和数据库进行对比
    String username = JwtUtil.getUsername(token);
    if (username == null) {
        throw new AuthenticationException("token非法无效!");
    }

    // 查询用户信息
    LoginUser user = sysBaseAPI.getUserByName(username);
    if (user == null) {
        throw new AuthenticationException("用户不存在!");
    }
    // 判断用户状态
    if (user.getStatus() != 1) {
        throw new AuthenticationException("账号已被锁定,请联系管理员!");
    }
    // 校验token是否超时失效 & 或者账号密码是否错误
    if (!jwtTokenRefresh(token, username, user.getPassword(), redisUtil)) {
        throw new AuthenticationException("Token失效,请重新登录!");
    }
    return true;
}
 
Example #5
Source File: DataSourceCachePool.java    From teaching with Apache License 2.0 5 votes vote down vote up
/**
 * 获取多数据源缓存
 *
 * @param dbKey
 * @return
 */
public static DynamicDataSourceModel getCacheDynamicDataSourceModel(String dbKey) {
    DynamicDataSourceModel dbSource = dynamicDbSourcesCache.get(dbKey);
    if (dbSource == null) {
        ISysBaseAPI sysBaseAPI = SpringContextUtils.getBean(ISysBaseAPI.class);
        dbSource = sysBaseAPI.getDynamicDbSourceByCode(dbKey);
        dynamicDbSourcesCache.put(dbKey, dbSource);
        dynamicDbSourcesIdToCode.put(dbSource.getId(), dbKey);
    }
    return dbSource;
}
 
Example #6
Source File: QueryGenerator.java    From teaching with Apache License 2.0 5 votes vote down vote up
/**
 * 获取系统数据库类型
 */
private static String getDbType(){
	if(oConvertUtils.isNotEmpty(DB_TYPE)){
		return DB_TYPE;
	}
	try {
		ISysBaseAPI sysBaseAPI = ApplicationContextUtil.getContext().getBean(ISysBaseAPI.class);
		DB_TYPE = sysBaseAPI.getDatabaseType();
		return DB_TYPE;
	} catch (Exception e) {
		e.printStackTrace();
	}
	return DB_TYPE;
}
 
Example #7
Source File: TokenUtils.java    From jeecg-boot with Apache License 2.0 5 votes vote down vote up
/**
 * 验证Token
 */
public static boolean verifyToken(HttpServletRequest request, ISysBaseAPI sysBaseAPI, RedisUtil redisUtil) {
    log.info(" -- url --" + request.getRequestURL());
    String token = getTokenByRequest(request);

    if (StringUtils.isBlank(token)) {
        throw new AuthenticationException("token不能为空!");
    }

    // 解密获得username,用于和数据库进行对比
    String username = JwtUtil.getUsername(token);
    if (username == null) {
        throw new AuthenticationException("token非法无效!");
    }

    // 查询用户信息
    LoginUser user = sysBaseAPI.getUserByName(username);
    if (user == null) {
        throw new AuthenticationException("用户不存在!");
    }
    // 判断用户状态
    if (user.getStatus() != 1) {
        throw new AuthenticationException("账号已被锁定,请联系管理员!");
    }
    // 校验token是否超时失效 & 或者账号密码是否错误
    if (!jwtTokenRefresh(token, username, user.getPassword(), redisUtil)) {
        throw new AuthenticationException("Token失效,请重新登录!");
    }
    return true;
}
 
Example #8
Source File: DataSourceCachePool.java    From jeecg-boot with Apache License 2.0 5 votes vote down vote up
/**
 * 获取多数据源缓存
 *
 * @param dbKey
 * @return
 */
public static DynamicDataSourceModel getCacheDynamicDataSourceModel(String dbKey) {
    String redisCacheKey = CacheConstant.SYS_DYNAMICDB_CACHE + dbKey;
    if (getRedisTemplate().hasKey(redisCacheKey)) {
        return (DynamicDataSourceModel) getRedisTemplate().opsForValue().get(redisCacheKey);
    }
    ISysBaseAPI sysBaseAPI = SpringContextUtils.getBean(ISysBaseAPI.class);
    DynamicDataSourceModel dbSource = sysBaseAPI.getDynamicDbSourceByCode(dbKey);
    if (dbSource != null) {
        getRedisTemplate().opsForValue().set(redisCacheKey, dbSource);
    }
    return dbSource;
}
 
Example #9
Source File: QueryGenerator.java    From jeecg-boot with Apache License 2.0 5 votes vote down vote up
/**
 * 获取系统数据库类型
 */
private static String getDbType(){
	if(oConvertUtils.isNotEmpty(DB_TYPE)){
		return DB_TYPE;
	}
	try {
		ISysBaseAPI sysBaseAPI = ApplicationContextUtil.getContext().getBean(ISysBaseAPI.class);
		DB_TYPE = sysBaseAPI.getDatabaseType();
		return DB_TYPE;
	} catch (Exception e) {
		e.printStackTrace();
	}
	return DB_TYPE;
}