Search in sources :

Example 1 with RedisUtil

use of com.moxi.mogublog.utils.RedisUtil in project mogu_blog_v2 by moxi624.

the class TokenInterceptor method preHandle.

@Override
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object o) throws Exception {
    StringBuffer requestURL = request.getRequestURL();
    // 得到请求头信息authorization信息
    String authHeader = "";
    if (request.getHeader("Authorization") != null) {
        authHeader = request.getHeader("Authorization");
    } else if (request.getParameter(SysConf.TOKEN) != null) {
        authHeader = request.getParameter(SysConf.TOKEN);
    }
    if (StringUtils.isNotEmpty(authHeader) && authHeader.startsWith("bearer_")) {
        // 获取在线的管理员信息
        RedisUtil redisUtil = SpringUtils.getBean(RedisUtil.class);
        String onlineAdmin = redisUtil.get(RedisConf.LOGIN_TOKEN_KEY + RedisConf.SEGMENTATION + authHeader);
        if (StringUtils.isNotEmpty(onlineAdmin)) {
            // 得到管理员UID和 Name
            OnlineAdmin admin = JsonUtils.jsonToPojo(onlineAdmin, OnlineAdmin.class);
            request.setAttribute(SysConf.ADMIN_UID, admin.getAdminUid());
            request.setAttribute(SysConf.NAME, admin.getUserName());
            request.setAttribute(SysConf.TOKEN, authHeader);
        }
    }
    return true;
}
Also used : RedisUtil(com.moxi.mogublog.utils.RedisUtil) OnlineAdmin(com.moxi.mogublog.commons.entity.OnlineAdmin)

Aggregations

OnlineAdmin (com.moxi.mogublog.commons.entity.OnlineAdmin)1 RedisUtil (com.moxi.mogublog.utils.RedisUtil)1