📄 edithardtokenprofilejsphelper.java
字号:
/************************************************************************* * * * EJBCA: The OpenSource Certificate Authority * * * * This software is free software; you can redistribute it and/or * * modify it under the terms of the GNU Lesser General Public * * License as published by the Free Software Foundation; either * * version 2.1 of the License, or any later version. * * * * See terms of license at gnu.org. * * * *************************************************************************/ package se.anatom.ejbca.webdist.hardtokeninterface;import java.io.*;import java.util.Iterator;import java.util.List;import javax.servlet.http.HttpServletRequest;import org.apache.commons.fileupload.*;import se.anatom.ejbca.authorization.AuthorizationDeniedException;import se.anatom.ejbca.hardtoken.HardTokenProfileExistsException;import se.anatom.ejbca.hardtoken.hardtokenprofiles.EIDProfile;import se.anatom.ejbca.hardtoken.hardtokenprofiles.EnhancedEIDProfile;import se.anatom.ejbca.hardtoken.hardtokenprofiles.HardTokenProfile;import se.anatom.ejbca.hardtoken.hardtokenprofiles.HardTokenProfileWithAdressLabel;import se.anatom.ejbca.hardtoken.hardtokenprofiles.HardTokenProfileWithPINEnvelope;import se.anatom.ejbca.hardtoken.hardtokenprofiles.HardTokenProfileWithReceipt;import se.anatom.ejbca.hardtoken.hardtokenprofiles.HardTokenProfileWithVisualLayout;import se.anatom.ejbca.hardtoken.hardtokenprofiles.IAdressLabelSettings;import se.anatom.ejbca.hardtoken.hardtokenprofiles.IPINEnvelopeSettings;import se.anatom.ejbca.hardtoken.hardtokenprofiles.IReceiptSettings;import se.anatom.ejbca.hardtoken.hardtokenprofiles.IVisualLayoutSettings;import se.anatom.ejbca.hardtoken.hardtokenprofiles.SwedishEIDProfile;import se.anatom.ejbca.webdist.webconfiguration.EjbcaWebBean;/** * Contains help methods used to parse a hard token profile jsp page requests. * * @author Philip Vendil * @version $Id: EditHardTokenProfileJSPHelper.java,v 1.10.2.1 2005/11/17 20:43:56 herrvendil Exp $ */public class EditHardTokenProfileJSPHelper implements java.io.Serializable { public static final String ACTION = "action"; public static final String ACTION_EDIT_HARDTOKENPROFILES = "edithardtokenprofiles"; public static final String ACTION_EDIT_HARDTOKENPROFILE = "edithardtokenprofile"; public static final String ACTION_UPLOADENVELOPETEMP = "uploadenvelopetemp"; public static final String ACTION_UPLOADVISUALTEMP = "uploadvisualtemp"; public static final String ACTION_UPLOADRECEIPTTEMP = "uploadreceipttemp"; public static final String ACTION_UPLOADADRESSLABELTEMP = "uploadadresstemp"; public static final String ACTION_CHANGE_PROFILETYPE = "changeprofiletype"; public static final String CHECKBOX_VALUE = HardTokenProfile.TRUE;// Used in profiles.jsp public static final String BUTTON_EDIT_HARDTOKENPROFILES = "buttonedithardtokenprofile"; public static final String BUTTON_DELETE_HARDTOKENPROFILES = "buttondeletehardtokenprofile"; public static final String BUTTON_ADD_HARDTOKENPROFILES = "buttonaddhardtokenprofile"; public static final String BUTTON_RENAME_HARDTOKENPROFILES = "buttonrenamehardtokenprofile"; public static final String BUTTON_CLONE_HARDTOKENPROFILES = "buttonclonehardtokenprofile"; public static final String SELECT_HARDTOKENPROFILES = "selecthardtokenprofile"; public static final String TEXTFIELD_HARDTOKENPROFILESNAME = "textfieldhardtokenprofilename"; public static final String HIDDEN_HARDTOKENPROFILENAME = "hiddenhardtokenprofilename"; // Buttons used in profile.jsp public static final String BUTTON_SAVE = "buttonsave"; public static final String BUTTON_CANCEL = "buttoncancel"; public static final String BUTTON_UPLOADENVELOPETEMP= "buttonuploadenvelopetemplate"; public static final String BUTTON_UPLOADVISUALTEMP = "buttonuploadvisualtemplate"; public static final String BUTTON_UPLOADRECEIPTTEMP = "buttonuploadreceipttemplate"; public static final String BUTTON_UPLOADADRESSLABELTEMP = "buttonuploadadresslabeltemplate"; public static final String BUTTON_UPLOADFILE = "buttonuploadfile"; public static final String TYPE_SWEDISHEID = "typeswedisheid"; public static final String TYPE_ENCHANCEDEID = "typeenchancedeid"; public static final String TEXTFIELD_VISUALVALIDITY = "textfieldvisualvalidity"; public static final String TEXTFIELD_SNPREFIX = "textfieldsnprefix"; public static final String CHECKBOX_EREASBLE = "checkboxereasable"; public static final String CHECKBOX_KEYRECOVERABLE = "checkboxkeyrecoverable"; public static final String CHECKBOX_REUSEOLDCERT = "checkboxreuseoldcert"; public static final String CHECKBOX_USEIDENTICALPINS= "useidenticalpins"; public static final String HIDDEN_HARDTOKENTYPE = "hiddenhardtokentype"; public static final String SELECT_HARDTOKENTYPE = "selecthardtokentype"; public static final String SELECT_CERTIFICATEPROFILE = "selectcertificateprofile"; public static final String SELECT_CA = "selectca"; public static final String SELECT_PINTYPE = "selectpintype"; public static final String SELECT_MINKEYLENGTH = "selectminkeylength"; public static final String SELECT_ENVELOPETYPE = "selectenvelopetype"; public static final String SELECT_NUMOFENVELOPECOPIES= "selectenvelopecopies"; public static final String SELECT_RECEIPTTYPE = "selectreceipttype"; public static final String SELECT_NUMOFRECEIPTCOPIES = "selectreceiptcopies"; public static final String SELECT_ADRESSLABELTYPE = "selectadresslabeltype"; public static final String SELECT_NUMOFADRESSLABELCOPIES = "selectadresslabelcopies"; public static final String SELECT_VISUALLAYOUTTYPE = "selectvisuallayouttype"; public static final String SELECT_NUMOFTOKENCOPIES = "selectnumoftokencopies"; public static final String SELECT_MINPINLENGTH = "selectminpinlength"; public static final String FILE_TEMPLATE = "filetemplate"; public static final int UPLOADMODE_ENVELOPE = 0; public static final int UPLOADMODE_VISUAL = 1; public static final int UPLOADMODE_RECEIPT = 2; public static final int UPLOADMODE_ADRESSLABEL = 3; public static final String PAGE_HARDTOKENPROFILE = "hardtokenprofilepage.jspf"; public static final String PAGE_HARDTOKENPROFILES = "hardtokenprofilespage.jspf"; public static final String PAGE_UPLOADTEMPLATE = "uploadtemplate.jspf"; /** Creates new LogInterfaceBean */ public EditHardTokenProfileJSPHelper(){ } // Public methods. /** * Method that initialized the bean. * * @param request is a reference to the http request. */ public void initialize(EjbcaWebBean ejbcawebbean, HardTokenInterfaceBean hardtokenbean) throws Exception{ if(!initialized){ this.hardtokenbean = hardtokenbean; initialized = true; issuperadministrator = false; try{ issuperadministrator = ejbcawebbean.isAuthorizedNoLog("/super_administrator"); }catch(AuthorizationDeniedException ade){} } } public String parseRequest(HttpServletRequest request) throws AuthorizationDeniedException{ String includefile = PAGE_HARDTOKENPROFILES; String profile = null; HardTokenProfileDataHandler handler = hardtokenbean.getHardTokenProfileDataHandler(); String action = null; InputStream file = null; boolean buttonupload = false; String filename = null; if(FileUploadBase.isMultipartContent(request)){ try{ DiskFileUpload upload = new DiskFileUpload(); upload.setSizeMax(2000000); upload.setSizeThreshold(1999999); List /* FileItem */ items = upload.parseRequest(request); Iterator iter = items.iterator(); while (iter.hasNext()) { FileItem item = (FileItem) iter.next(); if (item.isFormField()) { if(item.getFieldName().equals(ACTION)) action = item.getString(); if(item.getFieldName().equals(HIDDEN_HARDTOKENPROFILENAME)) profilename = item.getString(); if(item.getFieldName().equals(BUTTON_CANCEL)) { // do nothing } if(item.getFieldName().equals(BUTTON_UPLOADFILE)) buttonupload = true; }else{ file = item.getInputStream(); filename = item.getName(); } } }catch(IOException e){ fileuploadfailed = true; includefile=PAGE_HARDTOKENPROFILE; }catch(FileUploadException e){ fileuploadfailed = true; includefile=PAGE_HARDTOKENPROFILE; } }else{ action = request.getParameter(ACTION); } if( action != null){ if( action.equals(ACTION_EDIT_HARDTOKENPROFILES)){ if( request.getParameter(BUTTON_EDIT_HARDTOKENPROFILES) != null){ // Display profilepage.jsp profile = request.getParameter(SELECT_HARDTOKENPROFILES); if(profile != null){ if(!profile.trim().equals("")){ includefile=PAGE_HARDTOKENPROFILE; this.profilename = profile; this.profiledata = handler.getHardTokenProfile(profilename); } else{ profile= null; } } if(profile == null){ includefile=PAGE_HARDTOKENPROFILES; } } if( request.getParameter(BUTTON_DELETE_HARDTOKENPROFILES) != null) { // Delete profile and display profilespage. profile = request.getParameter(SELECT_HARDTOKENPROFILES); if(profile != null){ if(!profile.trim().equals("")){ hardtokenprofiledeletefailed = handler.removeHardTokenProfile(profile); } } includefile=PAGE_HARDTOKENPROFILES; } if( request.getParameter(BUTTON_RENAME_HARDTOKENPROFILES) != null){ // Rename selected profile and display profilespage. String newhardtokenprofilename = request.getParameter(TEXTFIELD_HARDTOKENPROFILESNAME); String oldhardtokenprofilename = request.getParameter(SELECT_HARDTOKENPROFILES); if(oldhardtokenprofilename != null && newhardtokenprofilename != null){ if(!newhardtokenprofilename.trim().equals("") && !oldhardtokenprofilename.trim().equals("")){ try{ handler.renameHardTokenProfile(oldhardtokenprofilename.trim(),newhardtokenprofilename.trim()); }catch( HardTokenProfileExistsException e){ hardtokenprofileexists=true; } } } includefile=PAGE_HARDTOKENPROFILES; } if( request.getParameter(BUTTON_ADD_HARDTOKENPROFILES) != null){ // Add profile and display profilespage. profile = request.getParameter(TEXTFIELD_HARDTOKENPROFILESNAME); if(profile != null){ if(!profile.trim().equals("")){ try{ if(!handler.addHardTokenProfile(profile.trim(), new SwedishEIDProfile())){ profilemalformed = true; } }catch( HardTokenProfileExistsException e){ hardtokenprofileexists=true; } } } includefile=PAGE_HARDTOKENPROFILES; } if( request.getParameter(BUTTON_CLONE_HARDTOKENPROFILES) != null){ // clone profile and display profilespage. String newhardtokenprofilename = request.getParameter(TEXTFIELD_HARDTOKENPROFILESNAME); String oldhardtokenprofilename = request.getParameter(SELECT_HARDTOKENPROFILES); if(oldhardtokenprofilename != null && newhardtokenprofilename != null){ if(!newhardtokenprofilename.trim().equals("") && !oldhardtokenprofilename.trim().equals("")){ try{ handler.cloneHardTokenProfile(oldhardtokenprofilename.trim(),newhardtokenprofilename.trim()); }catch(HardTokenProfileExistsException e){ hardtokenprofileexists=true; } } } includefile=PAGE_HARDTOKENPROFILES; } } if( action.equals(ACTION_EDIT_HARDTOKENPROFILE)){ // Display edit access rules page. profile = request.getParameter(HIDDEN_HARDTOKENPROFILENAME); if(profile != null){ if(!profile.trim().equals("")){ if(request.getParameter(BUTTON_SAVE) != null || request.getParameter(BUTTON_UPLOADENVELOPETEMP) != null || request.getParameter(BUTTON_UPLOADVISUALTEMP) != null || request.getParameter(BUTTON_UPLOADRECEIPTTEMP) != null || request.getParameter(BUTTON_UPLOADADRESSLABELTEMP) != null ){ if(profiledata == null){ String tokentype = request.getParameter(HIDDEN_HARDTOKENTYPE); if(tokentype.equals(TYPE_SWEDISHEID)) profiledata = new SwedishEIDProfile(); if(tokentype.equals(TYPE_ENCHANCEDEID)) profiledata = new EnhancedEIDProfile(); } // Save changes. // General settings String value = request.getParameter(TEXTFIELD_SNPREFIX); if(value != null){ value = value.trim(); profiledata.setHardTokenSNPrefix(value); } value = request.getParameter(CHECKBOX_EREASBLE); if(value != null){ profiledata.setEreasableToken(value.equals(CHECKBOX_VALUE)); }else profiledata.setEreasableToken(false); value = request.getParameter(SELECT_NUMOFTOKENCOPIES); if(value != null){ profiledata.setNumberOfCopies(Integer.parseInt(value)); } value = request.getParameter(CHECKBOX_USEIDENTICALPINS); if(value != null){ profiledata.setGenerateIdenticalPINForCopies(value.equals(CHECKBOX_VALUE)); }else
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -