com.github.dennisit.vplus.data.interceptor.AppletInterceptor Maven / Gradle / Ivy
/*--------------------------------------------------------------------------
* Copyright (c) 2010-2020, Elon.su All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* Neither the name of the elon developer nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
* Author: Elon.su, you can also mail [email protected]
*--------------------------------------------------------------------------
*/
package com.github.dennisit.vplus.data.interceptor;
import com.github.dennisit.vplus.data.utils.DigestUtils;
import lombok.extern.slf4j.Slf4j;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
/**
* Created by Elon.su on 17/10/6.
*/
@Slf4j
public class AppletInterceptor extends HandlerInterceptorAdapter {
public static final String APP_KEY = DigestUtils.md5Hex("APP_KEY");
public static final String VERSION_KEY = DigestUtils.md5Hex("APP_VERSION");
/**
* 应用标识
*/
private String appKey;
/**
* 应用版本
*/
private String version;
/**
* 应用拦截器
*/
public AppletInterceptor() {
}
public AppletInterceptor(String appKey, String version) {
this.appKey = appKey;
this.version = version;
}
@Override
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
return super.preHandle(request, response, handler);
}
@Override
public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) throws Exception {
HttpSession session = request.getSession(true);
session.setAttribute(AppletInterceptor.APP_KEY, appKey);
session.setAttribute(AppletInterceptor.VERSION_KEY, version);
log.debug("[Applet] [AppKey:{}] [Version:{}]", String.valueOf(session.getAttribute(AppletInterceptor.APP_KEY)), String.valueOf(session.getAttribute(AppletInterceptor.VERSION_KEY)));
}
public void setAppKey(String appKey) {
this.appKey = appKey;
}
public void setVersion(String version) {
this.version = version;
}
}