com.centit.framework.security.HostIpSecurityMetadataSource Maven / Gradle / Ivy
package com.centit.framework.security;
import com.centit.support.file.PropertiesReader;
import org.springframework.security.access.ConfigAttribute;
import org.springframework.security.access.SecurityConfig;
import org.springframework.security.web.FilterInvocation;
import org.springframework.security.web.access.intercept.FilterInvocationSecurityMetadataSource;
import javax.servlet.http.HttpServletRequest;
import java.util.*;
//@Component("hostIpSecurityMetadataSource")
public class HostIpSecurityMetadataSource
implements FilterInvocationSecurityMetadataSource
{
public static final String LOCAL_HOST_IP="127.0.0.1";
//private static final Logger logger = LoggerFactory.getLogger(DaoInvocationSecurityMetadataSource.class);
//private static boolean logDebug = logger.isDebugEnabled();
private String appHome;
public void setAppHome(String appHome) {
this.appHome = appHome;
}
private Map> hostIpAttributes=null;
@Override
public boolean supports(Class> clazz) {
if (FilterInvocation.class.isAssignableFrom(clazz)) {
return true;
}
return false;
}
@Override
public Collection getAllConfigAttributes() {
return null;
}
public Collection getHostConfigAttributes(String urlIp) {
if(hostIpAttributes==null){
//放到数据字典的httpserver的字典中
loadConfigAttributes();
}
return hostIpAttributes.get(urlIp);
}
private void loadConfigAttributes(){
if(hostIpAttributes!=null)
hostIpAttributes.clear();
else
hostIpAttributes = new HashMap<>();
Properties hosts = PropertiesReader.getFilePathProperties(
appHome +"/config/host_white_list.properties");
if(hosts!=null){
Set> hostset = hosts.entrySet();
if(hostset!=null){
for(Map.Entry