KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sslexplorer > webforwards > ReverseProxyWebForward


1 /*
2  * SSL-Explorer
3  *
4  * Copyright (C) 2003-2006 3SP LTD. All Rights Reserved
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * as published by the Free Software Foundation; either version 2 of
9  * the License, or (at your option) any later version.
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public
16  * License along with this program; if not, write to the Free Software
17  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18  */

19             
20 package com.sslexplorer.webforwards;
21
22 import java.net.MalformedURLException JavaDoc;
23 import java.net.URL JavaDoc;
24 import java.util.Calendar JavaDoc;
25 import java.util.HashMap JavaDoc;
26 import java.util.Iterator JavaDoc;
27 import java.util.Map JavaDoc;
28 import java.util.StringTokenizer JavaDoc;
29 import java.util.Vector JavaDoc;
30
31 import com.sslexplorer.core.CoreEvent;
32 import com.sslexplorer.policyframework.LaunchSession;
33
34 /**
35  *
36  */

37 public class ReverseProxyWebForward extends AbstractAuthenticatingWebForward {
38
39     private String JavaDoc paths;
40
41     private boolean activeDNS = false;
42
43     private String JavaDoc hostHeader;
44
45     private HashMap JavaDoc customHeaders = new HashMap JavaDoc();
46
47     private boolean isURLRoot = false;
48
49     private String JavaDoc charset = null;
50     
51     public ReverseProxyWebForward(int realmID, int id, int reverseProxyTypeId,
52             String JavaDoc destinationURL, String JavaDoc shortName, String JavaDoc description,
53             String JavaDoc category,
54             String JavaDoc authenticationUsername,
55             String JavaDoc authenticationPassword, String JavaDoc preferredAuthenticationMethod, String JavaDoc formType, String JavaDoc formParameters,
56             String JavaDoc paths, String JavaDoc hostHeader,
57             boolean activeDNS, Calendar JavaDoc dateCreated, Calendar JavaDoc dateAmended, String JavaDoc 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 JavaDoc u = new URL JavaDoc(destinationURL);
68             isURLRoot = u.getPath().equals("") || u.getPath().equals("/");
69         } catch (MalformedURLException JavaDoc ex) {
70         }
71
72         this.hostHeader = hostHeader;
73     }
74
75     public String JavaDoc getPaths() {
76         return paths;
77     }
78
79     public boolean isURLRoot() {
80         return isURLRoot;
81     }
82
83     public void setPaths(String JavaDoc paths) {
84         this.paths = paths;
85     }
86
87     public boolean containsCustomHeader(String JavaDoc header) {
88         return customHeaders.containsKey(header.toLowerCase());
89     }
90
91     public void setCustomHeader(String JavaDoc header, String JavaDoc value) {
92         if (!customHeaders.containsKey(header.toLowerCase())) {
93             customHeaders.put(header.toLowerCase(), new Vector JavaDoc());
94         }
95
96         Vector JavaDoc v = (Vector JavaDoc) customHeaders.get(header.toLowerCase());
97
98         v.add(value);
99     }
100
101     public Map JavaDoc 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 JavaDoc pathInContext) {
114         StringTokenizer JavaDoc t = new StringTokenizer JavaDoc(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 JavaDoc getHostHeader() {
124         return hostHeader;
125     }
126
127     public void setHostHeader(String JavaDoc hostHeader) {
128         this.hostHeader = hostHeader;
129     }
130     
131     public void addCustomHeadersToEvent(CoreEvent evt, String JavaDoc key){
132         int counter = 1;
133         Iterator JavaDoc itr = this.customHeaders.entrySet().iterator();
134         while (itr.hasNext()) {
135             Map.Entry JavaDoc element = (Map.Entry JavaDoc) 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 JavaDoc key){
144         int counter = 1;
145         StringTokenizer JavaDoc t = new StringTokenizer JavaDoc(this.paths, "\n");
146         while (t.hasMoreElements()) {
147             String JavaDoc element = (String JavaDoc) t.nextElement();
148             evt.addAttribute(key+" "+counter, element);
149             counter++;
150         }
151     }
152     
153     
154     public String JavaDoc getCharset() {
155         return charset;
156     }
157     
158     public void setCharset(String JavaDoc charset) {
159         this.charset = charset;
160     }
161
162     public String JavaDoc getLaunchUri(LaunchSession launchSession) {
163         return "launchReverseProxy.do?" + LaunchSession.LAUNCH_ID + "=" + launchSession.getId();
164     }
165
166 }
167
Popular Tags