KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > ejbca > ui > web > admin > rainterface > ViewEndEntityHelper


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.rainterface;
15
16 import java.util.Date JavaDoc;
17 import java.util.Iterator JavaDoc;
18 import java.util.List JavaDoc;
19 import java.util.TreeMap JavaDoc;
20
21 import javax.servlet.ServletException JavaDoc;
22 import javax.servlet.http.HttpServletRequest JavaDoc;
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 /**
35  * Helper class for the View End Entity Page, parses the request and performs apporiate actions.
36  *
37  * @author Philip Vendil
38  * @version $Id: ViewEndEntityHelper.java,v 1.5.2.1 2007/05/08 14:06:21 jeklund Exp $
39  */

40
41 public class ViewEndEntityHelper implements java.io.Serializable JavaDoc{
42
43     
44     public static final String JavaDoc USER_PARAMETER = "username";
45     public static final String JavaDoc TIMESTAMP_PARAMETER = "timestamp";
46     
47     public static final String JavaDoc BUTTON_CLOSE = "buttonclose";
48     public static final String JavaDoc BUTTON_PREVIOUS = "buttonprevious";
49     public static final String JavaDoc BUTTON_NEXT = "buttonnext";
50     
51     public static final String JavaDoc ACTION = "action";
52     public static final String JavaDoc ACTION_PAGE = "actionpage";
53     
54     public static final String JavaDoc HIDDEN_USERNAME = "hiddenusername";
55     public static final String JavaDoc HIDDEN_INDEX = "hiddenindex";
56     
57     public static final String JavaDoc CHECKBOX_CLEARTEXTPASSWORD = "checkboxcleartextpassword";
58     public static final String JavaDoc CHECKBOX_ADMINISTRATOR = "checkboxadministrator";
59     public static final String JavaDoc CHECKBOX_KEYRECOVERABLE = "checkboxkeyrecoverable";
60     public static final String JavaDoc CHECKBOX_SENDNOTIFICATION = "checkboxsendnotification";
61     public static final String JavaDoc CHECKBOX_PRINT = "checkboxprint";
62     
63     public static final String JavaDoc 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 JavaDoc[] 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 JavaDoc username = null;
79     public EndEntityProfile profile = null;
80     public int[] fielddata = null;
81     public String JavaDoc fieldvalue = null;
82     
83     public int row = 0;
84     
85     public int currentuserindex = 0;
86     
87     public String JavaDoc[] 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 JavaDoc currentusername=null;
96     
97     
98        // Public methods.
99
/**
100      * Method that initialized the bean.
101      *
102      * @param request is a reference to the http request.
103      */

104     public void initialize(EjbcaWebBean ejbcawebbean,
105                            RAInterfaceBean rabean, CAInterfaceBean cabean) throws Exception JavaDoc{
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 JavaDoc hardtokenprofiles = ejbcawebbean.getInformationMemory().getHardTokenProfiles();
116
117             tokentexts = new String JavaDoc[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 JavaDoc iter = hardtokenprofiles.keySet().iterator();
124             int index=0;
125             while(iter.hasNext()){
126               String JavaDoc name = (String JavaDoc) iter.next();
127               tokentexts[index+RAInterfaceBean.tokentexts.length]= name;
128               tokenids[index+RAInterfaceBean.tokentexts.length] = ((Integer JavaDoc) hardtokenprofiles.get(name)).intValue();
129               index++;
130             }
131          }
132         
133       }
134     }
135     
136     public void parseRequest(HttpServletRequest JavaDoc request) throws AuthorizationDeniedException, Exception JavaDoc{
137           nouserparameter=true;
138           notauthorized = false;
139           profilenotfound = true;
140           
141           RequestHelper.setDefaultCharacterEncoding(request);
142           String JavaDoc 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 JavaDoc timestamp = new Date JavaDoc(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 JavaDoc("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     /* returns false if the admin isn't authorized to view user
200      * Sets the vaiable userdatas of current and previous values
201      */

202     
203     private boolean getUserDatas(String JavaDoc username) throws Exception JavaDoc{
204       boolean authorized = false;
205     
206       try{
207           if(currentusername == null || !currentusername.equals(username)){
208               // fetch userdata and certreqdatas and order them by timestamp, newest first.
209
int currentexists = 0;
210               UserView currentuser = rabean.findUser(username);
211               if(currentuser != null){
212                   currentexists = 1;
213               }
214               List JavaDoc 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     /**
233      * Returns an Index to the user that related to a certain timestamp.
234      *
235      * @param timestamp parameter sent from view log page
236      * @return index in user datas that should be shown.
237      */

238     private int getTimeStampIndex(Date JavaDoc 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