KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > ejbca > ui > web > admin > cainterface > EditPublisherJSPHelper


1 /*************************************************************************
2  * *
3  * EJBCA: The OpenSource Certificate Authority *
4  * *
5  * This software is free software; you can redistribute it and/or *
6  * modify it under the terms of the GNU Lesser General Public *
7  * License as published by the Free Software Foundation; either *
8  * version 2.1 of the License, or any later version. *
9  * *
10  * See terms of license at gnu.org. *
11  * *
12  *************************************************************************/

13
14 package org.ejbca.ui.web.admin.cainterface;
15
16 import java.io.UnsupportedEncodingException JavaDoc;
17 import java.util.ArrayList JavaDoc;
18
19 import javax.servlet.http.HttpServletRequest JavaDoc;
20
21 import org.ejbca.core.model.authorization.AuthorizationDeniedException;
22 import org.ejbca.core.model.authorization.AvailableAccessRules;
23 import org.ejbca.core.model.ca.publisher.ActiveDirectoryPublisher;
24 import org.ejbca.core.model.ca.publisher.BasePublisher;
25 import org.ejbca.core.model.ca.publisher.CustomPublisherContainer;
26 import org.ejbca.core.model.ca.publisher.LdapPublisher;
27 import org.ejbca.core.model.ca.publisher.LdapSearchPublisher;
28 import org.ejbca.core.model.ca.publisher.PublisherConnectionException;
29 import org.ejbca.core.model.ca.publisher.PublisherExistsException;
30 import org.ejbca.ui.web.RequestHelper;
31 import org.ejbca.ui.web.admin.configuration.EjbcaWebBean;
32
33
34 /**
35  * Contains help methods used to parse a publisher jsp page requests.
36  *
37  * @author Philip Vendil
38  * @version $Id: EditPublisherJSPHelper.java,v 1.7 2006/12/21 15:10:41 anatom Exp $
39  */

40 public class EditPublisherJSPHelper implements java.io.Serializable JavaDoc {
41
42     /**
43      * Determines if a de-serialized file is compatible with this class.
44      *
45      * Maintainers must change this value if and only if the new version
46      * of this class is not compatible with old versions. See Sun docs
47      * for <a HREF=http://java.sun.com/products/jdk/1.1/docs/guide
48      * /serialization/spec/version.doc.html> details. </a>
49      *
50      */

51     private static final long serialVersionUID = 436830207093078432L;
52     
53     public static final String JavaDoc ACTION = "action";
54     public static final String JavaDoc ACTION_EDIT_PUBLISHERS = "editpublishers";
55     public static final String JavaDoc ACTION_EDIT_PUBLISHER = "editpublisher";
56
57     public static final String JavaDoc ACTION_CHANGE_PUBLISHERTYPE = "changepublishertype";
58
59
60     public static final String JavaDoc CHECKBOX_VALUE = BasePublisher.TRUE;
61
62 // Used in publishers.jsp
63
public static final String JavaDoc BUTTON_EDIT_PUBLISHER = "buttoneditpublisher";
64     public static final String JavaDoc BUTTON_DELETE_PUBLISHER = "buttondeletepublisher";
65     public static final String JavaDoc BUTTON_ADD_PUBLISHER = "buttonaddpublisher";
66     public static final String JavaDoc BUTTON_RENAME_PUBLISHER = "buttonrenamepublisher";
67     public static final String JavaDoc BUTTON_CLONE_PUBLISHER = "buttonclonepublisher";
68
69     public static final String JavaDoc SELECT_PUBLISHER = "selectpublisher";
70     public static final String JavaDoc TEXTFIELD_PUBLISHERNAME = "textfieldpublishername";
71     public static final String JavaDoc HIDDEN_PUBLISHERNAME = "hiddenpublishername";
72
73 // Buttons used in publisher.jsp
74
public static final String JavaDoc BUTTON_TESTCONNECTION = "buttontestconnection";
75     public static final String JavaDoc BUTTON_SAVE = "buttonsave";
76     public static final String JavaDoc BUTTON_CANCEL = "buttoncancel";
77
78     public static final String JavaDoc TYPE_CUSTOM = "typecustom";
79     public static final String JavaDoc TYPE_LDAP = "typeldap";
80     public static final String JavaDoc TYPE_AD = "typead";
81     public static final String JavaDoc TYPE_LDAP_SEARCH = "typeldapsearch";
82
83     public static final String JavaDoc HIDDEN_PUBLISHERTYPE = "hiddenpublishertype";
84     public static final String JavaDoc SELECT_PUBLISHERTYPE = "selectpublishertype";
85
86     public static final String JavaDoc SELECT_APPLICABLECAS = "selectapplicablecas";
87     public static final String JavaDoc TEXTAREA_DESCRIPTION = "textareadescription";
88
89     public static final String JavaDoc TEXTFIELD_CUSTOMCLASSPATH = "textfieldcustomclasspath";
90     public static final String JavaDoc TEXTAREA_CUSTOMPROPERTIES = "textareacustomproperties";
91
92     public static final String JavaDoc TEXTFIELD_LDAPHOSTNAME = "textfieldldaphostname";
93     public static final String JavaDoc TEXTFIELD_LDAPPORT = "textfieldldapport";
94     public static final String JavaDoc TEXTFIELD_LDAPBASEDN = "textfieldldapbasedn";
95     public static final String JavaDoc TEXTFIELD_LDAPLOGINDN = "textfieldldaplogindn";
96     public static final String JavaDoc TEXTFIELD_LDAPUSEROBJECTCLASS = "textfieldldapuserobjectclass";
97     public static final String JavaDoc TEXTFIELD_LDAPCAOBJECTCLASS = "textfieldldapcaobjectclass";
98     public static final String JavaDoc TEXTFIELD_LDAPUSERCERTATTRIBUTE = "textfieldldapusercertattribute";
99     public static final String JavaDoc TEXTFIELD_LDAPCACERTATTRIBUTE = "textfieldldapcacertattribute";
100     public static final String JavaDoc TEXTFIELD_LDAPCRLATTRIBUTE = "textfieldldapcrlattribute";
101     public static final String JavaDoc TEXTFIELD_LDAPARLATTRIBUTE = "textfieldldaparlattribute";
102     public static final String JavaDoc TEXTFIELD_LDAPSEARCHBASEDN = "textfieldldapsearchbasedn";
103     public static final String JavaDoc TEXTFIELD_LDAPSEARCHFILTER = "textfieldldapsearchfilter";
104     public static final String JavaDoc PASSWORD_LDAPLOGINPASSWORD = "textfieldldaploginpassword";
105     public static final String JavaDoc PASSWORD_LDAPCONFIRMLOGINPWD = "textfieldldaploginconfirmpwd";
106     public static final String JavaDoc CHECKBOX_LDAPUSESSL = "checkboxldapusessl";
107     public static final String JavaDoc CHECKBOX_LDAPCREATENONEXISTING = "checkboxldapcreatenonexisting";
108     public static final String JavaDoc CHECKBOX_LDAPMODIFYEXISTING = "checkboxldapmodifyexisting";
109     public static final String JavaDoc CHECKBOX_LDAPADDMULTIPLECERTIFICATES= "checkboxaldapddmultiplecertificates";
110     public static final String JavaDoc CHECKBOX_LDAP_REVOKE_REMOVECERTIFICATE = "checkboxldaprevokeremovecertificate";
111     public static final String JavaDoc CHECKBOX_LDAP_REVOKE_REMOVEUSERONCERTREVOKE = "checkboxldaprevokeuseroncertrevoke";
112     public static final String JavaDoc SELECT_LDAPUSEFIELDINLDAPDN = "selectldapusefieldsinldapdn";
113
114     public static final String JavaDoc CHECKBOX_ADUSEPASSWORD = "checkboxadusepassword";
115     public static final String JavaDoc SELECT_ADUSERACCOUNTCONTROL = "selectaduseraccountcontrol";
116     public static final String JavaDoc SELECT_ADSAMACCOUNTNAME = "selectsamaccountname";
117     public static final String JavaDoc TEXTFIELD_ADUSERDESCRIPTION = "textfieldaduserdescription";
118
119     public static final String JavaDoc PAGE_PUBLISHER = "publisherpage.jspf";
120     public static final String JavaDoc PAGE_PUBLISHERS = "publisherspage.jspf";
121
122     /** Creates new LogInterfaceBean */
123     public EditPublisherJSPHelper(){
124     }
125     // Public methods.
126
/**
127      * Method that initialized the bean.
128      *
129      * @param request is a reference to the http request.
130      */

131     public void initialize(HttpServletRequest JavaDoc request, EjbcaWebBean ejbcawebbean,
132             CAInterfaceBean cabean) throws Exception JavaDoc{
133
134         if(!initialized){
135             this.cabean = cabean;
136             initialized = true;
137             issuperadministrator = false;
138             try{
139                 issuperadministrator = ejbcawebbean.isAuthorizedNoLog(AvailableAccessRules.ROLE_SUPERADMINISTRATOR);
140             }catch(AuthorizationDeniedException ade){}
141         }
142     }
143
144     public String JavaDoc parseRequest(HttpServletRequest JavaDoc request) throws AuthorizationDeniedException{
145         String JavaDoc includefile = PAGE_PUBLISHERS;
146         String JavaDoc publisher = null;
147         PublisherDataHandler handler = cabean.getPublisherDataHandler();
148         String JavaDoc action = null;
149
150         try {
151             RequestHelper.setDefaultCharacterEncoding(request);
152         } catch (UnsupportedEncodingException JavaDoc e1) {
153             // itgnore
154
}
155         action = request.getParameter(ACTION);
156         if( action != null){
157             if( action.equals(ACTION_EDIT_PUBLISHERS)){
158                 if( request.getParameter(BUTTON_EDIT_PUBLISHER) != null){
159                     publisher = request.getParameter(SELECT_PUBLISHER);
160                     if(publisher != null){
161                         if(!publisher.trim().equals("")){
162                             includefile=PAGE_PUBLISHER;
163                             this.publishername = publisher;
164                             this.publisherdata = handler.getPublisher(publishername);
165                         }
166                         else{
167                             publisher= null;
168                         }
169                     }
170                     if(publisher == null){
171                         includefile=PAGE_PUBLISHERS;
172                     }
173                 }
174                 if( request.getParameter(BUTTON_DELETE_PUBLISHER) != null) {
175                     publisher = request.getParameter(SELECT_PUBLISHER);
176                     if(publisher != null){
177                         if(!publisher.trim().equals("")){
178                             publisherdeletefailed = handler.removePublisher(publisher);
179                         }
180                     }
181                     includefile=PAGE_PUBLISHERS;
182                 }
183                 if( request.getParameter(BUTTON_RENAME_PUBLISHER) != null){
184                     // Rename selected publisher and display profilespage.
185
String JavaDoc newpublishername = request.getParameter(TEXTFIELD_PUBLISHERNAME);
186                     String JavaDoc oldpublishername = request.getParameter(SELECT_PUBLISHER);
187                     if(oldpublishername != null && newpublishername != null){
188                         if(!newpublishername.trim().equals("") && !oldpublishername.trim().equals("")){
189                             try{
190                                 handler.renamePublisher(oldpublishername.trim(),newpublishername.trim());
191                             }catch( PublisherExistsException e){
192                                 publisherexists=true;
193                             }
194                         }
195                     }
196                     includefile=PAGE_PUBLISHERS;
197                 }
198                 if( request.getParameter(BUTTON_ADD_PUBLISHER) != null){
199                     publisher = request.getParameter(TEXTFIELD_PUBLISHERNAME);
200                     if(publisher != null){
201                         if(!publisher.trim().equals("")){
202                             try{
203                                 handler.addPublisher(publisher.trim(), new LdapPublisher());
204                             }catch( PublisherExistsException e){
205                                 publisherexists=true;
206                             }
207                         }
208                     }
209                     includefile=PAGE_PUBLISHERS;
210                 }
211                 if( request.getParameter(BUTTON_CLONE_PUBLISHER) != null){
212                     String JavaDoc newpublishername = request.getParameter(TEXTFIELD_PUBLISHERNAME);
213                     String JavaDoc oldpublishername = request.getParameter(SELECT_PUBLISHER);
214                     if(oldpublishername != null && newpublishername != null){
215                         if(!newpublishername.trim().equals("") && !oldpublishername.trim().equals("")){
216                             handler.clonePublisher(oldpublishername.trim(),newpublishername.trim());
217                         }
218                     }
219                     includefile=PAGE_PUBLISHERS;
220                 }
221             }
222             if( action.equals(ACTION_EDIT_PUBLISHER)){
223                 // Display edit access rules page.
224
publisher = request.getParameter(HIDDEN_PUBLISHERNAME);
225                 this.publishername = publisher;
226                 if(publisher != null){
227                     if(!publisher.trim().equals("")){
228                         if(request.getParameter(BUTTON_SAVE) != null ||
229                                 request.getParameter(BUTTON_TESTCONNECTION) != null){
230
231                             if(publisherdata == null){
232                                 int tokentype = new Integer JavaDoc(request.getParameter(HIDDEN_PUBLISHERTYPE)).intValue();
233                                 if(tokentype == CustomPublisherContainer.TYPE_CUSTOMPUBLISHERCONTAINER)
234                                     publisherdata = new CustomPublisherContainer();
235                                 if(tokentype == LdapPublisher.TYPE_LDAPPUBLISHER)
236                                     publisherdata = new LdapPublisher();
237                                 if (tokentype == LdapSearchPublisher.TYPE_LDAPSEARCHPUBLISHER)
238                                     publisherdata = new LdapSearchPublisher();
239                                 if(tokentype == ActiveDirectoryPublisher.TYPE_ADPUBLISHER)
240                                     publisherdata = new ActiveDirectoryPublisher();
241                             }
242                             // Save changes.
243

244                             // General settings
245
String JavaDoc value = request.getParameter(TEXTAREA_DESCRIPTION);
246                             if(value != null){
247                                 value = value.trim();
248                                 publisherdata.setDescription(value);
249                             }
250
251
252                             if(publisherdata instanceof CustomPublisherContainer){
253                                 value = request.getParameter(TEXTFIELD_CUSTOMCLASSPATH);
254                                 if(value != null){
255                                     value = value.trim();
256                                     ((CustomPublisherContainer) publisherdata).setClassPath(value);
257                                 }
258                                 value = request.getParameter(TEXTAREA_CUSTOMPROPERTIES);
259                                 if(value != null){
260                                     value = value.trim();
261                                     ((CustomPublisherContainer) publisherdata).setPropertyData(value);
262                                 }
263                             }
264
265                             if(publisherdata instanceof LdapPublisher){
266                                 LdapPublisher ldappublisher = (LdapPublisher) publisherdata;
267
268                                 value = request.getParameter(TEXTFIELD_LDAPHOSTNAME);
269                                 if(value != null){
270                                     value = value.trim();
271                                     ldappublisher.setHostname(value);
272                                 }
273                                 value = request.getParameter(TEXTFIELD_LDAPPORT);
274                                 if(value != null){
275                                     value = value.trim();
276                                     ldappublisher.setPort(value);
277                                 }
278                                 value = request.getParameter(TEXTFIELD_LDAPBASEDN);
279                                 if(value != null){
280                                     value = value.trim();
281                                     ldappublisher.setBaseDN(value);
282                                 }
283                                 value = request.getParameter(TEXTFIELD_LDAPLOGINDN);
284                                 if(value != null){
285                                     value = value.trim();
286                                     ldappublisher.setLoginDN(value);
287                                 }
288                                 value = request.getParameter(PASSWORD_LDAPLOGINPASSWORD);
289                                 if(value != null){
290                                     value = value.trim();
291                                     ldappublisher.setLoginPassword(value);
292                                 }
293                                 value = request.getParameter(TEXTFIELD_LDAPUSEROBJECTCLASS);
294                                 if(value != null){
295                                     value = value.trim();
296                                     ldappublisher.setUserObjectClass(value);
297                                 }
298                                 value = request.getParameter(TEXTFIELD_LDAPCAOBJECTCLASS);
299                                 if(value != null){
300                                     value = value.trim();
301                                     ldappublisher.setCAObjectClass(value);
302                                 }
303                                 value = request.getParameter(TEXTFIELD_LDAPUSERCERTATTRIBUTE);
304                                 if(value != null){
305                                     value = value.trim();
306                                     ldappublisher.setUserCertAttribute(value);
307                                 }
308                                 value = request.getParameter(TEXTFIELD_LDAPCACERTATTRIBUTE);
309                                 if(value != null){
310                                     value = value.trim();
311                                     ldappublisher.setCACertAttribute(value);
312                                 }
313                                 value = request.getParameter(TEXTFIELD_LDAPCRLATTRIBUTE);
314                                 if(value != null){
315                                     value = value.trim();
316                                     ldappublisher.setCRLAttribute(value);
317                                 }
318                                 value = request.getParameter(TEXTFIELD_LDAPARLATTRIBUTE);
319                                 if(value != null){
320                                     value = value.trim();
321                                     ldappublisher.setARLAttribute(value);
322                                 }
323                                 value = request.getParameter(CHECKBOX_LDAPUSESSL);
324                                 if(value != null)
325                                     ldappublisher.setUseSSL(value.equals(CHECKBOX_VALUE));
326                                 else
327                                     ldappublisher.setUseSSL(false);
328
329                                 value = request.getParameter(CHECKBOX_LDAPCREATENONEXISTING);
330                                 if(value != null)
331                                     ldappublisher.setCreateNonExisingUsers(value.equals(CHECKBOX_VALUE));
332                                 else
333                                     ldappublisher.setCreateNonExisingUsers(false);
334
335                                 value = request.getParameter(CHECKBOX_LDAPMODIFYEXISTING);
336                                 if(value != null)
337                                     ldappublisher.setModifyExistingUsers(value.equals(CHECKBOX_VALUE));
338                                 else
339                                     ldappublisher.setModifyExistingUsers(false);
340
341                                 value = request.getParameter(CHECKBOX_LDAPADDMULTIPLECERTIFICATES);
342                                 if(value != null)
343                                     ldappublisher.setAddMultipleCertificates(value.equals(CHECKBOX_VALUE));
344                                 else
345                                     ldappublisher.setAddMultipleCertificates(false);
346
347                                 value = request.getParameter(CHECKBOX_LDAP_REVOKE_REMOVECERTIFICATE);
348                                 if(value != null)
349                                     ldappublisher.setRemoveRevokedCertificates(value.equals(CHECKBOX_VALUE));
350                                 else
351                                     ldappublisher.setRemoveRevokedCertificates(false);
352
353                                 value = request.getParameter(CHECKBOX_LDAP_REVOKE_REMOVEUSERONCERTREVOKE);
354                                 if(value != null)
355                                     ldappublisher.setRemoveUsersWhenCertRevoked(value.equals(CHECKBOX_VALUE));
356                                 else
357                                     ldappublisher.setRemoveUsersWhenCertRevoked(false);
358
359                                 String JavaDoc[] values = request.getParameterValues(SELECT_LDAPUSEFIELDINLDAPDN);
360                                 if(values != null){
361                                     ArrayList JavaDoc usefields = new ArrayList JavaDoc();
362                                     for(int i=0;i< values.length;i++){
363                                         usefields.add(new Integer JavaDoc(values[i]));
364                                     }
365
366                                     ldappublisher.setUseFieldInLdapDN(usefields);
367                                 }
368                             }
369
370
371                             if (publisherdata instanceof LdapSearchPublisher) {
372                               LdapSearchPublisher ldapsearchpublisher = (LdapSearchPublisher) publisherdata;
373
374                               value = request.getParameter(TEXTFIELD_LDAPSEARCHBASEDN);
375                               if (value != null) {
376                                 value = value.trim();
377                                 ldapsearchpublisher.setSearchBaseDN(value);
378                               }
379                               value = request.getParameter(TEXTFIELD_LDAPSEARCHFILTER);
380                               if (value != null) {
381                                 value = value.trim();
382                                 ldapsearchpublisher.setSearchFilter(value);
383                               }
384                             }
385
386
387                             if(publisherdata instanceof ActiveDirectoryPublisher){
388                                 ActiveDirectoryPublisher adpublisher = (ActiveDirectoryPublisher) publisherdata;
389
390                                 value = request.getParameter(SELECT_ADSAMACCOUNTNAME);
391                                 if(value != null){
392                                     value = value.trim();
393                                     adpublisher.setSAMAccountName(Integer.parseInt(value));
394                                 }
395
396                                 value = request.getParameter(TEXTFIELD_ADUSERDESCRIPTION);
397                                 if(value != null){
398                                     value = value.trim();
399                                     adpublisher.setUserDescription(value);
400                                 }
401
402                                 value = request.getParameter(CHECKBOX_ADUSEPASSWORD);
403                                 if(value != null)
404                                     adpublisher.setUseUserPassword(value.equals(CHECKBOX_VALUE));
405                                 else
406                                     adpublisher.setUseUserPassword(false);
407
408                                 value = request.getParameter(SELECT_ADUSERACCOUNTCONTROL);
409                                 if(value != null){
410                                     value = value.trim();
411                                     adpublisher.setUserAccountControl(Integer.parseInt(value));
412                                 }
413                             }
414
415
416                             if(request.getParameter(BUTTON_SAVE) != null){
417                                 handler.changePublisher(publisher,publisherdata);
418                                 includefile=PAGE_PUBLISHERS;
419                             }
420                             if(request.getParameter(BUTTON_TESTCONNECTION)!= null){
421                                 connectionmessage = true;
422                                 handler.changePublisher(publisher,publisherdata);
423                                 try{
424                                     handler.testConnection(publisher);
425                                     connectionsuccessful = true;
426                                 }catch(PublisherConnectionException pce){
427                                     connectionerrormessage = pce.getMessage();
428                                 }
429                                 includefile=PAGE_PUBLISHER;
430                             }
431
432                         }
433                         if(request.getParameter(BUTTON_CANCEL) != null){
434                             // Don't save changes.
435
includefile=PAGE_PUBLISHERS;
436                         }
437
438                     }
439                 }
440             }
441
442             if( action.equals(ACTION_CHANGE_PUBLISHERTYPE)){
443                 this.publishername = request.getParameter(HIDDEN_PUBLISHERNAME);
444                 String JavaDoc value = request.getParameter(SELECT_PUBLISHERTYPE);
445                 if(value!=null){
446                     int profiletype = Integer.parseInt(value);
447                     switch(profiletype){
448                     case CustomPublisherContainer.TYPE_CUSTOMPUBLISHERCONTAINER :
449                         publisherdata = new CustomPublisherContainer();
450                         break;
451                     case LdapPublisher.TYPE_LDAPPUBLISHER :
452                         publisherdata = new LdapPublisher();
453                         break;
454                     case LdapSearchPublisher.TYPE_LDAPSEARCHPUBLISHER:
455                         publisherdata = new LdapSearchPublisher();
456                         break;
457                     case ActiveDirectoryPublisher.TYPE_ADPUBLISHER :
458                         publisherdata = new ActiveDirectoryPublisher();
459                         break;
460                     }
461                 }
462
463                 includefile=PAGE_PUBLISHER;
464             }
465         }
466
467         return includefile;
468     }
469
470     public int getPublisherType(){
471         int retval = CustomPublisherContainer.TYPE_CUSTOMPUBLISHERCONTAINER;
472
473         if(publisherdata instanceof CustomPublisherContainer)
474             retval = CustomPublisherContainer.TYPE_CUSTOMPUBLISHERCONTAINER;
475
476         if(publisherdata instanceof LdapPublisher)
477             retval = LdapPublisher.TYPE_LDAPPUBLISHER;
478
479         if (publisherdata instanceof LdapSearchPublisher)
480             retval = LdapSearchPublisher.TYPE_LDAPSEARCHPUBLISHER;
481
482         if(publisherdata instanceof ActiveDirectoryPublisher)
483             retval = ActiveDirectoryPublisher.TYPE_ADPUBLISHER;
484
485         return retval;
486     }
487
488
489     // Private fields.
490
private CAInterfaceBean cabean;
491     private boolean initialized=false;
492     public boolean publisherexists = false;
493     public boolean publisherdeletefailed = false;
494     public boolean connectionmessage = false;
495     public boolean connectionsuccessful = false;
496     public String JavaDoc connectionerrormessage = "";
497     public boolean issuperadministrator = false;
498     public BasePublisher publisherdata = null;
499     public String JavaDoc publishername = null;
500
501
502 }
503
Popular Tags