KickJava   Java API By Example, From Geeks To Geeks.

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


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.apache.log4j.Logger;
19 import org.ejbca.core.model.InternalResources;
20 import org.ejbca.core.model.ra.UserDataConstants;
21 import org.ejbca.core.model.ra.UserDataVO;
22 import org.ejbca.core.protocol.xkms.common.XKMSConstants;
23 import org.ejbca.util.passgen.IPasswordGenerator;
24 import org.ejbca.util.passgen.PasswordGeneratorFactory;
25 import org.w3._2002._03.xkms_.KeyBindingAbstractType;
26 import org.w3._2002._03.xkms_.KeyBindingType;
27 import org.w3._2002._03.xkms_.ReissueRequestType;
28 import org.w3._2002._03.xkms_.ReissueResultType;
29 import org.w3c.dom.Document JavaDoc;
30
31 /**
32  * Class generating a response for a reissue call
33  *
34  *
35  * @author Philip Vendil
36  *
37  * @version $Id: ReissueResponseGenerator.java,v 1.2 2007/01/07 19:44:14 herrvendil Exp $
38  */

39
40 public class ReissueResponseGenerator extends
41         KRSSResponseGenerator {
42     private static Logger log = Logger.getLogger(ReissueResponseGenerator.class);
43
44     private static final InternalResources intres = InternalResources.getInstance();
45     
46     public ReissueResponseGenerator(String JavaDoc remoteIP, ReissueRequestType req, Document JavaDoc requestDoc) {
47         super(remoteIP, req,requestDoc);
48     }
49     
50     /**
51      * Returns a reissue response
52      */

53     public ReissueResultType getResponse(boolean requestVerifies){
54         ReissueResultType result = xkmsFactory.createReissueResultType();
55         super.populateResponse(result, requestVerifies);
56         ReissueRequestType req = (ReissueRequestType) this.req;
57         
58
59         if(resultMajor == null){
60             if(!checkValidRespondWithRequest(req.getRespondWith(),false)){
61                 resultMajor = XKMSConstants.RESULTMAJOR_SENDER;
62                 resultMinor = XKMSConstants.RESULTMINOR_MESSAGENOTSUPPORTED;
63             }
64
65             if(resultMajor == null){
66                 if(resultMajor == null){
67                     X509Certificate JavaDoc cert = (X509Certificate JavaDoc) getPublicKeyInfo(req, false);
68                     boolean isCertValid = certIsValid(cert);
69                     if(isCertValid && confirmPOP(cert.getPublicKey())){
70                         UserDataVO userData = findUserData(cert);
71                         if(userData != null){
72                             String JavaDoc password = "";
73                             boolean encryptedPassword = isPasswordEncrypted(req);
74                             if(isCertValid && XKMSConfig.isAutomaticReissueAllowed()){
75                                 password = setUserStatusToNew(userData);
76                             }else{
77                                 if(encryptedPassword){
78                                     password = getEncryptedPassword(requestDoc, userData.getPassword());
79                                 }else{
80                                     password = getClearPassword(req, userData.getPassword());
81                                 }
82                             }
83
84                             
85                             if(password != null ){
86                                 X509Certificate JavaDoc newCert = registerReissueOrRecover(false,true, result, userData,password, cert.getPublicKey(), null);
87                                 if(newCert != null){
88                                     KeyBindingAbstractType keyBinding = getResponseValues(req.getReissueKeyBinding(), newCert, false, true);
89                                     result.getKeyBinding().add((KeyBindingType) keyBinding);
90                                 }
91                             }
92                         }
93                     }
94                 }
95             }
96         }
97         
98         if(resultMajor == null){
99             resultMajor = XKMSConstants.RESULTMAJOR_SUCCESS;
100         }
101                    
102         setResult(result);
103         
104         return result;
105     }
106
107
108     /**
109      * Method that sets the users status to 'new' and a
110      * default password
111      * @param the userdata of the user
112      * @return the new password or null of operation failed.
113      */

114     private String JavaDoc setUserStatusToNew(UserDataVO userdata) {
115         String JavaDoc retval = null;
116         try {
117             IPasswordGenerator passwordGenerator = PasswordGeneratorFactory.getInstance(PasswordGeneratorFactory.PASSWORDTYPE_LETTERSANDDIGITS);
118             String JavaDoc password= passwordGenerator.getNewPassword(8, 8);
119
120             userdata.setStatus(UserDataConstants.STATUS_NEW);
121             userdata.setPassword(password);
122
123             getUserAdminSession().changeUser(raAdmin, userdata, true);
124             retval = password;
125         } catch (Exception JavaDoc e) {
126             log.error(intres.getLocalizedMessage("xkms.errorsettinguserstatus", userdata.getUsername()),e);
127         }
128         
129         return retval;
130     }
131
132
133
134
135 }
136
Popular Tags