1 19 20 package com.sslexplorer.webforwards; 21 22 import java.net.MalformedURLException ; 23 import java.net.URL ; 24 import java.util.Calendar ; 25 import java.util.HashMap ; 26 import java.util.Iterator ; 27 import java.util.Map ; 28 import java.util.StringTokenizer ; 29 import java.util.Vector ; 30 31 import com.sslexplorer.core.CoreEvent; 32 import com.sslexplorer.policyframework.LaunchSession; 33 34 37 public class ReverseProxyWebForward extends AbstractAuthenticatingWebForward { 38 39 private String paths; 40 41 private boolean activeDNS = false; 42 43 private String hostHeader; 44 45 private HashMap customHeaders = new HashMap (); 46 47 private boolean isURLRoot = false; 48 49 private String charset = null; 50 51 public ReverseProxyWebForward(int realmID, int id, int reverseProxyTypeId, 52 String destinationURL, String shortName, String description, 53 String category, 54 String authenticationUsername, 55 String authenticationPassword, String preferredAuthenticationMethod, String formType, String formParameters, 56 String paths, String hostHeader, 57 boolean activeDNS, Calendar dateCreated, Calendar dateAmended, String charset) { 58 super(realmID, id, reverseProxyTypeId, destinationURL, shortName, 59 description, category, 60 authenticationUsername, authenticationPassword, 61 preferredAuthenticationMethod, formType, formParameters, 62 dateCreated, dateAmended); 63 this.paths = paths; 64 this.activeDNS = activeDNS; 65 this.charset = charset; 66 try { 67 URL u = new URL (destinationURL); 68 isURLRoot = u.getPath().equals("") || u.getPath().equals("/"); 69 } catch (MalformedURLException ex) { 70 } 71 72 this.hostHeader = hostHeader; 73 } 74 75 public String getPaths() { 76 return paths; 77 } 78 79 public boolean isURLRoot() { 80 return isURLRoot; 81 } 82 83 public void setPaths(String paths) { 84 this.paths = paths; 85 } 86 87 public boolean containsCustomHeader(String header) { 88 return customHeaders.containsKey(header.toLowerCase()); 89 } 90 91 public void setCustomHeader(String header, String value) { 92 if (!customHeaders.containsKey(header.toLowerCase())) { 93 customHeaders.put(header.toLowerCase(), new Vector ()); 94 } 95 96 Vector v = (Vector ) customHeaders.get(header.toLowerCase()); 97 98 v.add(value); 99 } 100 101 public Map getCustomHeaders() { 102 return customHeaders; 103 } 104 105 public void setActiveDNS(boolean activeDNS) { 106 this.activeDNS = activeDNS; 107 } 108 109 public boolean getActiveDNS() { 110 return activeDNS; 111 } 112 113 public boolean isValidPath(String pathInContext) { 114 StringTokenizer t = new StringTokenizer (paths, "\n"); 115 while (t.hasMoreTokens()) { 116 if (pathInContext.startsWith(t.nextToken())) { 117 return true; 118 } 119 } 120 return false; 121 } 122 123 public String getHostHeader() { 124 return hostHeader; 125 } 126 127 public void setHostHeader(String hostHeader) { 128 this.hostHeader = hostHeader; 129 } 130 131 public void addCustomHeadersToEvent(CoreEvent evt, String key){ 132 int counter = 1; 133 Iterator itr = this.customHeaders.entrySet().iterator(); 134 while (itr.hasNext()) { 135 Map.Entry element = (Map.Entry ) itr.next(); 136 if (!"".equals(element.getKey())){ 137 evt.addAttribute(key+" "+counter, element.toString()); 138 counter++; 139 } 140 } 141 } 142 143 public void addPathsToEvent(CoreEvent evt, String key){ 144 int counter = 1; 145 StringTokenizer t = new StringTokenizer (this.paths, "\n"); 146 while (t.hasMoreElements()) { 147 String element = (String ) t.nextElement(); 148 evt.addAttribute(key+" "+counter, element); 149 counter++; 150 } 151 } 152 153 154 public String getCharset() { 155 return charset; 156 } 157 158 public void setCharset(String charset) { 159 this.charset = charset; 160 } 161 162 public String getLaunchUri(LaunchSession launchSession) { 163 return "launchReverseProxy.do?" + LaunchSession.LAUNCH_ID + "=" + launchSession.getId(); 164 } 165 166 } 167 | Popular Tags |