KickJava   Java API By Example, From Geeks To Geeks.

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


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.util.Calendar JavaDoc;
23 import java.util.StringTokenizer JavaDoc;
24
25 import com.sslexplorer.core.CoreEvent;
26
27
28 /**
29  *
30  */

31 public abstract class AbstractAuthenticatingWebForward extends AbstractWebForward {
32
33     private String JavaDoc authenticationUsername;
34     private String JavaDoc authenticationPassword;
35     private String JavaDoc preferredAuthenticationScheme;
36     private String JavaDoc formType = WebForwardTypes.FORM_SUBMIT_NONE;
37     private String JavaDoc formParameters = "";
38
39     public AbstractAuthenticatingWebForward(int realmID, int id, int type, String JavaDoc destinationURL, String JavaDoc shortName, String JavaDoc description,
40                                             String JavaDoc category, String JavaDoc authenticationUsername,
41                                             String JavaDoc authenticationPassword, String JavaDoc preferredAuthenticationScheme,
42                                             String JavaDoc formType, String JavaDoc formParameters, Calendar JavaDoc dateCreated, Calendar JavaDoc dateAmended) {
43         super(realmID, id, type, destinationURL, shortName, description, category, dateCreated, dateAmended);
44         this.authenticationUsername = authenticationUsername;
45         this.authenticationPassword = authenticationPassword;
46         this.preferredAuthenticationScheme = preferredAuthenticationScheme;
47         this.formParameters = formParameters;
48         this.formType = formType;
49     }
50
51     /**
52      * Get the username to use for authentication with this resource if HTTP
53      * authentication is encountered.
54      *
55      * @return username
56      */

57     public String JavaDoc getAuthenticationUsername() {
58         return authenticationUsername;
59     }
60
61     /**
62      * Set the username to use for authentication with this resource if HTTP
63      * authentication is encountered.
64      *
65      * @return authentication password
66      */

67     public String JavaDoc getAuthenticationPassword() {
68         return authenticationPassword;
69     }
70
71     /**
72      * Get the preferred authentication scheme. This will be one of
73      * {@link com.maverick.http.HttpAuthenticatorFactory#BASIC},
74      * {@link com.maverick.http.HttpAuthenticatorFactory#DIGEST} or
75      * {@link com.maverick.http.HttpAuthenticatorFactory#NTLM}.
76      *
77      *
78      * @return preferred authentication scheme
79      */

80     public String JavaDoc getPreferredAuthenticationScheme() {
81         return preferredAuthenticationScheme;
82     }
83
84     /**
85      * Set the username to use for authentication with this resource if HTTP
86      * authentication is encountered.
87      *
88      * @param authenticationUsername authentication username
89      */

90     public void setAuthenticationUsername(String JavaDoc authenticationUsername) {
91         this.authenticationUsername = authenticationUsername;
92     }
93
94     /**
95      * Set the username to use for authentication with this resource if HTTP
96      * authentication is encountered.
97      *
98      * @return authenticationPassword
99      */

100     public void setAuthenticationPassword(String JavaDoc authenticationPassword) {
101         this.authenticationPassword = authenticationPassword;
102     }
103
104     /**
105      * Set the preferred authentication scheme. This will be one of
106      * {@link com.maverick.http.HttpAuthenticatorFactory#BASIC},
107      * {@link com.maverick.http.HttpAuthenticatorFactory#DIGEST} or
108      * {@link com.maverick.http.HttpAuthenticatorFactory#NTLM}.
109      *
110      * @param preferredAuthenticationScheme preferred authentication scheme
111      */

112     public void setPreferredAuthenticationScheme(String JavaDoc preferredAuthenticationScheme) {
113         this.preferredAuthenticationScheme = preferredAuthenticationScheme;
114     }
115     
116     /**
117      * @return The form type
118      */

119     public String JavaDoc getFormType() {
120         return formType;
121     }
122
123     /**
124      * @return The form parameters
125      */

126     public String JavaDoc getFormParameters() {
127         return formParameters;
128     }
129
130     /**
131      * @param formType
132      */

133     public void setFormType(String JavaDoc formType) {
134         this.formType = formType;
135     }
136
137     /**
138      * @param formType
139      */

140     public void setFormParameters(String JavaDoc formParameters) {
141         this.formParameters = formParameters;
142     }
143
144     public boolean paramsRequirePassword() {
145         if (!super.paramsRequirePassword()){
146             if (authenticationPassword.contains("${session:password}") | formParameters.contains("${session:password}")){
147                 return true;
148             }
149             else{
150                 return false;
151             }
152         }
153         else{
154             return false;
155         }
156     }
157     
158     public void addFormParametersToEvent(CoreEvent evt, String JavaDoc key){
159         int counter = 1;
160         StringTokenizer JavaDoc t = new StringTokenizer JavaDoc(this.formParameters, "\n");
161         while (t.hasMoreElements()) {
162             String JavaDoc element = (String JavaDoc) t.nextElement();
163             evt.addAttribute(key+" "+counter, element);
164             counter++;
165         }
166     }
167
168
169 }
170
Popular Tags