KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > ejbca > ui > web > admin > cainterface > ViewCAInfoJSPHelper


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.cainterface;
15
16 import java.security.cert.X509Certificate JavaDoc;
17
18 import javax.servlet.http.HttpServletRequest JavaDoc;
19
20 import org.ejbca.core.model.SecConst;
21 import org.ejbca.core.model.authorization.AuthorizationDeniedException;
22 import org.ejbca.core.model.authorization.AvailableAccessRules;
23 import org.ejbca.core.model.ca.catoken.CATokenAuthenticationFailedException;
24 import org.ejbca.core.model.ca.catoken.CATokenOfflineException;
25 import org.ejbca.core.model.ca.catoken.HardCATokenInfo;
26 import org.ejbca.core.model.ca.catoken.IHardCAToken;
27 import org.ejbca.ui.web.RequestHelper;
28 import org.ejbca.ui.web.admin.configuration.EjbcaWebBean;
29
30
31 /**
32  * Contains help methods used to parse a viewcainfo jsp page requests.
33  *
34  * @author Philip Vendil
35  * @version $Id: ViewCAInfoJSPHelper.java,v 1.3.10.1 2007/06/15 09:07:51 jeklund Exp $
36  */

37 public class ViewCAInfoJSPHelper implements java.io.Serializable JavaDoc {
38          
39     public static final String JavaDoc CA_PARAMETER = "caid";
40
41     public static final String JavaDoc CERTSERNO_PARAMETER = "certsernoparameter";
42       
43     public static final String JavaDoc PASSWORD_AUTHENTICATIONCODE = "passwordactivationcode";
44       
45     public static final String JavaDoc BUTTON_ACTIVATE = "buttonactivate";
46     public static final String JavaDoc BUTTON_MAKEOFFLINE = "buttonmakeoffline";
47     public static final String JavaDoc BUTTON_CLOSE = "buttonclose";
48
49
50     /** Creates new LogInterfaceBean */
51     public ViewCAInfoJSPHelper(){
52     }
53     // Public methods.
54
/**
55      * Method that initialized the bean.
56      *
57      * @param request is a reference to the http request.
58      */

59     public void initialize(HttpServletRequest JavaDoc request, EjbcaWebBean ejbcawebbean,
60                            CAInterfaceBean cabean) throws Exception JavaDoc{
61
62       if(!initialized){
63         this.cabean = cabean;
64         initialized = true;
65         can_activate = false;
66         authorized = false;
67         try{
68             authorized = ejbcawebbean.isAuthorizedNoLog(AvailableAccessRules.REGULAR_CABASICFUNCTIONS);
69             can_activate = ejbcawebbean.isAuthorizedNoLog(AvailableAccessRules.REGULAR_ACTIVATECA);
70         }catch(AuthorizationDeniedException ade){}
71       }
72     }
73
74     /**
75      * Method that parses the request and take appropriate actions.
76      * @param request the http request
77      * @throws Exception
78      */

79     public void parseRequest(HttpServletRequest JavaDoc request) throws Exception JavaDoc{
80           generalerrormessage = null;
81           activationerrormessage = null;
82           activationmessage = null;
83           ishardcatoken = false;
84          
85           RequestHelper.setDefaultCharacterEncoding(request);
86
87           if( request.getParameter(CA_PARAMETER) != null ){
88             caid = Integer.parseInt(request.getParameter(CA_PARAMETER));
89                             
90             if(request.getParameter(BUTTON_ACTIVATE) != null || request.getParameter(BUTTON_MAKEOFFLINE) != null){
91               // Get currentstate
92
status = SecConst.CA_OFFLINE;
93               try{
94                 cainfo = cabean.getCAInfo(caid);
95                 status = cainfo.getCAInfo().getStatus();
96                 if( cainfo.getCAInfo().getCATokenInfo() instanceof HardCATokenInfo ){
97                     ishardcatoken = true;
98                 }
99               } catch(AuthorizationDeniedException e){
100                 generalerrormessage = "NOTAUTHORIZEDTOVIEWCA";
101                 return;
102               }
103               
104               // If Activate button is pressed, the admin is authorized and the current status is offline then activate.
105
if(request.getParameter(BUTTON_ACTIVATE) != null &&
106                  can_activate &&
107                  ishardcatoken &&
108                  ((status == SecConst.CA_OFFLINE) ||
109                    (status == SecConst.CA_ACTIVE &&
110                    ((HardCATokenInfo) cainfo.getCAInfo().getCATokenInfo()).getCATokenStatus() == IHardCAToken.STATUS_OFFLINE))){
111                  
112                  String JavaDoc authorizationcode = request.getParameter(PASSWORD_AUTHENTICATIONCODE);
113                  try {
114                      cabean.getCADataHandler().activateCAToken(caid,authorizationcode);
115                      activationmessage = "CAACTIVATIONSUCCESSFUL";
116                  } catch (CATokenAuthenticationFailedException catafe) {
117                      activationerrormessage = "AUTHENTICATIONERROR";
118                      activationerrorreason = catafe.getMessage();
119                  } catch (CATokenOfflineException catoe) {
120                      activationerrormessage = "ERROR";
121                      activationerrorreason = catoe.getMessage();
122                  }
123               }
124               // If Activate button is pressed, the admin is authorized and the current status is offline then activate.
125
if(request.getParameter(BUTTON_MAKEOFFLINE) != null &&
126                  can_activate &&
127                  ishardcatoken &&
128                  status == SecConst.CA_ACTIVE){
129                  
130                  try{
131                    cabean.getCADataHandler().deactivateCAToken(caid);
132                    activationmessage = "MAKEOFFLINESUCCESSFUL";
133                  }catch(Exception JavaDoc e){
134                     throw e;
135                  }
136               }
137             }
138                                                                               
139             
140             try{
141               cainfo = cabean.getCAInfo(caid);
142               status = cainfo.getCAInfo().getStatus();
143               if( cainfo.getCAInfo().getCATokenInfo() instanceof HardCATokenInfo ){
144                 ishardcatoken = true;
145                 hardtokenoffline = ((HardCATokenInfo) cainfo.getCAInfo().getCATokenInfo()).getCATokenStatus() == IHardCAToken.STATUS_OFFLINE;
146               }
147               ocspcert = cainfo.getOCSPSignerCertificate();
148             } catch(AuthorizationDeniedException e){
149                 generalerrormessage = "NOTAUTHORIZEDTOVIEWCA";
150             }
151
152             if(cainfo==null){
153               generalerrormessage = "CADOESNTEXIST";
154             }
155           }else{
156             generalerrormessage = "YOUMUSTSPECIFYCAID";
157           }
158   
159     }
160
161     
162        
163     // Private fields.
164
private CAInterfaceBean cabean;
165     private boolean initialized=false;
166     public String JavaDoc generalerrormessage = null;
167     public String JavaDoc activationerrormessage = null;
168     public String JavaDoc activationerrorreason = null;
169     public String JavaDoc activationmessage = null;
170     public boolean can_activate = false;
171     public boolean authorized = false;
172     public boolean ishardcatoken = false;
173     public CAInfoView cainfo = null;
174     public int status = 0;
175     public boolean hardtokenoffline = false;
176     public int caid = 0;
177     public X509Certificate JavaDoc ocspcert = null;
178     
179     
180 }
181
Popular Tags