v1.4.0 GA

上级 9fa72d8a
/**
*
*/
package org.maxkey.cache;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* AbstractCache .
* @author Crystal
* @version 1.0
* @Date 2015/11/12
* @Date 2015/11/12
*/
public abstract class AbstractCache extends Thread {
protected final static Logger _logger = LoggerFactory.getLogger(AbstractCache.class);
private int interval = 30000/1000;
/**
*
*/
public AbstractCache() {
}
public abstract void business();
@Override
public void run() {
while(true){
_logger.debug("Cache Thread Start run "+getName());
_logger.info("Cache Thread Start run "+this.getClass());
try {
business();
_logger.debug("Cache Thread "+getName()+" Finished . ");
_logger.info("Cache Thread "+this.getClass()+" Finished . ");
_logger.debug("Cache Thread sleep "+(interval * 1000)+" minute . ");
sleep(interval * 1000);
} catch (InterruptedException e) {
_logger.error(e.getMessage(), e);
}
}
}
@Override
public void start(){
this.run();
}
/**
* @param name
*/
public AbstractCache(String name) {
super(name);
// TODO Auto-generated constructor stub
}
public int getInterval() {
return interval;
}
public void setInterval(int interval) {
this.interval = interval;
}
public abstract class AbstractCache extends Thread {
protected static final Logger _logger = LoggerFactory.getLogger(AbstractCache.class);
private int interval = 30000 / 1000;
public AbstractCache() {
}
public abstract void business();
@Override
public void run() {
while (true) {
_logger.debug("Cache Thread Start run " + getName());
_logger.info("Cache Thread Start run " + this.getClass());
try {
business();
_logger.debug("Cache Thread " + getName() + " Finished . ");
_logger.info("Cache Thread " + this.getClass() + " Finished . ");
_logger.debug("Cache Thread sleep " + (interval * 1000) + " minute . ");
sleep(interval * 1000);
} catch (InterruptedException e) {
_logger.error(e.getMessage(), e);
}
}
}
@Override
public void start() {
this.run();
}
/**
* constructor.
* @param name String
*/
public AbstractCache(String name) {
super(name);
// TODO Auto-generated constructor stub
}
public int getInterval() {
return interval;
}
public void setInterval(int interval) {
this.interval = interval;
}
}
/**
*
*/
package org.maxkey.cache;
import java.util.ArrayList;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* CacheFactory.
* @author Crystal.Sea
*
*/
public class CacheFactory {
protected final static Logger _logger = LoggerFactory.getLogger(CacheFactory.class);
private ArrayList<AbstractCache> cache;
/**
*
*/
public CacheFactory() {
}
public void start(){
for (AbstractCache cacheable :cache){
_logger.info("Cache "+cacheable.getClass());
new Thread(cacheable).start();
}
}
public ArrayList<AbstractCache> getCache() {
return cache;
}
public void setCache(ArrayList<AbstractCache> cache) {
this.cache = cache;
}
protected static final Logger _logger = LoggerFactory.getLogger(CacheFactory.class);
private ArrayList<AbstractCache> cache;
/**
* CacheFactory.
*/
public CacheFactory() {
}
/**
* start Cache.
*/
public void start() {
for (AbstractCache cacheable : cache) {
_logger.info("Cache " + cacheable.getClass());
new Thread(cacheable).start();
}
}
public ArrayList<AbstractCache> getCache() {
return cache;
}
public void setCache(ArrayList<AbstractCache> cache) {
this.cache = cache;
}
}
package org.maxkey.domain;
import org.apache.mybatis.jpa.persistence.JpaBaseDomain;
public class IpAddrFilter extends JpaBaseDomain {
/**
*
*/
private static final long serialVersionUID = 2308650344165845812L;
public static class FILTER{
public static int WHITELIST=1;
public static int BLACKLIST=2;
}
String id;
private String ipAddr;
private int filter;
private String description;
/**
* @return the id
*/
public String getId() {
return id;
}
/**
* @param id the id to set
*/
public void setId(String id) {
this.id = id;
}
public String getIpAddr() {
return ipAddr;
}
public void setIpAddr(String ipAddr) {
this.ipAddr = ipAddr;
}
public int getFilter() {
return filter;
}
public void setFilter(int filter) {
this.filter = filter;
}
/**
* @return the description
*/
public String getDescription() {
return description;
}
/**
* @param description the description to set
*/
public void setDescription(String description) {
this.description = description;
}
@Override
public String toString() {
return "IpAddrFilter [ipAddr=" + ipAddr + ", filter=" + filter + "]";
}
}
/**
*
*/
package org.maxkey.dao.persistence;
import org.apache.mybatis.jpa.persistence.IJpaBaseMapper;
import org.maxkey.domain.IpAddrFilter;
/**
* @author Crystal.sea
*
*/
public interface IpAddrFilterMapper extends IJpaBaseMapper<IpAddrFilter> {
}
package org.maxkey.dao.service;
import org.apache.mybatis.jpa.persistence.JpaBaseService;
import org.maxkey.dao.persistence.IpAddrFilterMapper;
import org.maxkey.domain.IpAddrFilter;
import org.springframework.stereotype.Service;
@Service
public class IpAddrFilterService extends JpaBaseService<IpAddrFilter>{
public IpAddrFilterService() {
super(IpAddrFilterMapper.class);
}
/* (non-Javadoc)
* @see com.connsec.db.service.BaseService#getMapper()
*/
@Override
public IpAddrFilterMapper getMapper() {
// TODO Auto-generated method stub
return (IpAddrFilterMapper)super.getMapper();
}
}
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="org.maxkey.dao.persistence.IpAddrFilterMapper">
<sql id="where_statement">
<if test="id != null and id != ''">
AND ID = #{id}
</if>
<if test="ipAddr != null and ipAddr != ''">
AND IPADDR LIKE '%${ipAddr}%'
</if>
<if test="filter != null and filter != ''">
AND FILTER = #{filter}
</if>
</sql>
<select id="grid" parameterType="IpAddrFilter" resultType="IpAddrFilter">
SELECT
*
FROM
IPADDRFILTER
WHERE
(1=1)
<include refid="where_statement"/>
</select>
<select id="count" parameterType="IpAddrFilter" resultType="java.lang.Integer">
SELECT
COUNT(*)
FROM
IPADDRFILTER
WHERE
(1=1)
<include refid="where_statement"/>
</select>
</mapper>
\ No newline at end of file
package org.maxkey.web.contorller;
import org.apache.mybatis.jpa.persistence.JpaPageResults;
import org.maxkey.constants.ConstantsOperateMessage;
import org.maxkey.dao.service.IpAddrFilterService;
import org.maxkey.domain.IpAddrFilter;
import org.maxkey.web.WebContext;
import org.maxkey.web.message.Message;
import org.maxkey.web.message.MessageType;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;
@Controller
@RequestMapping(value={"/config/ipaddrfilter"})
public class IpAddrFilterController {
final static Logger _logger = LoggerFactory.getLogger(IpAddrFilterController.class);
@Autowired
@Qualifier("ipAddrFilterService")
IpAddrFilterService ipAddrFilterService;
@RequestMapping(value={"/list"})
public ModelAndView ipAddrFiltersList(){
return new ModelAndView("config/ipaddrfilter/ipaddrfilterList");
}
@RequestMapping(value = { "/grid" })
@ResponseBody
public JpaPageResults<IpAddrFilter> queryDataGrid(@ModelAttribute("ipAddrFilters") IpAddrFilter ipAddrFilters) {
_logger.debug(""+ipAddrFilters);
return ipAddrFilterService.queryPageResults(ipAddrFilters);
}
@RequestMapping(value = { "/forwardAdd" })
public ModelAndView forwardAdd() {
return new ModelAndView("config/ipaddrfilter/ipaddrfilterAdd");
}
@RequestMapping(value = { "/forwardUpdate/{id}" })
public ModelAndView forwardUpdate(@PathVariable("id") String id) {
ModelAndView modelAndView=new ModelAndView("config/ipaddrfilter/ipaddrfilterUpdate");
IpAddrFilter ipAddrFilter=ipAddrFilterService.get(id);
modelAndView.addObject("model",ipAddrFilter);
return modelAndView;
}
@ResponseBody
@RequestMapping(value={"/add"})
public Message insert(@ModelAttribute("ipAddrFilter") IpAddrFilter ipAddrFilter) {
_logger.debug("-Add :" + ipAddrFilter);
if (ipAddrFilterService.insert(ipAddrFilter)) {
return new Message(WebContext.getI18nValue(ConstantsOperateMessage.INSERT_SUCCESS),MessageType.success);
} else {
return new Message(WebContext.getI18nValue(ConstantsOperateMessage.INSERT_SUCCESS),MessageType.error);
}
}
/**
* 查询
* @param ipAddrFilter
* @return
*/
@ResponseBody
@RequestMapping(value={"/query"})
public Message query(@ModelAttribute("ipAddrFilter") IpAddrFilter ipAddrFilter) {
_logger.debug("-query :" + ipAddrFilter);
if (ipAddrFilterService.load(ipAddrFilter)!=null) {
return new Message(WebContext.getI18nValue(ConstantsOperateMessage.INSERT_SUCCESS),MessageType.success);
} else {
return new Message(WebContext.getI18nValue(ConstantsOperateMessage.INSERT_ERROR),MessageType.error);
}
}
/**
* 修改
* @param ipAddrFilter
* @return
*/
@ResponseBody
@RequestMapping(value={"/update"})
public Message update(@ModelAttribute("ipAddrFilter") IpAddrFilter ipAddrFilter) {
_logger.debug("-update ipAddrFilter :" + ipAddrFilter);
if (ipAddrFilterService.update(ipAddrFilter)) {
return new Message(WebContext.getI18nValue(ConstantsOperateMessage.UPDATE_SUCCESS),MessageType.success);
} else {
return new Message(WebContext.getI18nValue(ConstantsOperateMessage.UPDATE_ERROR),MessageType.error);
}
}
@ResponseBody
@RequestMapping(value={"/delete"})
public Message delete(@ModelAttribute("ipAddrFilter") IpAddrFilter ipAddrFilter) {
_logger.debug("-delete ipAddrFilter :" + ipAddrFilter);
if (ipAddrFilterService.delete(ipAddrFilter)) {
return new Message(WebContext.getI18nValue(ConstantsOperateMessage.DELETE_SUCCESS),MessageType.success);
} else {
return new Message(WebContext.getI18nValue(ConstantsOperateMessage.DELETE_SUCCESS),MessageType.error);
}
}
}
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib prefix="spring" uri="http://www.springframework.org/tags" %>
<%@ taglib prefix="s" uri="http://www.connsec.com/tags" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<form id="actionForm" method="post" type="label" autoclose="true" action="<s:Base/>/config/ipaddrfilter/add">
<table border="0" cellpadding="0" cellspacing="0" class="datatable" >
<tbody>
<tr>
<th><s:Locale code="ipaddrfilter.ipAddr" />:</th>
<td nowrap>
<span class="intspan"><input type="text" id="ipAddr" name="ipAddr" class="int required" title="" value=""/></span>
<b class="orange">*</b><label for="ipAddr"></label>
</td>
</tr>
<tr>
<th><s:Locale code="ipaddrfilter.filter" />:</th>
<td nowrap>
<span class="intspan">
<select id="filter" name="filter" >
<option value="1" selected><s:Locale code="ipaddrfilter.filter.whitelist"/></option>
<option value="2" ><s:Locale code="ipaddrfilter.filter.blacklist"/></option>
</select>
</span>
<b class="orange">*</b><label for="filter"></label>
</td>
</tr>
<tr>
<td nowrap colspan="2" class="center">
<input id="_method" type="hidden" name="_method" value="post"/>
<input id="status" type="hidden" name="status" value="1"/>
<input class="button" id="submitBtn" type="button" value="<s:Locale code="button.text.save" />">
<input class="button" id="closeBtn" type="button" value="<s:Locale code="button.text.cancel" />">
</td>
</tr>
</tbody>
</table>
</form>
\ No newline at end of file
<!DOCTYPE HTML>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<#include "../../layout/header.ftl"/>
<#include "../../layout/common.cssjs.ftl"/>
<script type="text/javascript">
function beforeAction() {
$("label[for='maxLength']").html("");
$("label[for='specialChar']").html("");
var minLength = $("#minLength").val();
var maxLength = $("#maxLength").val();
var lowerCase = $("#lowerCase").val();
var upperCase = $("#upperCase").val();
var digits = $("#digits").val();
var specialChar = $("#specialChar").val();
if(parseInt(minLength) > parseInt(maxLength)) {
$("label[for='maxLength']").html("");
return false;
}
if(parseInt(lowerCase)+parseInt(upperCase)+parseInt(digits)+parseInt(specialChar) > parseInt(maxLength)) {
$("label[for='specialChar']").html("");
return false;
}
if(parseInt(lowerCase)+parseInt(upperCase)+parseInt(digits)+parseInt(specialChar) < parseInt(minLength)) {
$("label[for='specialChar']").html("");
return false;
}
return true;
}
</script>
</head>
<body>
<div class="app header-default side-nav-dark">
<div class="layout">
<div class="header navbar">
<#include "../../layout/top.ftl"/>
</div>
<div class="col-md-3 sidebar-nav side-nav" >
<#include "../../layout/sidenav.ftl"/>
</div>
<div class="page-container">
<div class="main-content">
<div class="container-fluid">
<div class="breadcrumb-wrapper row">
<div class="col-12 col-lg-3 col-md-6">
<h4 class="page-title">Dashboard 2</h4>
</div>
<div class="col-12 col-lg-9 col-md-6">
<ol class="breadcrumb float-right">
<li><a href="index.html">Dashboard</a></li>
<li class="active">/ Dashboard 2</li>
</ol>
</div>
</div>
</div>
<div class="col-12 grid-margin">
<div class="card">
<div class="card-header border-bottom">
<h4 class="card-title">Horizontal Two column</h4>
</div>
<div class="card-body">
<form method="post" type="label" validate="true" action="<s:Base/>/config/passwordpolicy/update" id="actionForm" >
<p class="card-description">Personal info</p>
<div class="row">
<div class="col-md-6">
<div class="form-group row">
<label class="col-sm-3 col-form-label"><s:Locale code="passwordpolicy.minlength" /></label>
<div class="col-sm-9">
<input id="id" name="id" type="hidden" value="${model.id}"/>
<input class="form-control" type="text" id="minLength" name="minLength" value="${model.minLength}" />
</div>
</div>
</div>
<div class="col-md-6">
<div class="form-group row">
<label class="col-sm-3 col-form-label"><s:Locale code="passwordpolicy.maxlength" /></label>
<div class="col-sm-9">
<input class="form-control" type="text" id="maxLength" name="maxLength" value="${model.maxLength}" />
</div>
</div>
</div>
</div>
<div class="row">
<div class="col-md-6">
<div class="form-group row">
<label class="col-sm-3 col-form-label"><s:Locale code="passwordpolicy.lowercase" /></label>
<div class="col-sm-9">
<input class="form-control" type="text" id="lowerCase" name="lowerCase" value="${model.lowerCase}" />
</div>
</div>
</div>
<div class="col-md-6">
<div class="form-group row">
<label class="col-sm-3 col-form-label"><s:Locale code="passwordpolicy.uppercase" /></label>
<div class="col-sm-9">
<input class="form-control" type="text" id="upperCase" name="upperCase" value="${model.upperCase}" />
</div>
</div>
</div>
</div>
<div class="row">
<div class="col-md-6">
<div class="form-group row">
<label class="col-sm-3 col-form-label"><s:Locale code="passwordpolicy.digits" /></label>
<div class="col-sm-9">
<input class="form-control" type="text" id="digits" name="digits" value="${model.digits}"/>
</div>
</div>
</div>
<div class="col-md-6">
<div class="form-group row">
<label class="col-sm-3"><s:Locale code="passwordpolicy.specialchar" /></label>
<div class="col-sm-9">
<input class="form-control" type="text" id="specialChar" name="specialChar" value="${model.specialChar}" />
</div>
</div>
</div>
</div>
<div class="row">
<div class="col-md-6">
<div class="form-group row">
<label class="col-sm-3 col-form-label"><s:Locale code="passwordpolicy.attempts" /></label>
<div class="col-sm-9">
<input class="form-control" type="text" id="attempts" name="attempts" value="${model.attempts}" />
</div>
</div>
</div>
<div class="col-md-6">
<div class="form-group row">
<label class="col-sm-3 col-form-label"><s:Locale code="passwordpolicy.duration" />(Unit:Hour):</label>
<div class="col-sm-9">
<input class="form-control" type="text" id="duration" name="duration" value="${model.duration}"/>
</div>
</div>
</div>
</div>
<div class="row">
<div class="col-md-6">
<div class="form-group row">
<label class="col-sm-3 col-form-label"><s:Locale code="passwordpolicy.expiration" />(Unit:Day):</label>
<div class="col-sm-9">
<input class="form-control" type="text" id="expiration" name="expiration" value="${model.expiration}" />
</div>
</div>
</div>
<div class="col-md-6">
<div class="form-group row">
<label class="col-sm-3 col-form-label"><s:Locale code="passwordpolicy.username" /></label>
<div class="col-sm-9">
<select class="form-control" id="username" name="username" >
<option <c:if test="${1==model.username}">selected</c:if> value="1"><s:Locale code="common.text.status.3"/></option>
<option <c:if test="${0==model.username}">selected</c:if> value="0"><s:Locale code="common.text.status.4"/></option>
</select>
</div>
</div>
</div>
</div>
<div class="row">
<div class="col-md-12">
<div class="form-group m-b-20">
<label style="float: left;" for="simplePasswords"><s:Locale code="passwordpolicy.simplepasswords" /></label>
<textarea id="simplePasswords" name="simplePasswords" class="form-control" >${model.simplePasswords}</textarea>
</div>
</div>
</div>
<div class="row">
<div class="col-md-3">
<button type="submit" class="button btn-primary btn btn-common btn-block mr-3" id="submitBtn" ><s:Locale code="button.text.save" /></button>
</div>
</div>
</form>
</div>
</div>
</div>
<footer class="content-footer">
<#include "../../layout/footer.ftl"/>
</footer>
</div>
</div>
</div>
<div id="preloader">
<div class="loader" id="loader-1"></div>
</div>
</body>
</html>
\ No newline at end of file
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib prefix="spring" uri="http://www.springframework.org/tags" %>
<%@ taglib prefix="s" uri="http://www.connsec.com/tags" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<form id="actionForm" method="post" type="label" autoclose="true" action="<s:Base/>/config/ipaddrfilter/update">
<table border="0" cellpadding="0" cellspacing="0" class="datatable">
<tbody>
<tr>
<th><s:Locale code="ipaddrfilter.id" />:</th>
<td nowrap>
<input id="id" type="text" readonly name="id" value="${model.id}"/>
</td>
</tr>
<tr>
<th><s:Locale code="ipaddrfilter.ipAddr" />:</th>
<td nowrap>
<span class="intspan"><input type="text" id="ipAddr" name="ipAddr" class="int required" title="" value="${model.ipAddr}"/></span>
<b class="orange">*</b><label for="ipAddr"></label>
</td>
</tr>
<tr>
<th><s:Locale code="ipaddrfilter.filter" />:</th>
<td nowrap>
<span class="intspan">
<select id="filter" name="filter" >
<option value="1" <c:if test="${1==model.filter}">selected</c:if> ><s:Locale code="ipaddrfilter.filter.whitelist"/></option>
<option value="2" <c:if test="${2==model.filter}">selected</c:if> ><s:Locale code="ipaddrfilter.filter.blacklist"/></option>
</select>
</span>
<b class="orange">*</b><label for="filter"></label>
</td>
</tr>
<tr>
<td nowrap colspan="2" class="center">
<input id="_method" type="hidden" name="_method" value="post"/>
<input id="status" type="hidden" name="status" value="1"/>
<input class="button" id="submitBtn" type="button" value="<s:Locale code="button.text.save" />">
<input class="button" id="closeBtn" type="button" value="<s:Locale code="button.text.cancel" />">
</td>
</tr>
</tbody>
</table>
</form>
\ No newline at end of file
package org.maxkey.web.filter;
import java.io.IOException;
import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import org.maxkey.config.ApplicationConfig;
import org.maxkey.domain.IpAddrFilter;
import org.maxkey.web.WebContext;
import org.maxkey.web.filter.ipaddress.IpAddressCache;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.web.context.support.WebApplicationContextUtils;
public class IpAddressFilter implements Filter {
private static final Logger _logger = LoggerFactory.getLogger(IpAddressFilter.class);
@Autowired
@Qualifier("applicationConfig")
private ApplicationConfig applicationConfig;
boolean whiteList = false;
@Override
public void init(FilterConfig filterConfig) throws ServletException {
// TODO Auto-generated method stub
}
@Override
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
throws IOException, ServletException {
if (applicationConfig == null) {
_logger.info("applicationConfig init .");
applicationConfig = WebApplicationContextUtils.getWebApplicationContext(
request.getServletContext())
.getBean("applicationConfig", ApplicationConfig.class);
}
HttpServletRequest httpServletRequest = (HttpServletRequest) request;
HttpServletResponse httpServletResponse = (HttpServletResponse) response;
HttpSession session = httpServletRequest.getSession();
String ipAddress = WebContext.getRequestIpAddress(httpServletRequest);
_logger.trace("IpAddress " + ipAddress);
// 黑名单地址
if (IpAddressCache.ipAddressBlackListMap.containsKey(ipAddress)) {
IpAddrFilter ipAddrFilter = IpAddressCache.ipAddressBlackListMap.get(ipAddress);
_logger.info("You IpAddress in Black List " + ipAddrFilter);
RequestDispatcher dispatcher = request.getRequestDispatcher("/accessdeny");
dispatcher.forward(request, response);
return;
}
// 白名单地址
if (whiteList && !IpAddressCache.ipAddressWhiteListMap.containsKey(ipAddress)) {
_logger.info("You IpAddress not in White List " + ipAddress);
RequestDispatcher dispatcher = request.getRequestDispatcher("/accessdeny");
dispatcher.forward(request, response);
return;
}
chain.doFilter(request, response);
}
@Override
public void destroy() {
// TODO Auto-generated method stub
}
}
package org.maxkey.web.filter.ipaddress;
import java.util.HashMap;
import java.util.List;
import org.maxkey.cache.AbstractCache;
import org.maxkey.domain.IpAddrFilter;
public class IpAddressCache extends AbstractCache{
JdbcIpAddressService jdbcIpAddressService;
public static HashMap<String,IpAddrFilter> ipAddressBlackListMap=new HashMap<String,IpAddrFilter>();
public static HashMap<String,IpAddrFilter> ipAddressWhiteListMap=new HashMap<String,IpAddrFilter>();
@Override
public void business() {
List<IpAddrFilter> ipAddrFilterList=jdbcIpAddressService.queryAll();
if(ipAddrFilterList!=null){
ipAddressBlackListMap.clear();
ipAddressWhiteListMap.clear();
for(IpAddrFilter ipAddrFilter :ipAddrFilterList){
if(ipAddrFilter.getFilter()==IpAddrFilter.FILTER.BLACKLIST){
ipAddressBlackListMap.put(ipAddrFilter.getIpAddr(), ipAddrFilter);
}else{
ipAddressWhiteListMap.put(ipAddrFilter.getIpAddr(), ipAddrFilter);
}
}
}
}
public void setJdbcIpAddressService(JdbcIpAddressService jdbcIpAddressService) {
this.jdbcIpAddressService = jdbcIpAddressService;
}
}
package org.maxkey.web.filter.ipaddress;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.List;
import org.maxkey.domain.IpAddrFilter;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.RowMapper;
public class JdbcIpAddressService {
private static final Logger _logger = LoggerFactory.getLogger(JdbcIpAddressService.class);
private static final String DEFAULT_ALL_SELECT_STATEMENT = "SELECT ID, IPADDR,FILTER,DESCRIPTION FROM IPADDRFILTER WHERE STATUS = 1";
private static final String DEFAULT_FILTER_SELECT_STATEMENT = "SELECT ID, IPADDR,FILTER,DESCRIPTION FROM IPADDRFILTER WHERE FILTER = ? AND STATUS = 1";
private final JdbcTemplate jdbcTemplate;
public JdbcIpAddressService(JdbcTemplate jdbcTemplate) {
this.jdbcTemplate = jdbcTemplate;
}
public List<IpAddrFilter> queryAll() {
List<IpAddrFilter> listIpAddrFilter=jdbcTemplate.query(DEFAULT_ALL_SELECT_STATEMENT, new RowMapper<IpAddrFilter>() {
public IpAddrFilter mapRow(ResultSet rs, int rowNum) throws SQLException {
IpAddrFilter ipAddrFilter=new IpAddrFilter();
ipAddrFilter.setId(rs.getString(1));
ipAddrFilter.setIpAddr(rs.getString(2));
ipAddrFilter.setFilter(rs.getInt(3));
ipAddrFilter.setDescription(rs.getString(4));
return ipAddrFilter;
}
});
_logger.debug("ListIpAddrFilter "+listIpAddrFilter);
return (listIpAddrFilter.size()>0)?listIpAddrFilter:null;
}
}
/**
*
*/
/**
* @author Crystal.Sea
*
*/
package org.maxkey.web.filter.ipaddress;
\ No newline at end of file
......@@ -111,23 +111,6 @@
<bean id="passwordReciprocal" class="org.maxkey.crypto.password.PasswordReciprocal"></bean>
<bean id="cacheFactory" class="org.maxkey.cache.CacheFactory">
<property name="cache">
<list>
<bean class="org.maxkey.web.filter.ipaddress.IpAddressCache">
<property name="jdbcIpAddressService">
<bean class="org.maxkey.web.filter.ipaddress.JdbcIpAddressService">
<constructor-arg ref="jdbcTemplate"/>
</bean>
</property>
<property name="interval" value="1200" />
</bean>
</list>
</property>
</bean>
<!-- Captcha Producer Config -->
<bean id="captchaProducer" class="com.google.code.kaptcha.impl.DefaultKaptcha">
<property name="config">
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册