KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > ejbca > core > protocol > xkms > generators > RecoverResponseGenerator


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.core.protocol.xkms.generators;
15
16 import java.security.cert.X509Certificate JavaDoc;
17
18 import org.ejbca.core.model.ra.UserDataVO;
19 import org.ejbca.core.protocol.xkms.common.XKMSConstants;
20 import org.w3._2002._03.xkms_.KeyBindingAbstractType;
21 import org.w3._2002._03.xkms_.KeyBindingType;
22 import org.w3._2002._03.xkms_.RecoverRequestType;
23 import org.w3._2002._03.xkms_.RecoverResultType;
24 import org.w3c.dom.Document JavaDoc;
25
26 /**
27  * Class generating a response for a recover call
28  *
29  *
30  * @author Philip Vendil
31  *
32  * @version $Id: RecoverResponseGenerator.java,v 1.1 2007/01/05 05:32:51 herrvendil Exp $
33  */

34
35 public class RecoverResponseGenerator extends
36         KRSSResponseGenerator {
37     //private static Logger log = Logger.getLogger(RecoverResponseGenerator.class);
38

39     public RecoverResponseGenerator(String JavaDoc remoteIP, RecoverRequestType req, Document JavaDoc requestDoc) {
40         super(remoteIP, req,requestDoc);
41     }
42     
43     /**
44      * Returns a register response
45      */

46     public RecoverResultType getResponse(boolean requestVerifies){
47         RecoverResultType result = xkmsFactory.createRecoverResultType();
48         super.populateResponse(result, requestVerifies);
49         RecoverRequestType req = (RecoverRequestType) this.req;
50         
51
52         if(resultMajor == null){
53             if(!checkValidRespondWithRequest(req.getRespondWith(),false)){
54                 resultMajor = XKMSConstants.RESULTMAJOR_SENDER;
55                 resultMinor = XKMSConstants.RESULTMINOR_MESSAGENOTSUPPORTED;
56             }
57
58             if(resultMajor == null){
59                 if(resultMajor == null){
60                     X509Certificate JavaDoc cert = (X509Certificate JavaDoc) getPublicKeyInfo(req, false);
61                     
62                     UserDataVO userData = findUserData(cert);
63                     if(userData != null){
64                         String JavaDoc password = "";
65                         boolean encryptedPassword = isPasswordEncrypted(req);
66                         if(encryptedPassword){
67                             password = getEncryptedPassword(requestDoc, userData.getPassword());
68                         }else{
69                             password = getClearPassword(req, userData.getPassword());
70                         }
71
72                         if(password != null ){
73                             X509Certificate JavaDoc newCert = registerReissueOrRecover(true,false, result, userData,password, cert.getPublicKey(), null);
74                             if(newCert != null){
75                                 KeyBindingAbstractType keyBinding = getResponseValues(req.getRecoverKeyBinding(), newCert, false, true);
76                                 result.getKeyBinding().add((KeyBindingType) keyBinding);
77                             }
78                         }
79                     }
80
81                 }
82             }
83         }
84         
85         if(resultMajor == null){
86             resultMajor = XKMSConstants.RESULTMAJOR_SUCCESS;
87         }
88                    
89         setResult(result);
90         
91         return result;
92     }
93
94
95     
96
97
98
99     
100 }
101
Popular Tags