KickJava   Java API By Example, From Geeks To Geeks.

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


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

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

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

47     public RegisterResultType getResponse(boolean requestVerifies){
48         RegisterResultType result = xkmsFactory.createRegisterResultType();
49         super.populateResponse(result, requestVerifies);
50         RegisterRequestType req = (RegisterRequestType) this.req;
51         
52
53         if(resultMajor == null){
54             if(!checkValidRespondWithRequest(req.getRespondWith(),false)){
55                 resultMajor = XKMSConstants.RESULTMAJOR_SENDER;
56                 resultMinor = XKMSConstants.RESULTMINOR_MESSAGENOTSUPPORTED;
57             }
58
59             if(resultMajor == null){
60                 
61
62                 if(resultMajor == null){
63                     PublicKey JavaDoc publicKey = getPublicKey(req);
64                     if(confirmPOP(publicKey)){
65                         String JavaDoc subjectDN = getSubjectDN(req);
66                         UserDataVO userData = findUserData(subjectDN);
67                         if(userData != null){
68                             String JavaDoc password = "";
69                             boolean encryptedPassword = isPasswordEncrypted(req);
70                             if(encryptedPassword){
71                                 password = getEncryptedPassword(requestDoc, userData.getPassword());
72                             }else{
73                                 password = getClearPassword(req, userData.getPassword());
74                             }
75                             String JavaDoc revocationCode = getRevocationCode(req);
76                             if(password != null ){
77                                 X509Certificate JavaDoc cert = registerReissueOrRecover(false,false, result, userData,password, publicKey, revocationCode);
78                                 if(cert != null){
79                                     KeyBindingAbstractType keyBinding = getResponseValues(req.getPrototypeKeyBinding(), cert, false, true);
80                                     result.getKeyBinding().add((KeyBindingType) keyBinding);
81                                 }
82                             }
83                         }
84                     }
85                 }
86             }
87         }
88         
89         if(resultMajor == null){
90             resultMajor = XKMSConstants.RESULTMAJOR_SUCCESS;
91         }
92                    
93         setResult(result);
94         
95         return result;
96     }
97
98     /**
99      * Method extracting the public key from the message.
100      * @param req the request
101      * @return the public key or null if no public key could be found.
102      */

103     protected PublicKey JavaDoc getPublicKey(RegisterRequestType req){
104         Object JavaDoc retval = getPublicKeyInfo(req, true);
105         if(retval instanceof X509Certificate JavaDoc){
106             retval = ((X509Certificate JavaDoc) retval).getPublicKey();
107         }
108
109         
110         return (PublicKey JavaDoc) retval;
111     }
112     
113
114
115
116
117     
118 }
119
Popular Tags