본문 바로가기
Developer/Java

[Java] IP허용체크

by 순수한소년 2020. 8. 18.
728x90
반응형
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
@Override
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {    
    String requestURI = request.getRequestURI(); //요청 URI
    boolean isPermittedURL = false;        
    
    if(requestURI.indexOf("/adm"> -1){    //관리자페이지일때
        String ipChk = request.getRemoteAddr();
        List adminIpList = menuManageService.selectAdminIpList();            
        String temp = "";
        boolean ipcheck = false;
        Map<Object, String> map = new HashMap<Object, String>();        
        try{
            for(int i = 0 ; i < adminIpList.size() ; i++){
                map = (HashMap)adminIpList.get(i);
                temp = map.get("IP").toString();                    
                if(temp.equals(ipChk)){
                    ipcheck = true;
                }                
            }                
        }catch(Exception e){
            e.printStackTrace();
        }    
        
        if(!ipcheck){
            response.sendRedirect("/code404.jsp");
            return false;
        }
    }
}
 
/**
 * 허용IP 조회
 * @param  List
 * @exception Exception
 */
List selectAdminIpList() throws Exception;
 
/**
 * 허용IP 조회
 * @param  List
 * @exception Exception
 */
public List selectAdminIpList() throws Exception {
      return menuManageDAO.selectAdminIpList();
}
 
/**
 * 허용IP 조회
 * @param  List
 * @exception Exception
 */
public List selectAdminIpList() throws Exception {
          return menuManageDAO.selectAdminIpList();
}
 
<select id="menuManageDAO.selectAdminIpList" resultClass="java.util.HashMap">
    <![CDATA[
        select IP from TBPERMIT where use_at = 'Y'
    ]]>
</select>
cs
반응형