1 13 14 package org.ejbca.ui.web.admin.hardtokeninterface; 15 16 import java.io.BufferedReader ; 17 import java.io.IOException ; 18 import java.io.InputStream ; 19 import java.io.InputStreamReader ; 20 import java.io.UnsupportedEncodingException ; 21 import java.util.Iterator ; 22 import java.util.List ; 23 24 import javax.servlet.http.HttpServletRequest ; 25 26 import org.apache.commons.fileupload.DiskFileUpload; 27 import org.apache.commons.fileupload.FileItem; 28 import org.apache.commons.fileupload.FileUploadBase; 29 import org.apache.commons.fileupload.FileUploadException; 30 import org.ejbca.core.model.authorization.AuthorizationDeniedException; 31 import org.ejbca.core.model.hardtoken.HardTokenProfileExistsException; 32 import org.ejbca.core.model.hardtoken.profiles.EIDProfile; 33 import org.ejbca.core.model.hardtoken.profiles.EnhancedEIDProfile; 34 import org.ejbca.core.model.hardtoken.profiles.HardTokenProfile; 35 import org.ejbca.core.model.hardtoken.profiles.HardTokenProfileWithAdressLabel; 36 import org.ejbca.core.model.hardtoken.profiles.HardTokenProfileWithPINEnvelope; 37 import org.ejbca.core.model.hardtoken.profiles.HardTokenProfileWithReceipt; 38 import org.ejbca.core.model.hardtoken.profiles.HardTokenProfileWithVisualLayout; 39 import org.ejbca.core.model.hardtoken.profiles.IAdressLabelSettings; 40 import org.ejbca.core.model.hardtoken.profiles.IPINEnvelopeSettings; 41 import org.ejbca.core.model.hardtoken.profiles.IReceiptSettings; 42 import org.ejbca.core.model.hardtoken.profiles.IVisualLayoutSettings; 43 import org.ejbca.core.model.hardtoken.profiles.SwedishEIDProfile; 44 import org.ejbca.core.model.hardtoken.profiles.TurkishEIDProfile; 45 import org.ejbca.ui.web.RequestHelper; 46 import org.ejbca.ui.web.admin.configuration.EjbcaWebBean; 47 48 49 55 public class EditHardTokenProfileJSPHelper implements java.io.Serializable { 56 57 public static final String ACTION = "action"; 58 public static final String ACTION_EDIT_HARDTOKENPROFILES = "edithardtokenprofiles"; 59 public static final String ACTION_EDIT_HARDTOKENPROFILE = "edithardtokenprofile"; 60 public static final String ACTION_UPLOADENVELOPETEMP = "uploadenvelopetemp"; 61 public static final String ACTION_UPLOADVISUALTEMP = "uploadvisualtemp"; 62 public static final String ACTION_UPLOADRECEIPTTEMP = "uploadreceipttemp"; 63 public static final String ACTION_UPLOADADRESSLABELTEMP = "uploadadresstemp"; 64 65 public static final String ACTION_CHANGE_PROFILETYPE = "changeprofiletype"; 66 67 68 public static final String CHECKBOX_VALUE = HardTokenProfile.TRUE; 69 70 public static final String BUTTON_EDIT_HARDTOKENPROFILES = "buttonedithardtokenprofile"; 72 public static final String BUTTON_DELETE_HARDTOKENPROFILES = "buttondeletehardtokenprofile"; 73 public static final String BUTTON_ADD_HARDTOKENPROFILES = "buttonaddhardtokenprofile"; 74 public static final String BUTTON_RENAME_HARDTOKENPROFILES = "buttonrenamehardtokenprofile"; 75 public static final String BUTTON_CLONE_HARDTOKENPROFILES = "buttonclonehardtokenprofile"; 76 77 public static final String SELECT_HARDTOKENPROFILES = "selecthardtokenprofile"; 78 public static final String TEXTFIELD_HARDTOKENPROFILESNAME = "textfieldhardtokenprofilename"; 79 public static final String HIDDEN_HARDTOKENPROFILENAME = "hiddenhardtokenprofilename"; 80 81 public static final String BUTTON_SAVE = "buttonsave"; 83 public static final String BUTTON_CANCEL = "buttoncancel"; 84 public static final String BUTTON_UPLOADENVELOPETEMP= "buttonuploadenvelopetemplate"; 85 public static final String BUTTON_UPLOADVISUALTEMP = "buttonuploadvisualtemplate"; 86 public static final String BUTTON_UPLOADRECEIPTTEMP = "buttonuploadreceipttemplate"; 87 public static final String BUTTON_UPLOADADRESSLABELTEMP = "buttonuploadadresslabeltemplate"; 88 public static final String BUTTON_UPLOADFILE = "buttonuploadfile"; 89 90 public static final String TYPE_SWEDISHEID = "typeswedisheid"; 91 public static final String TYPE_ENCHANCEDEID = "typeenchancedeid"; 92 public static final String TYPE_TURKISHEID = "typeturkisheid"; 93 94 public static final String TEXTFIELD_VISUALVALIDITY = "textfieldvisualvalidity"; 95 public static final String TEXTFIELD_SNPREFIX = "textfieldsnprefix"; 96 97 public static final String CHECKBOX_EREASBLE = "checkboxereasable"; 98 public static final String CHECKBOX_CERTWRITABLE = "checkboxcertwritable"; 99 public static final String CHECKBOX_KEYRECOVERABLE = "checkboxkeyrecoverable"; 100 public static final String CHECKBOX_REUSEOLDCERT = "checkboxreuseoldcert"; 101 public static final String CHECKBOX_USEIDENTICALPINS= "useidenticalpins"; 102 103 public static final String HIDDEN_HARDTOKENTYPE = "hiddenhardtokentype"; 104 105 public static final String SELECT_HARDTOKENTYPE = "selecthardtokentype"; 106 public static final String SELECT_CERTIFICATEPROFILE = "selectcertificateprofile"; 107 public static final String SELECT_CA = "selectca"; 108 public static final String SELECT_PINTYPE = "selectpintype"; 109 public static final String SELECT_MINKEYLENGTH = "selectminkeylength"; 110 public static final String SELECT_ENVELOPETYPE = "selectenvelopetype"; 111 public static final String SELECT_NUMOFENVELOPECOPIES= "selectenvelopecopies"; 112 public static final String SELECT_RECEIPTTYPE = "selectreceipttype"; 113 public static final String SELECT_NUMOFRECEIPTCOPIES = "selectreceiptcopies"; 114 public static final String SELECT_ADRESSLABELTYPE = "selectadresslabeltype"; 115 public static final String SELECT_NUMOFADRESSLABELCOPIES = "selectadresslabelcopies"; 116 public static final String SELECT_VISUALLAYOUTTYPE = "selectvisuallayouttype"; 117 public static final String SELECT_NUMOFTOKENCOPIES = "selectnumoftokencopies"; 118 public static final String SELECT_MINPINLENGTH = "selectminpinlength"; 119 120 public static final String FILE_TEMPLATE = "filetemplate"; 121 122 public static final int UPLOADMODE_ENVELOPE = 0; 123 public static final int UPLOADMODE_VISUAL = 1; 124 public static final int UPLOADMODE_RECEIPT = 2; 125 public static final int UPLOADMODE_ADRESSLABEL = 3; 126 127 public static final String PAGE_HARDTOKENPROFILE = "hardtokenprofilepage.jspf"; 128 public static final String PAGE_HARDTOKENPROFILES = "hardtokenprofilespage.jspf"; 129 public static final String PAGE_UPLOADTEMPLATE = "uploadtemplate.jspf"; 130 131 132 public EditHardTokenProfileJSPHelper(){ 133 } 134 140 public void initialize(EjbcaWebBean ejbcawebbean, HardTokenInterfaceBean hardtokenbean) throws Exception { 141 142 if(!initialized){ 143 this.hardtokenbean = hardtokenbean; 144 initialized = true; 145 issuperadministrator = false; 146 try{ 147 issuperadministrator = ejbcawebbean.isAuthorizedNoLog("/super_administrator"); 148 }catch(AuthorizationDeniedException ade){} 149 } 150 } 151 152 public String parseRequest(HttpServletRequest request) throws AuthorizationDeniedException{ 153 String includefile = PAGE_HARDTOKENPROFILES; 154 String profile = null; 155 HardTokenProfileDataHandler handler = hardtokenbean.getHardTokenProfileDataHandler(); 156 String action = null; 157 158 InputStream file = null; 159 160 boolean buttonupload = false; 161 String filename = null; 162 163 try { 164 RequestHelper.setDefaultCharacterEncoding(request); 165 } catch (UnsupportedEncodingException e1) { 166 } 168 169 if(FileUploadBase.isMultipartContent(request)){ 170 try{ 171 DiskFileUpload upload = new DiskFileUpload(); 172 upload.setSizeMax(2000000); 173 upload.setSizeThreshold(1999999); 174 List items = upload.parseRequest(request); 175 176 Iterator iter = items.iterator(); 177 while (iter.hasNext()) { 178 FileItem item = (FileItem) iter.next(); 179 180 if (item.isFormField()) { 181 if(item.getFieldName().equals(ACTION)) 182 action = item.getString(); 183 if(item.getFieldName().equals(HIDDEN_HARDTOKENPROFILENAME)) 184 profilename = item.getString(); 185 if(item.getFieldName().equals(BUTTON_CANCEL)) { 186 } 188 if(item.getFieldName().equals(BUTTON_UPLOADFILE)) 189 buttonupload = true; 190 }else{ 191 file = item.getInputStream(); 192 filename = item.getName(); 193 } 194 } 195 }catch(IOException e){ 196 fileuploadfailed = true; 197 includefile=PAGE_HARDTOKENPROFILE; 198 }catch(FileUploadException e){ 199 fileuploadfailed = true; 200 includefile=PAGE_HARDTOKENPROFILE; 201 } 202 }else{ 203 action = request.getParameter(ACTION); 204 } 205 206 207 208 if( action != null){ 209 if( action.equals(ACTION_EDIT_HARDTOKENPROFILES)){ 210 if( request.getParameter(BUTTON_EDIT_HARDTOKENPROFILES) != null){ 211 profile = request.getParameter(SELECT_HARDTOKENPROFILES); 213 if(profile != null){ 214 if(!profile.trim().equals("")){ 215 includefile=PAGE_HARDTOKENPROFILE; 216 this.profilename = profile; 217 this.profiledata = handler.getHardTokenProfile(profilename); 218 } 219 else{ 220 profile= null; 221 } 222 } 223 if(profile == null){ 224 includefile=PAGE_HARDTOKENPROFILES; 225 } 226 } 227 if( request.getParameter(BUTTON_DELETE_HARDTOKENPROFILES) != null) { 228 profile = request.getParameter(SELECT_HARDTOKENPROFILES); 230 if(profile != null){ 231 if(!profile.trim().equals("")){ 232 hardtokenprofiledeletefailed = handler.removeHardTokenProfile(profile); 233 } 234 } 235 includefile=PAGE_HARDTOKENPROFILES; 236 } 237 if( request.getParameter(BUTTON_RENAME_HARDTOKENPROFILES) != null){ 238 String newhardtokenprofilename = request.getParameter(TEXTFIELD_HARDTOKENPROFILESNAME); 240 String oldhardtokenprofilename = request.getParameter(SELECT_HARDTOKENPROFILES); 241 if(oldhardtokenprofilename != null && newhardtokenprofilename != null){ 242 if(!newhardtokenprofilename.trim().equals("") && !oldhardtokenprofilename.trim().equals("")){ 243 try{ 244 handler.renameHardTokenProfile(oldhardtokenprofilename.trim(),newhardtokenprofilename.trim()); 245 }catch( HardTokenProfileExistsException e){ 246 hardtokenprofileexists=true; 247 } 248 } 249 } 250 includefile=PAGE_HARDTOKENPROFILES; 251 } 252 if( request.getParameter(BUTTON_ADD_HARDTOKENPROFILES) != null){ 253 profile = request.getParameter(TEXTFIELD_HARDTOKENPROFILESNAME); 255 if(profile != null){ 256 if(!profile.trim().equals("")){ 257 try{ 258 if(!handler.addHardTokenProfile(profile.trim(), new SwedishEIDProfile())){ 259 profilemalformed = true; 260 } 261 }catch( HardTokenProfileExistsException e){ 262 hardtokenprofileexists=true; 263 } 264 } 265 } 266 includefile=PAGE_HARDTOKENPROFILES; 267 } 268 if( request.getParameter(BUTTON_CLONE_HARDTOKENPROFILES) != null){ 269 String newhardtokenprofilename = request.getParameter(TEXTFIELD_HARDTOKENPROFILESNAME); 271 String oldhardtokenprofilename = request.getParameter(SELECT_HARDTOKENPROFILES); 272 if(oldhardtokenprofilename != null && newhardtokenprofilename != null){ 273 if(!newhardtokenprofilename.trim().equals("") && !oldhardtokenprofilename.trim().equals("")){ 274 try{ 275 handler.cloneHardTokenProfile(oldhardtokenprofilename.trim(),newhardtokenprofilename.trim()); 276 }catch(HardTokenProfileExistsException e){ 277 hardtokenprofileexists=true; 278 } 279 } 280 } 281 includefile=PAGE_HARDTOKENPROFILES; 282 } 283 } 284 285 if( action.equals(ACTION_EDIT_HARDTOKENPROFILE)){ 286 profile = request.getParameter(HIDDEN_HARDTOKENPROFILENAME); 288 if(profile != null){ 289 if(!profile.trim().equals("")){ 290 if(request.getParameter(BUTTON_SAVE) != null || 291 request.getParameter(BUTTON_UPLOADENVELOPETEMP) != null || 292 request.getParameter(BUTTON_UPLOADVISUALTEMP) != null || 293 request.getParameter(BUTTON_UPLOADRECEIPTTEMP) != null || 294 request.getParameter(BUTTON_UPLOADADRESSLABELTEMP) != null ){ 295 296 297 if(profiledata == null){ 298 String tokentype = request.getParameter(HIDDEN_HARDTOKENTYPE); 299 if(tokentype.equals(TYPE_SWEDISHEID)) 300 profiledata = new SwedishEIDProfile(); 301 if(tokentype.equals(TYPE_ENCHANCEDEID)) 302 profiledata = new EnhancedEIDProfile(); 303 if(tokentype.equals(TYPE_TURKISHEID)) 304 profiledata = new TurkishEIDProfile(); 305 } 306 308 String value = request.getParameter(TEXTFIELD_SNPREFIX); 310 if(value != null){ 311 value = value.trim(); 312 profiledata.setHardTokenSNPrefix(value); 313 } 314 value = request.getParameter(CHECKBOX_EREASBLE); 315 if(value != null){ 316 profiledata.setEreasableToken(value.equals(CHECKBOX_VALUE)); 317 }else 318 profiledata.setEreasableToken(false); 319 320 value = request.getParameter(SELECT_NUMOFTOKENCOPIES); 321 if(value != null){ 322 profiledata.setNumberOfCopies(Integer.parseInt(value)); 323 } 324 325 value = request.getParameter(CHECKBOX_USEIDENTICALPINS); 326 if(value != null){ 327 profiledata.setGenerateIdenticalPINForCopies(value.equals(CHECKBOX_VALUE)); 328 }else 329 profiledata.setGenerateIdenticalPINForCopies(false); 330 331 if(profiledata instanceof HardTokenProfileWithPINEnvelope){ 332 value = request.getParameter(SELECT_ENVELOPETYPE); 333 if(value != null) 334 ((HardTokenProfileWithPINEnvelope) profiledata).setPINEnvelopeType(Integer.parseInt(value)); 335 value = request.getParameter(SELECT_NUMOFENVELOPECOPIES); 336 if(value != null) 337 ((HardTokenProfileWithPINEnvelope) profiledata).setNumberOfPINEnvelopeCopies(Integer.parseInt(value)); 338 value = request.getParameter(TEXTFIELD_VISUALVALIDITY); 339 if(value != null) 340 ((HardTokenProfileWithPINEnvelope) profiledata).setVisualValidity(Integer.parseInt(value)); 341 342 } 343 344 if(profiledata instanceof HardTokenProfileWithVisualLayout){ 345 HardTokenProfileWithVisualLayout visprof = (HardTokenProfileWithVisualLayout) profiledata; 346 value = request.getParameter(SELECT_VISUALLAYOUTTYPE); 347 if(value != null) 348 visprof.setVisualLayoutType(Integer.parseInt(value)); 349 } 350 351 if(profiledata instanceof HardTokenProfileWithReceipt){ 352 value = request.getParameter(SELECT_RECEIPTTYPE); 353 if(value != null) 354 ((HardTokenProfileWithReceipt) profiledata).setReceiptType(Integer.parseInt(value)); 355 value = request.getParameter(SELECT_NUMOFRECEIPTCOPIES); 356 if(value != null) 357 ((HardTokenProfileWithReceipt) profiledata).setNumberOfReceiptCopies(Integer.parseInt(value)); 358 } 359 if(profiledata instanceof HardTokenProfileWithAdressLabel){ 360 value = request.getParameter(SELECT_ADRESSLABELTYPE); 361 if(value != null) 362 ((HardTokenProfileWithAdressLabel) profiledata).setAdressLabelType(Integer.parseInt(value)); 363 value = request.getParameter(SELECT_NUMOFADRESSLABELCOPIES); 364 if(value != null) 365 ((HardTokenProfileWithAdressLabel) profiledata).setNumberOfAdressLabelCopies(Integer.parseInt(value)); 366 } 367 368 if(profiledata instanceof SwedishEIDProfile){ 369 SwedishEIDProfile sweprof = (SwedishEIDProfile) profiledata; 370 371 value = request.getParameter(SELECT_MINKEYLENGTH); 372 if(value!= null){ 373 int val = Integer.parseInt(value); 374 sweprof.setMinimumKeyLength(SwedishEIDProfile.CERTUSAGE_SIGN, val); 375 sweprof.setMinimumKeyLength(SwedishEIDProfile.CERTUSAGE_AUTHENC, val); 376 sweprof.setKeyType(SwedishEIDProfile.CERTUSAGE_SIGN, EIDProfile.KEYTYPE_RSA); 377 sweprof.setKeyType(SwedishEIDProfile.CERTUSAGE_AUTHENC, EIDProfile.KEYTYPE_RSA); 378 } 379 value = request.getParameter(CHECKBOX_CERTWRITABLE); 380 if(value != null){ 381 sweprof.setCertWritable(SwedishEIDProfile.CERTUSAGE_SIGN, value.equals(CHECKBOX_VALUE)); 382 sweprof.setCertWritable(SwedishEIDProfile.CERTUSAGE_AUTHENC, value.equals(CHECKBOX_VALUE)); 383 }else{ 384 sweprof.setCertWritable(SwedishEIDProfile.CERTUSAGE_SIGN, false); 385 sweprof.setCertWritable(SwedishEIDProfile.CERTUSAGE_AUTHENC, false); 386 } 387 388 value = request.getParameter(SELECT_CERTIFICATEPROFILE + "0"); 389 if(value!= null) 390 sweprof.setCertificateProfileId(SwedishEIDProfile.CERTUSAGE_SIGN, Integer.parseInt(value)); 391 392 value = request.getParameter(SELECT_CA + "0"); 393 if(value!= null) 394 sweprof.setCAId(SwedishEIDProfile.CERTUSAGE_SIGN, Integer.parseInt(value)); 395 value = request.getParameter(SELECT_PINTYPE + "0"); 396 if(value!= null) 397 sweprof.setPINType(SwedishEIDProfile.CERTUSAGE_SIGN, Integer.parseInt(value)); 398 value = request.getParameter(SELECT_MINPINLENGTH + "0"); 399 if(value!= null) 400 sweprof.setMinimumPINLength(SwedishEIDProfile.CERTUSAGE_SIGN, Integer.parseInt(value)); 401 402 value = request.getParameter(SELECT_CERTIFICATEPROFILE + "1"); 403 if(value!= null) 404 sweprof.setCertificateProfileId(SwedishEIDProfile.CERTUSAGE_AUTHENC, Integer.parseInt(value)); 405 406 value = request.getParameter(SELECT_CA + "1"); 407 if(value!= null) 408 sweprof.setCAId(SwedishEIDProfile.CERTUSAGE_AUTHENC, Integer.parseInt(value)); 409 value = request.getParameter(SELECT_PINTYPE + "1"); 410 if(value!= null) 411 sweprof.setPINType(SwedishEIDProfile.CERTUSAGE_AUTHENC, Integer.parseInt(value)); 412 value = request.getParameter(SELECT_MINPINLENGTH + "1"); 413 if(value!= null) 414 sweprof.setMinimumPINLength(SwedishEIDProfile.CERTUSAGE_AUTHENC, Integer.parseInt(value)); 415 416 } 417 418 if(profiledata instanceof TurkishEIDProfile){ 419 TurkishEIDProfile turkprof = (TurkishEIDProfile) profiledata; 420 421 value = request.getParameter(SELECT_MINKEYLENGTH); 422 if(value!= null){ 423 int val = Integer.parseInt(value); 424 turkprof.setMinimumKeyLength(TurkishEIDProfile.CERTUSAGE_SIGN, val); 425 turkprof.setMinimumKeyLength(TurkishEIDProfile.CERTUSAGE_AUTHENC, val); 426 turkprof.setKeyType(TurkishEIDProfile.CERTUSAGE_SIGN, EIDProfile.KEYTYPE_RSA); 427 turkprof.setKeyType(TurkishEIDProfile.CERTUSAGE_AUTHENC, EIDProfile.KEYTYPE_RSA); 428 } 429 value = request.getParameter(CHECKBOX_CERTWRITABLE); 430 if(value != null){ 431 turkprof.setCertWritable(TurkishEIDProfile.CERTUSAGE_SIGN, value.equals(CHECKBOX_VALUE)); 432 turkprof.setCertWritable(TurkishEIDProfile.CERTUSAGE_AUTHENC, value.equals(CHECKBOX_VALUE)); 433 }else{ 434 turkprof.setCertWritable(TurkishEIDProfile.CERTUSAGE_SIGN, false); 435 turkprof.setCertWritable(TurkishEIDProfile.CERTUSAGE_AUTHENC, false); 436 } 437 438 value = request.getParameter(SELECT_CERTIFICATEPROFILE + "0"); 439 if(value!= null) 440 turkprof.setCertificateProfileId(TurkishEIDProfile.CERTUSAGE_SIGN, Integer.parseInt(value)); 441 442 value = request.getParameter(SELECT_CA + "0"); 443 if(value!= null) 444 turkprof.setCAId(TurkishEIDProfile.CERTUSAGE_SIGN, Integer.parseInt(value)); 445 value = request.getParameter(SELECT_PINTYPE + "0"); 446 if(value!= null) 447 turkprof.setPINType(TurkishEIDProfile.CERTUSAGE_SIGN, Integer.parseInt(value)); 448 value = request.getParameter(SELECT_MINPINLENGTH + "0"); 449 if(value!= null) 450 turkprof.setMinimumPINLength(TurkishEIDProfile.CERTUSAGE_SIGN, Integer.parseInt(value)); 451 452 value = request.getParameter(SELECT_CERTIFICATEPROFILE + "1"); 453 if(value!= null) 454 turkprof.setCertificateProfileId(TurkishEIDProfile.CERTUSAGE_AUTHENC, Integer.parseInt(value)); 455 456 value = request.getParameter(SELECT_CA + "1"); 457 if(value!= null) 458 turkprof.setCAId(TurkishEIDProfile.CERTUSAGE_AUTHENC, Integer.parseInt(value)); 459 } 460 461 if(profiledata instanceof EnhancedEIDProfile){ 462 EnhancedEIDProfile enhprof = (EnhancedEIDProfile) profiledata; 463 464 value = request.getParameter(SELECT_MINKEYLENGTH); 465 if(value!= null){ 466 int val = Integer.parseInt(value); 467 enhprof.setMinimumKeyLength(EnhancedEIDProfile.CERTUSAGE_SIGN, val); 468 enhprof.setMinimumKeyLength(EnhancedEIDProfile.CERTUSAGE_AUTH, val); 469 enhprof.setMinimumKeyLength(EnhancedEIDProfile.CERTUSAGE_ENC, val); 470 enhprof.setKeyType(EnhancedEIDProfile.CERTUSAGE_SIGN, EIDProfile.KEYTYPE_RSA); 471 enhprof.setKeyType(EnhancedEIDProfile.CERTUSAGE_ENC, EIDProfile.KEYTYPE_RSA); 472 enhprof.setKeyType(EnhancedEIDProfile.CERTUSAGE_ENC, EIDProfile.KEYTYPE_RSA); 473 } 474 475 value = request.getParameter(CHECKBOX_CERTWRITABLE); 476 if(value != null){ 477 enhprof.setCertWritable(EnhancedEIDProfile.CERTUSAGE_SIGN, value.equals(CHECKBOX_VALUE)); 478 enhprof.setCertWritable(EnhancedEIDProfile.CERTUSAGE_AUTH, value.equals(CHECKBOX_VALUE)); 479 enhprof.setCertWritable(EnhancedEIDProfile.CERTUSAGE_ENC, value.equals(CHECKBOX_VALUE)); 480 }else{ 481 enhprof.setCertWritable(EnhancedEIDProfile.CERTUSAGE_SIGN, false); 482 enhprof.setCertWritable(EnhancedEIDProfile.CERTUSAGE_AUTH, false); 483 enhprof.setCertWritable(EnhancedEIDProfile.CERTUSAGE_ENC, false); 484 } 485 486 value = request.getParameter(SELECT_CERTIFICATEPROFILE + "0"); 487 if(value!= null) 488 enhprof.setCertificateProfileId(EnhancedEIDProfile.CERTUSAGE_SIGN, Integer.parseInt(value)); 489 490 value = request.getParameter(SELECT_CA + "0"); 491 if(value!= null) 492 enhprof.setCAId(EnhancedEIDProfile.CERTUSAGE_SIGN, Integer.parseInt(value)); 493 value = request.getParameter(SELECT_PINTYPE + "0"); 494 if(value!= null) 495 enhprof.setPINType(EnhancedEIDProfile.CERTUSAGE_SIGN, Integer.parseInt(value)); 496 value = request.getParameter(SELECT_MINPINLENGTH + "0"); 497 if(value!= null) 498 enhprof.setMinimumPINLength(EnhancedEIDProfile.CERTUSAGE_SIGN, Integer.parseInt(value)); 499 enhprof.setIsKeyRecoverable(EnhancedEIDProfile.CERTUSAGE_SIGN, false); 500 501 value = request.getParameter(SELECT_CERTIFICATEPROFILE + "1"); 502 if(value!= null) 503 enhprof.setCertificateProfileId(EnhancedEIDProfile.CERTUSAGE_AUTH, Integer.parseInt(value)); 504 505 value = request.getParameter(SELECT_CA + "1"); 506 if(value!= null) 507 enhprof.setCAId(EnhancedEIDProfile.CERTUSAGE_AUTH, Integer.parseInt(value)); 508 value = request.getParameter(SELECT_PINTYPE + "1"); 509 if(value!= null) 510 enhprof.setPINType(EnhancedEIDProfile.CERTUSAGE_AUTH, Integer.parseInt(value)); 511 value = request.getParameter(SELECT_MINPINLENGTH + "1"); 512 if(value!= null) 513 enhprof.setMinimumPINLength(EnhancedEIDProfile.CERTUSAGE_AUTH, Integer.parseInt(value)); 514 enhprof.setIsKeyRecoverable(EnhancedEIDProfile.CERTUSAGE_AUTH, false); 515 516 value = request.getParameter(SELECT_CERTIFICATEPROFILE + "2"); 517 if(value!= null) 518 enhprof.setCertificateProfileId(EnhancedEIDProfile.CERTUSAGE_ENC, Integer.parseInt(value)); 519 520 value = request.getParameter(SELECT_CA + "2"); 521 if(value!= null) 522 enhprof.setCAId(EnhancedEIDProfile.CERTUSAGE_ENC, Integer.parseInt(value)); 523 value = request.getParameter(SELECT_PINTYPE + "2"); 524 if(value!= null) 525 enhprof.setPINType(EnhancedEIDProfile.CERTUSAGE_ENC, Integer.parseInt(value)); 526 value = request.getParameter(SELECT_MINPINLENGTH + "2"); 527 if(value!= null) 528 enhprof.setMinimumPINLength(EnhancedEIDProfile.CERTUSAGE_ENC, Integer.parseInt(value)); 529 value = request.getParameter(CHECKBOX_KEYRECOVERABLE + "2"); 530 if(value != null) 531 enhprof.setIsKeyRecoverable(EnhancedEIDProfile.CERTUSAGE_ENC, value.equals(CHECKBOX_VALUE)); 532 else 533 enhprof.setIsKeyRecoverable(EnhancedEIDProfile.CERTUSAGE_ENC, false); 534 value = request.getParameter(CHECKBOX_REUSEOLDCERT + "2"); 535 if(value != null) 536 enhprof.setReuseOldCertificate(EnhancedEIDProfile.CERTUSAGE_ENC, value.equals(CHECKBOX_VALUE)); 537 else 538 enhprof.setReuseOldCertificate(EnhancedEIDProfile.CERTUSAGE_ENC, false); 539 540 541 } 542 543 544 if(request.getParameter(BUTTON_SAVE) != null){ 545 if(!handler.changeHardTokenProfile(profile,profiledata)){ 546 profilemalformed = true; 547 } 548 includefile=PAGE_HARDTOKENPROFILES; 549 } 550 if(request.getParameter(BUTTON_UPLOADENVELOPETEMP) != null){ 551 uploadmode = UPLOADMODE_ENVELOPE; 552 includefile=PAGE_UPLOADTEMPLATE; 553 } 554 if(request.getParameter(BUTTON_UPLOADVISUALTEMP) != null){ 555 uploadmode = UPLOADMODE_VISUAL; 556 includefile=PAGE_UPLOADTEMPLATE; 557 } 558 if(request.getParameter(BUTTON_UPLOADRECEIPTTEMP) != null){ 559 uploadmode = UPLOADMODE_RECEIPT; 560 includefile=PAGE_UPLOADTEMPLATE; 561 } 562 if(request.getParameter(BUTTON_UPLOADADRESSLABELTEMP) != null){ 563 uploadmode = UPLOADMODE_ADRESSLABEL; 564 includefile=PAGE_UPLOADTEMPLATE; 565 } 566 567 } 568 if(request.getParameter(BUTTON_CANCEL) != null){ 569 includefile=PAGE_HARDTOKENPROFILES; 571 } 572 573 } 574 } 575 } 576 577 if( action.equals(ACTION_CHANGE_PROFILETYPE)){ 578 this.profilename = request.getParameter(HIDDEN_HARDTOKENPROFILENAME); 579 String value = request.getParameter(SELECT_HARDTOKENTYPE); 580 if(value!=null){ 581 int profiletype = Integer.parseInt(value); 582 switch(profiletype){ 583 case SwedishEIDProfile.TYPE_SWEDISHEID : 584 profiledata = new SwedishEIDProfile(); 585 break; 586 case EnhancedEIDProfile.TYPE_ENHANCEDEID: 587 profiledata = new EnhancedEIDProfile(); 588 break; 589 case TurkishEIDProfile.TYPE_TURKISHEID: 590 profiledata = new TurkishEIDProfile(); 591 break; 592 } 593 } 594 595 includefile=PAGE_HARDTOKENPROFILE; 596 } 597 if( action.equals(ACTION_UPLOADENVELOPETEMP)){ 598 if(buttonupload){ 599 if(profiledata instanceof IPINEnvelopeSettings){ 600 try{ 601 BufferedReader br = new BufferedReader (new InputStreamReader (file,"UTF8")); 602 String filecontent = ""; 603 String nextline = ""; 604 while(nextline!=null){ 605 nextline = br.readLine(); 606 if(nextline != null) 607 filecontent += nextline + "\n"; 608 } 609 ((IPINEnvelopeSettings) profiledata).setPINEnvelopeData(filecontent); 610 ((IPINEnvelopeSettings) profiledata).setPINEnvelopeTemplateFilename(filename); 611 fileuploadsuccess = true; 612 }catch(IOException ioe){ 613 fileuploadfailed = true; 614 } 615 } 616 } 617 includefile=PAGE_HARDTOKENPROFILE; 618 } 619 if( action.equals(ACTION_UPLOADVISUALTEMP)){ 620 if(profiledata instanceof IVisualLayoutSettings){ 621 try{ 622 BufferedReader br = new BufferedReader (new InputStreamReader (file,"UTF8")); 623 String filecontent = ""; 624 String nextline = ""; 625 while(nextline!=null){ 626 nextline = br.readLine(); 627 if(nextline != null) 628 filecontent += nextline + "\n"; 629 } 630 ((IVisualLayoutSettings) profiledata).setVisualLayoutData(filecontent); 631 ((IVisualLayoutSettings) profiledata).setVisualLayoutTemplateFilename(filename); 632 fileuploadsuccess = true; 633 }catch(IOException ioe){ 634 fileuploadfailed = true; 635 } 636 } 637 includefile=PAGE_HARDTOKENPROFILE; 638 } 639 if( action.equals(ACTION_UPLOADRECEIPTTEMP)){ 640 if(profiledata instanceof IReceiptSettings){ 641 try{ 642 BufferedReader br = new BufferedReader (new InputStreamReader (file,"UTF8")); 643 String filecontent = ""; 644 String nextline = ""; 645 while(nextline!=null){ 646 nextline = br.readLine(); 647 if(nextline != null) 648 filecontent += nextline + "\n"; 649 } 650 ((IReceiptSettings) profiledata).setReceiptData(filecontent); 651 ((IReceiptSettings) profiledata).setReceiptTemplateFilename(filename); 652 fileuploadsuccess = true; 653 }catch(IOException ioe){ 654 fileuploadfailed = true; 655 } 656 } 657 includefile=PAGE_HARDTOKENPROFILE; 658 } 659 if( action.equals(ACTION_UPLOADADRESSLABELTEMP)){ 660 if(profiledata instanceof IAdressLabelSettings){ 661 try{ 662 BufferedReader br = new BufferedReader (new InputStreamReader (file,"UTF8")); 663 String filecontent = ""; 664 String nextline = ""; 665 while(nextline!=null){ 666 nextline = br.readLine(); 667 if(nextline != null) 668 filecontent += nextline + "\n"; 669 } 670 ((IAdressLabelSettings) profiledata).setAdressLabelData(filecontent); 671 ((IAdressLabelSettings) profiledata).setAdressLabelTemplateFilename(filename); 672 fileuploadsuccess = true; 673 }catch(IOException ioe){ 674 fileuploadfailed = true; 675 } 676 } 677 includefile=PAGE_HARDTOKENPROFILE; 678 } 679 680 } 681 682 return includefile; 683 } 684 685 public int getProfileType(){ 686 int retval = SwedishEIDProfile.TYPE_SWEDISHEID; 687 688 if(profiledata instanceof SwedishEIDProfile) 689 retval = SwedishEIDProfile.TYPE_SWEDISHEID; 690 691 if(profiledata instanceof EnhancedEIDProfile) 692 retval = EnhancedEIDProfile.TYPE_ENHANCEDEID; 693 694 if(profiledata instanceof TurkishEIDProfile) 695 retval = TurkishEIDProfile.TYPE_TURKISHEID; 696 697 return retval; 698 } 699 700 701 702 private HardTokenInterfaceBean hardtokenbean; 704 private boolean initialized=false; 705 public boolean hardtokenprofileexists = false; 706 public boolean profilemalformed = false; 707 public boolean hardtokenprofiledeletefailed = false; 708 public boolean issuperadministrator = false; 709 public boolean fileuploadsuccess = false; 710 public boolean fileuploadfailed = false; 711 public HardTokenProfile profiledata = null; 712 public String profilename = null; 713 public int uploadmode = 0; 714 715 } 716 | Popular Tags |