1 13 14 package org.ejbca.ui.web.admin.rainterface; 15 16 import java.util.Date ; 17 import java.util.Iterator ; 18 import java.util.List ; 19 import java.util.TreeMap ; 20 21 import javax.servlet.ServletException ; 22 import javax.servlet.http.HttpServletRequest ; 23 24 import org.ejbca.core.model.authorization.AuthorizationDeniedException; 25 import org.ejbca.core.model.ca.store.CertReqHistory; 26 import org.ejbca.core.model.ra.UserDataConstants; 27 import org.ejbca.core.model.ra.raadmin.EndEntityProfile; 28 import org.ejbca.ui.web.RequestHelper; 29 import org.ejbca.ui.web.admin.cainterface.CAInterfaceBean; 30 import org.ejbca.ui.web.admin.configuration.EjbcaWebBean; 31 32 33 34 40 41 public class ViewEndEntityHelper implements java.io.Serializable { 42 43 44 public static final String USER_PARAMETER = "username"; 45 public static final String TIMESTAMP_PARAMETER = "timestamp"; 46 47 public static final String BUTTON_CLOSE = "buttonclose"; 48 public static final String BUTTON_PREVIOUS = "buttonprevious"; 49 public static final String BUTTON_NEXT = "buttonnext"; 50 51 public static final String ACTION = "action"; 52 public static final String ACTION_PAGE = "actionpage"; 53 54 public static final String HIDDEN_USERNAME = "hiddenusername"; 55 public static final String HIDDEN_INDEX = "hiddenindex"; 56 57 public static final String CHECKBOX_CLEARTEXTPASSWORD = "checkboxcleartextpassword"; 58 public static final String CHECKBOX_ADMINISTRATOR = "checkboxadministrator"; 59 public static final String CHECKBOX_KEYRECOVERABLE = "checkboxkeyrecoverable"; 60 public static final String CHECKBOX_SENDNOTIFICATION = "checkboxsendnotification"; 61 public static final String CHECKBOX_PRINT = "checkboxprint"; 62 63 public static final String CHECKBOX_VALUE = "true"; 64 65 public static final int[] statusids = {UserDataConstants.STATUS_NEW ,UserDataConstants.STATUS_FAILED, UserDataConstants.STATUS_INITIALIZED, UserDataConstants.STATUS_INPROCESS 66 , UserDataConstants.STATUS_GENERATED, UserDataConstants.STATUS_REVOKED , UserDataConstants.STATUS_HISTORICAL, UserDataConstants.STATUS_KEYRECOVERY}; 67 68 public static final String [] statustexts = {"STATUSNEW", "STATUSFAILED", "STATUSINITIALIZED", "STATUSINPROCESS", "STATUSGENERATED", "STATUSREVOKED", "STATUSHISTORICAL", "STATUSKEYRECOVERY"}; 69 70 public static final int columnwidth = 200; 71 72 public boolean nouserparameter = true; 73 public boolean notauthorized = false; 74 public boolean profilenotfound = true; 75 76 public UserView userdata = null; 77 public UserView[] userdatas = null; 78 public String username = null; 79 public EndEntityProfile profile = null; 80 public int[] fielddata = null; 81 public String fieldvalue = null; 82 83 public int row = 0; 84 85 public int currentuserindex = 0; 86 87 public String [] tokentexts = RAInterfaceBean.tokentexts; 88 public int[] tokenids = RAInterfaceBean.tokenids; 89 90 private boolean initialized; 91 92 private RAInterfaceBean rabean; 93 private EjbcaWebBean ejbcawebbean; 94 private CAInterfaceBean cabean; 95 private String currentusername=null; 96 97 98 104 public void initialize(EjbcaWebBean ejbcawebbean, 105 RAInterfaceBean rabean, CAInterfaceBean cabean) throws Exception { 106 107 if(!initialized){ 108 109 this.rabean = rabean; 110 this.ejbcawebbean = ejbcawebbean; 111 this.cabean = cabean; 112 initialized = true; 113 114 if(ejbcawebbean.getGlobalConfiguration().getIssueHardwareTokens()){ 115 TreeMap hardtokenprofiles = ejbcawebbean.getInformationMemory().getHardTokenProfiles(); 116 117 tokentexts = new String [RAInterfaceBean.tokentexts.length + hardtokenprofiles.keySet().size()]; 118 tokenids = new int[tokentexts.length]; 119 for(int i=0; i < RAInterfaceBean.tokentexts.length; i++){ 120 tokentexts[i]= RAInterfaceBean.tokentexts[i]; 121 tokenids[i] = RAInterfaceBean.tokenids[i]; 122 } 123 Iterator iter = hardtokenprofiles.keySet().iterator(); 124 int index=0; 125 while(iter.hasNext()){ 126 String name = (String ) iter.next(); 127 tokentexts[index+RAInterfaceBean.tokentexts.length]= name; 128 tokenids[index+RAInterfaceBean.tokentexts.length] = ((Integer ) hardtokenprofiles.get(name)).intValue(); 129 index++; 130 } 131 } 132 133 } 134 } 135 136 public void parseRequest(HttpServletRequest request) throws AuthorizationDeniedException, Exception { 137 nouserparameter=true; 138 notauthorized = false; 139 profilenotfound = true; 140 141 RequestHelper.setDefaultCharacterEncoding(request); 142 String action = request.getParameter(ACTION); 143 if( action == null && request.getParameter(TIMESTAMP_PARAMETER) != null && request.getParameter(USER_PARAMETER) != null){ 144 username = java.net.URLDecoder.decode(request.getParameter(USER_PARAMETER),"UTF-8"); 145 Date timestamp = new Date (Long.parseLong(request.getParameter(TIMESTAMP_PARAMETER))); 146 147 notauthorized = !getUserDatas(username); 148 currentuserindex = this.getTimeStampIndex(timestamp); 149 if ( userdatas == null || userdatas.length < 1 ) { 150 throw new ServletException ("Could not find any history for this user."); 151 } 152 userdata = userdatas[currentuserindex]; 153 154 nouserparameter = false; 155 if(userdata!=null) 156 profile = rabean.getEndEntityProfile(userdata.getEndEntityProfileId()); 157 }else{ 158 if(action == null && request.getParameter(USER_PARAMETER) != null){ 159 username = java.net.URLDecoder.decode(request.getParameter(USER_PARAMETER),"UTF-8"); 160 161 notauthorized = !getUserDatas(username); 162 userdata = userdatas[0]; 163 currentuserindex = 0; 164 165 nouserparameter = false; 166 if(userdata!=null) 167 profile = rabean.getEndEntityProfile(userdata.getEndEntityProfileId()); 168 }else{ 169 170 if( action != null && request.getParameter(USER_PARAMETER)!=null){ 171 username = java.net.URLDecoder.decode(request.getParameter(USER_PARAMETER),"UTF-8"); 172 if(request.getParameter(BUTTON_PREVIOUS)!=null){ 173 if(currentuserindex>0){ 174 currentuserindex--; 175 } 176 } 177 if(request.getParameter(BUTTON_NEXT)!=null){ 178 if(currentuserindex +1<userdatas.length){ 179 currentuserindex++; 180 } 181 } 182 183 notauthorized = !getUserDatas(username); 184 userdata = userdatas[currentuserindex]; 185 186 nouserparameter = false; 187 if(userdata!=null) 188 profile = rabean.getEndEntityProfile(userdata.getEndEntityProfileId()); 189 } 190 } 191 } 192 193 if(profile!=null){ 194 profilenotfound=false; 195 } 196 } 197 198 199 202 203 private boolean getUserDatas(String username) throws Exception { 204 boolean authorized = false; 205 206 try{ 207 if(currentusername == null || !currentusername.equals(username)){ 208 int currentexists = 0; 210 UserView currentuser = rabean.findUser(username); 211 if(currentuser != null){ 212 currentexists = 1; 213 } 214 List hist = cabean.getCertReqUserDatas(username); 215 216 userdatas = new UserView[hist.size() +currentexists]; 217 218 if(currentuser != null){ 219 userdatas[0] = currentuser; 220 } 221 for(int i=0; i< hist.size();i++){ 222 CertReqHistory next = ((CertReqHistory) hist.get(i)); 223 userdatas[i+currentexists] = new UserView(next.getUserDataVO(),ejbcawebbean.getInformationMemory().getCAIdToNameMap()); 224 } 225 226 } 227 authorized=true; 228 } catch(AuthorizationDeniedException e){ } 229 return authorized; 230 } 231 232 238 private int getTimeStampIndex(Date timestamp){ 239 int i; 240 241 for(i=0;i< userdatas.length;i++){ 242 if(timestamp.after(userdatas[i].getTimeModified())|| 243 timestamp.equals(userdatas[i].getTimeModified())){ 244 break; 245 } 246 } 247 248 return i; 249 } 250 251 252 } 253 | Popular Tags |