solr AuthFilter

package com.paic.wcm.search.admin.web.filter;


import java.io.IOException;


import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;


import org.apache.commons.lang.StringUtils;
import org.apache.commons.lang.exception.ExceptionUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.wltea.analyzer.cfg.DefualtConfig;
import org.wltea.analyzer.dic.Dictionary;


import com.paic.wcm.search.admin.core.Config;
import com.paic.wcm.search.admin.service.AuthService;
import com.paic.wcm.search.admin.service.quartz.BackupJob;
import com.paic.wcm.search.client.SimpleIndexClient;
import com.paic.wcm.search.service.QuartzService;
import com.paic.wcm.search.service.quartz.LoadDicJob;


/**
 * 更新索引校验filter
 */
public class AuthFilter implements Filter {


private static final Logger logger = LoggerFactory
.getLogger(AuthFilter.class);


/**
* Default constructor.
*/
public AuthFilter() {
}


/**
* @see Filter#destroy()
*/
public void destroy() {
}


/**
* @see Filter#doFilter(ServletRequest, ServletResponse, FilterChain)
*/
public void doFilter(ServletRequest request, ServletResponse response,
FilterChain chain) throws IOException, ServletException {
HttpServletRequest req = (HttpServletRequest) request;
HttpServletResponse res = (HttpServletResponse) response;


String path = req.getServletPath();


//更新索引的时候校验密砄1�7
if (path.equals("/pingan/update")||path.equals("/update")) {
String password = request.getParameter(SimpleIndexClient.KEY_PA_AUTH);
if (!AuthService.auth(password)) {
((HttpServletResponse) res).sendError(401);
return;
}else{
chain.doFilter(req, res);
return;
}
}

//静态资源不进行权限校验
if(path.contains("static")){
chain.doFilter(req, res);
return;
}

String userName = (String)req.getSession().getAttribute("user");
if(StringUtils.isEmpty(StringUtils.trimToEmpty(userName))){
if(path.contains("/admin")){
if(!(path.contains("login.do") || path.endsWith("login.jsp"))){
String contextPath = req.getContextPath();
res.sendRedirect(contextPath+"/admin/login.jsp");
return;
}
}
}


chain.doFilter(req, res);
}


/**
* @see Filter#init(FilterConfig)
*/
public void init(FilterConfig fConfig) throws ServletException {

// 初始化IK词典
Dictionary.initial(DefualtConfig.getInstance());
LoadDicJob.loadDic();

// 清理备份锁文仄1�7
BackupJob.cleanLockFile();


try {
QuartzService.scheduleJob(BackupJob.class, Config.get()
.getProperty(Config.KEY_CRON_BACKUP), null);
QuartzService.scheduleJob(LoadDicJob.class, Config.get()
.getProperty(Config.KEY_CRON_DIC), null);
} catch (Exception e) {
logger.error("创建定时任务异常");
logger.error(ExceptionUtils.getStackTrace(e));
}


}


}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值