1 13 14 package org.ejbca.ui.web.admin.rainterface; 15 16 import java.io.UnsupportedEncodingException ; 17 import java.util.ArrayList ; 18 import java.util.Collection ; 19 import java.util.HashSet ; 20 import java.util.Iterator ; 21 import java.util.Set ; 22 import java.util.TreeMap ; 23 24 import javax.servlet.http.HttpServletRequest ; 25 26 import org.ejbca.core.ejb.ra.userdatasource.IUserDataSourceSessionLocal; 27 import org.ejbca.core.model.authorization.AuthorizationDeniedException; 28 import org.ejbca.core.model.authorization.AvailableAccessRules; 29 import org.ejbca.core.model.log.Admin; 30 import org.ejbca.core.model.ra.userdatasource.BaseUserDataSource; 31 import org.ejbca.core.model.ra.userdatasource.CustomUserDataSourceContainer; 32 import org.ejbca.core.model.ra.userdatasource.UserDataSourceConnectionException; 33 import org.ejbca.core.model.ra.userdatasource.UserDataSourceExistsException; 34 import org.ejbca.core.model.ra.userdatasource.UserDataSourceVO; 35 import org.ejbca.ui.web.RequestHelper; 36 import org.ejbca.ui.web.admin.configuration.EjbcaWebBean; 37 import org.ejbca.util.dn.DNFieldExtractor; 38 39 40 46 public class EditUserDataSourceJSPHelper implements java.io.Serializable { 47 48 57 private static final long serialVersionUID = 436830207093078432L; 58 59 public static final String ACTION = "action"; 60 public static final String ACTION_EDIT_USERDATASOURCES = "edituserdatasources"; 61 public static final String ACTION_EDIT_USERDATASOURCE = "edituserdatasource"; 62 63 public static final String ACTION_CHANGE_USERDATASOURCETYPE = "changeuserdatasourcetype"; 64 65 66 public static final String CHECKBOX_VALUE = BaseUserDataSource.TRUE; 67 68 public static final String BUTTON_EDIT_USERDATASOURCE = "buttonedituserdatasource"; 70 public static final String BUTTON_DELETE_USERDATASOURCE = "buttondeleteuserdatasource"; 71 public static final String BUTTON_ADD_USERDATASOURCE = "buttonadduserdatasource"; 72 public static final String BUTTON_RENAME_USERDATASOURCE = "buttonrenameuserdatasource"; 73 public static final String BUTTON_CLONE_USERDATASOURCE = "buttoncloneuserdatasource"; 74 75 public static final String SELECT_USERDATASOURCE = "selectuserdatasource"; 76 public static final String TEXTFIELD_USERDATASOURCENAME = "textfielduserdatasourcename"; 77 public static final String HIDDEN_USERDATASOURCENAME = "hiddenuserdatasourcename"; 78 79 public static final String BUTTON_TESTCONNECTION = "buttontestconnection"; 81 public static final String BUTTON_SAVE = "buttonsave"; 82 public static final String BUTTON_CANCEL = "buttoncancel"; 83 84 public static final String TYPE_CUSTOM = "typecustom"; 85 86 public static final String HIDDEN_USERDATASOURCETYPE = "hiddenuserdatasourcetype"; 87 public static final String SELECT_USERDATASOURCETYPE = "selectuserdatasourcetype"; 88 89 public static final String SELECT_APPLICABLECAS = "selectapplicablecas"; 90 public static final String SELECT_MODIFYABLEFIELDS = "selectmodifyablefields"; 91 public static final String TEXTAREA_DESCRIPTION = "textareadescription"; 92 93 public static final String TEXTFIELD_CUSTOMCLASSPATH = "textfieldcustomclasspath"; 94 public static final String TEXTAREA_CUSTOMPROPERTIES = "textareacustomproperties"; 95 96 public static final String PAGE_USERDATASOURCE = "userdatasourcepage.jspf"; 97 public static final String PAGE_USERDATASOURCES = "userdatasourcespage.jspf"; 98 99 100 101 102 103 104 public EditUserDataSourceJSPHelper(){ 105 } 106 112 public void initialize(HttpServletRequest request, EjbcaWebBean ejbcawebbean, 113 RAInterfaceBean rabean) throws Exception { 114 115 if(!initialized){ 116 initialized = true; 117 userdatasourcesession = rabean.getUserDataSourceSession(); 118 issuperadministrator = false; 119 admin = ejbcawebbean.getAdminObject(); 120 this.ejbcawebbean = ejbcawebbean; 121 try{ 122 issuperadministrator = ejbcawebbean.isAuthorizedNoLog(AvailableAccessRules.ROLE_SUPERADMINISTRATOR); 123 }catch(AuthorizationDeniedException ade){} 124 } 125 } 126 127 public String parseRequest(HttpServletRequest request) throws AuthorizationDeniedException{ 128 String includefile = PAGE_USERDATASOURCES; 129 String userdatasource = null; 130 String action = null; 131 132 try { 133 RequestHelper.setDefaultCharacterEncoding(request); 134 } catch (UnsupportedEncodingException e1) { 135 } 137 action = request.getParameter(ACTION); 138 if( action != null){ 139 if( action.equals(ACTION_EDIT_USERDATASOURCES)){ 140 if( request.getParameter(BUTTON_EDIT_USERDATASOURCE) != null){ 141 userdatasource = request.getParameter(SELECT_USERDATASOURCE); 142 if(userdatasource != null){ 143 if(!userdatasource.trim().equals("")){ 144 includefile=PAGE_USERDATASOURCE; 145 this.userdatasourcename = userdatasource; 146 this.userdatasourcedata = userdatasourcesession.getUserDataSource(admin,userdatasourcename); 147 } 148 else{ 149 userdatasource= null; 150 } 151 } 152 if(userdatasource == null){ 153 includefile=PAGE_USERDATASOURCES; 154 } 155 } 156 if( request.getParameter(BUTTON_DELETE_USERDATASOURCE) != null) { 157 userdatasource = request.getParameter(SELECT_USERDATASOURCE); 158 if(userdatasource != null){ 159 if(!userdatasource.trim().equals("")){ 160 userdatasourcedeletefailed = !userdatasourcesession.removeUserDataSource(admin,userdatasource); 161 } 162 } 163 includefile=PAGE_USERDATASOURCES; 164 } 165 if( request.getParameter(BUTTON_RENAME_USERDATASOURCE) != null){ 166 String newuserdatasourcename = request.getParameter(TEXTFIELD_USERDATASOURCENAME); 168 String olduserdatasourcename = request.getParameter(SELECT_USERDATASOURCE); 169 if(olduserdatasourcename != null && newuserdatasourcename != null){ 170 if(!newuserdatasourcename.trim().equals("") && !olduserdatasourcename.trim().equals("")){ 171 try{ 172 userdatasourcesession.renameUserDataSource(admin,olduserdatasourcename.trim(),newuserdatasourcename.trim()); 173 }catch( UserDataSourceExistsException e){ 174 userdatasourceexists=true; 175 } 176 } 177 } 178 includefile=PAGE_USERDATASOURCES; 179 } 180 if( request.getParameter(BUTTON_ADD_USERDATASOURCE) != null){ 181 userdatasource = request.getParameter(TEXTFIELD_USERDATASOURCENAME); 182 if(userdatasource != null){ 183 if(!userdatasource.trim().equals("")){ 184 try{ 185 userdatasourcesession.addUserDataSource(admin,userdatasource.trim(), new CustomUserDataSourceContainer()); 186 }catch( UserDataSourceExistsException e){ 187 userdatasourceexists=true; 188 } 189 } 190 } 191 includefile=PAGE_USERDATASOURCES; 192 } 193 if( request.getParameter(BUTTON_CLONE_USERDATASOURCE) != null){ 194 String newuserdatasourcename = request.getParameter(TEXTFIELD_USERDATASOURCENAME); 195 String olduserdatasourcename = request.getParameter(SELECT_USERDATASOURCE); 196 if(olduserdatasourcename != null && newuserdatasourcename != null){ 197 if(!newuserdatasourcename.trim().equals("") && !olduserdatasourcename.trim().equals("")){ 198 try{ 199 userdatasourcesession.cloneUserDataSource(admin,olduserdatasourcename.trim(),newuserdatasourcename.trim()); 200 }catch( UserDataSourceExistsException e){ 201 userdatasourceexists=true; 202 } 203 } 204 } 205 includefile=PAGE_USERDATASOURCES; 206 } 207 } 208 if( action.equals(ACTION_EDIT_USERDATASOURCE)){ 209 userdatasource = request.getParameter(HIDDEN_USERDATASOURCENAME); 211 this.userdatasourcename = userdatasource; 212 if(userdatasource != null){ 213 if(!userdatasource.trim().equals("")){ 214 if(request.getParameter(BUTTON_SAVE) != null || 215 request.getParameter(BUTTON_TESTCONNECTION) != null){ 216 217 if(userdatasourcedata == null){ 218 int tokentype = new Integer (request.getParameter(HIDDEN_USERDATASOURCETYPE)).intValue(); 219 if(tokentype == CustomUserDataSourceContainer.TYPE_CUSTOMUSERDATASOURCECONTAINER) 220 userdatasourcedata = new CustomUserDataSourceContainer(); 221 222 } 223 225 String value = request.getParameter(TEXTAREA_DESCRIPTION); 227 if(value != null){ 228 value = value.trim(); 229 userdatasourcedata.setDescription(value); 230 } 231 232 String [] values = request.getParameterValues(SELECT_MODIFYABLEFIELDS); 233 if(values != null){ 234 Set modifyablefields = new HashSet (); 235 for(int i=0;i< values.length;i++){ 236 modifyablefields.add(new Integer (values[i])); 237 } 238 239 userdatasourcedata.setModifiableFields(modifyablefields); 240 }else{ 241 userdatasourcedata.setModifiableFields(new HashSet ()); 242 } 243 244 values = request.getParameterValues(SELECT_APPLICABLECAS); 245 if(values != null){ 246 ArrayList useCAs = new ArrayList (); 247 for(int i=0;i< values.length;i++){ 248 Integer caid = new Integer (values[i]); 249 if(caid.intValue() == BaseUserDataSource.ANYCA){ 250 useCAs = new ArrayList (); 251 useCAs.add(caid); 252 break; 253 } 254 useCAs.add(new Integer (values[i])); 255 } 256 257 userdatasourcedata.setApplicableCAs(useCAs); 258 }else{ 259 userdatasourcedata.setApplicableCAs(new ArrayList ()); 260 } 261 262 263 264 265 if(userdatasourcedata instanceof CustomUserDataSourceContainer){ 266 value = request.getParameter(TEXTFIELD_CUSTOMCLASSPATH); 267 if(value != null){ 268 value = value.trim(); 269 ((CustomUserDataSourceContainer) userdatasourcedata).setClassPath(value); 270 } 271 value = request.getParameter(TEXTAREA_CUSTOMPROPERTIES); 272 if(value != null){ 273 value = value.trim(); 274 ((CustomUserDataSourceContainer) userdatasourcedata).setPropertyData(value); 275 } 276 } 277 278 if(request.getParameter(BUTTON_SAVE) != null){ 279 userdatasourcesession.changeUserDataSource(admin,userdatasource,userdatasourcedata); 280 includefile=PAGE_USERDATASOURCES; 281 } 282 if(request.getParameter(BUTTON_TESTCONNECTION)!= null){ 283 connectionmessage = true; 284 userdatasourcesession.changeUserDataSource(admin, userdatasource,userdatasourcedata); 285 try{ 286 int userdatasourceid = userdatasourcesession.getUserDataSourceId(admin,userdatasource); 287 userdatasourcesession.testConnection(admin,userdatasourceid); 288 connectionsuccessful = true; 289 }catch(UserDataSourceConnectionException pce){ 290 connectionerrormessage = pce.getMessage(); 291 } 292 includefile=PAGE_USERDATASOURCE; 293 } 294 295 } 296 if(request.getParameter(BUTTON_CANCEL) != null){ 297 includefile=PAGE_USERDATASOURCES; 299 } 300 301 } 302 } 303 } 304 305 if( action.equals(ACTION_CHANGE_USERDATASOURCETYPE)){ 306 this.userdatasourcename = request.getParameter(HIDDEN_USERDATASOURCENAME); 307 String value = request.getParameter(SELECT_USERDATASOURCETYPE); 308 if(value!=null){ 309 int profiletype = Integer.parseInt(value); 310 switch(profiletype){ 311 case CustomUserDataSourceContainer.TYPE_CUSTOMUSERDATASOURCECONTAINER : 312 userdatasourcedata = new CustomUserDataSourceContainer(); 313 break; 314 } 315 } 316 317 includefile=PAGE_USERDATASOURCE; 318 } 319 } 320 321 return includefile; 322 } 323 324 public int getUserDataSourceType(){ 325 int retval = CustomUserDataSourceContainer.TYPE_CUSTOMUSERDATASOURCECONTAINER; 326 327 if(userdatasourcedata instanceof CustomUserDataSourceContainer) 328 retval = CustomUserDataSourceContainer.TYPE_CUSTOMUSERDATASOURCECONTAINER; 329 330 331 return retval; 332 } 333 334 335 public TreeMap getAuthorizedUserDataSourceNames(){ 336 TreeMap retval = new TreeMap (); 337 338 Collection authorizedsources = userdatasourcesession.getAuthorizedUserDataSourceIds(admin,false); 339 Iterator iter = authorizedsources.iterator(); 340 while(iter.hasNext()){ 341 Integer id = (Integer ) iter.next(); 342 retval.put(userdatasourcesession.getUserDataSourceName(admin,id.intValue()),id); 343 } 344 345 346 return retval; 347 } 348 349 public TreeMap getModifyableFieldTexts(){ 350 if(modifyableFieldTexts ==null){ 351 modifyableFieldTexts = new TreeMap (); 352 353 String subjectdntext = ejbcawebbean.getText("SUBJECTDN"); 354 String subjectaltnametext = ejbcawebbean.getText("SUBALTNAME"); 355 String subjectdirattrtext = ejbcawebbean.getText("SUBDIRATTR"); 356 357 modifyableFieldTexts.put(subjectdntext + " : " + ejbcawebbean.getText("UID"),new Integer (DNFieldExtractor.UID)); 358 modifyableFieldTexts.put(subjectdntext + " : " + ejbcawebbean.getText("COMMONNAME"),new Integer (DNFieldExtractor.CN)); 359 modifyableFieldTexts.put(subjectdntext + " : " + ejbcawebbean.getText("DNSERIALNUMBER"), new Integer (DNFieldExtractor.SN)); 360 modifyableFieldTexts.put(subjectdntext + " : " + ejbcawebbean.getText("GIVENNAME1"),new Integer (DNFieldExtractor.GIVENNAME)); 361 modifyableFieldTexts.put(subjectdntext + " : " + ejbcawebbean.getText("INITIALS"), new Integer (DNFieldExtractor.INITIALS)); 362 modifyableFieldTexts.put(subjectdntext + " : " + ejbcawebbean.getText("SURNAME"), new Integer (DNFieldExtractor.SURNAME)); 363 modifyableFieldTexts.put(subjectdntext + " : " + ejbcawebbean.getText("TITLE"), new Integer (DNFieldExtractor.T)); 364 modifyableFieldTexts.put(subjectdntext + " : " + ejbcawebbean.getText("ORGANIZATIONUNIT"), new Integer (DNFieldExtractor.OU)); 365 modifyableFieldTexts.put(subjectdntext + " : " + ejbcawebbean.getText("ORGANIZATION"), new Integer (DNFieldExtractor.O)); 366 modifyableFieldTexts.put(subjectdntext + " : " + ejbcawebbean.getText("LOCALE"), new Integer (DNFieldExtractor.L)); 367 modifyableFieldTexts.put(subjectdntext + " : " + ejbcawebbean.getText("STATE"), new Integer (DNFieldExtractor.ST)); 368 modifyableFieldTexts.put(subjectdntext + " : " + ejbcawebbean.getText("DOMAINCOMPONENT"), new Integer (DNFieldExtractor.DC)); 369 modifyableFieldTexts.put(subjectdntext + " : " + ejbcawebbean.getText("COUNTRY"), new Integer (DNFieldExtractor.C)); 370 modifyableFieldTexts.put(subjectdntext + " : " + ejbcawebbean.getText("UNSTRUCTUREDADDRESS"), new Integer (DNFieldExtractor.UNSTRUCTUREDADDRESS)); 371 modifyableFieldTexts.put(subjectdntext + " : " + ejbcawebbean.getText("UNSTRUCTUREDNAME"), new Integer (DNFieldExtractor.UNSTRUCTUREDNAME)); 372 373 modifyableFieldTexts.put(subjectaltnametext + " : " + ejbcawebbean.getText("DNSNAME"), new Integer (DNFieldExtractor.DNSNAME)); 374 modifyableFieldTexts.put(subjectaltnametext + " : " + ejbcawebbean.getText("IPADDRESS"), new Integer (DNFieldExtractor.IPADDRESS)); 375 modifyableFieldTexts.put(subjectaltnametext + " : " + ejbcawebbean.getText("DIRECTORYNAME"), new Integer (DNFieldExtractor.DIRECTORYNAME)); 376 modifyableFieldTexts.put(subjectaltnametext + " : " + ejbcawebbean.getText("UNIFORMRESOURCEID"), new Integer (DNFieldExtractor.URI)); 377 modifyableFieldTexts.put(subjectaltnametext + " : " + ejbcawebbean.getText("UPN"), new Integer (DNFieldExtractor.UPN)); 378 modifyableFieldTexts.put(subjectaltnametext + " : " + ejbcawebbean.getText("GUID"), new Integer (DNFieldExtractor.GUID)); 379 380 modifyableFieldTexts.put(subjectdirattrtext + " : " + ejbcawebbean.getText("DATEOFBIRTH"), new Integer (DNFieldExtractor.DATEOFBIRTH)); 381 modifyableFieldTexts.put(subjectdirattrtext + " : " + ejbcawebbean.getText("PLACEOFBIRTH"),new Integer ( DNFieldExtractor.PLACEOFBIRTH)); 382 modifyableFieldTexts.put(subjectdirattrtext + " : " + ejbcawebbean.getText("GENDER"),new Integer ( DNFieldExtractor.GENDER)); 383 modifyableFieldTexts.put(subjectdirattrtext + " : " + ejbcawebbean.getText("COUNTRYOFCITIZENSHIP"),new Integer ( DNFieldExtractor.COUNTRYOFCITIZENSHIP)); 384 modifyableFieldTexts.put(subjectdirattrtext + " : " + ejbcawebbean.getText("COUNTRYOFRESIDENCE"),new Integer ( DNFieldExtractor.COUNTRYOFRESIDENCE)); 385 386 387 modifyableFieldTexts.put(ejbcawebbean.getText("USERNAME"), new Integer (UserDataSourceVO.ISMODIFYABLE_USERNAME)); 388 modifyableFieldTexts.put(ejbcawebbean.getText("PASSWORD"), new Integer (UserDataSourceVO.ISMODIFYABLE_PASSWORD)); 389 modifyableFieldTexts.put(ejbcawebbean.getText("CA"), new Integer (UserDataSourceVO.ISMODIFYABLE_CAID)); 390 modifyableFieldTexts.put(ejbcawebbean.getText("EMAIL"), new Integer (UserDataSourceVO.ISMODIFYABLE_EMAILDATA)); 391 modifyableFieldTexts.put(ejbcawebbean.getText("PASSWORD"), new Integer (UserDataSourceVO.ISMODIFYABLE_TYPE)); 392 modifyableFieldTexts.put(ejbcawebbean.getText("ENDENTITYPROFILE"), new Integer (UserDataSourceVO.ISMODIFYABLE_ENDENTITYPROFILE)); 393 modifyableFieldTexts.put(ejbcawebbean.getText("CERTIFICATEPROFILE"), new Integer (UserDataSourceVO.ISMODIFYABLE_CERTIFICATEPROFILE)); 394 modifyableFieldTexts.put(ejbcawebbean.getText("TOKEN"), new Integer (UserDataSourceVO.ISMODIFYABLE_TOKENTYPE)); 395 modifyableFieldTexts.put(ejbcawebbean.getText("HARDTOKENISSUER"), new Integer (UserDataSourceVO.ISMODIFYABLE_HARDTOKENISSUER)); 396 397 398 } 399 return modifyableFieldTexts; 400 } 401 402 private boolean initialized=false; 403 public boolean userdatasourceexists = false; 404 public boolean userdatasourcedeletefailed = false; 405 public boolean connectionmessage = false; 406 public boolean connectionsuccessful = false; 407 public String connectionerrormessage = ""; 408 public boolean issuperadministrator = false; 409 public BaseUserDataSource userdatasourcedata = null; 410 public String userdatasourcename = null; 411 private TreeMap modifyableFieldTexts = null; 412 private IUserDataSourceSessionLocal userdatasourcesession = null; 413 private Admin admin = null; 414 private EjbcaWebBean ejbcawebbean = null; 415 416 417 } 418 | Popular Tags |