01: /*************************************************************************
02: * *
03: * EJBCA: The OpenSource Certificate Authority *
04: * *
05: * This software is free software; you can redistribute it and/or *
06: * modify it under the terms of the GNU Lesser General Public *
07: * License as published by the Free Software Foundation; either *
08: * version 2.1 of the License, or any later version. *
09: * *
10: * See terms of license at gnu.org. *
11: * *
12: *************************************************************************/package org.ejbca.core.protocol.xkms.generators;
13:
14: import java.security.cert.X509Certificate;
15: import java.util.Iterator;
16: import java.util.List;
17:
18: import org.ejbca.core.protocol.xkms.common.XKMSConstants;
19: import org.w3._2002._03.xkms_.KeyBindingType;
20: import org.w3._2002._03.xkms_.ValidateRequestType;
21: import org.w3._2002._03.xkms_.ValidateResultType;
22:
23: /**
24: * Class generating a response for a locate call
25: *
26: *
27: * @author Philip Vendil 2006 sep 27
28: *
29: * @version $Id: ValidateResponseGenerator.java,v 1.2 2007/01/05 05:32:51 herrvendil Exp $
30: */
31:
32: public class ValidateResponseGenerator extends KISSResponseGenerator {
33:
34: public ValidateResponseGenerator(String remoteIP,
35: ValidateRequestType req) {
36: super (remoteIP, req);
37: }
38:
39: /**
40: * Returns a locate response
41: */
42: public ValidateResultType getResponse(boolean requestVerifies) {
43: ValidateResultType result = xkmsFactory
44: .createValidateResultType();
45: super .populateResponse(result, requestVerifies);
46: ValidateRequestType req = (ValidateRequestType) this .req;
47:
48: if (resultMajor == null) {
49: if (!checkValidRespondWithRequest(req.getRespondWith())) {
50: resultMajor = XKMSConstants.RESULTMAJOR_SENDER;
51: resultMinor = XKMSConstants.RESULTMINOR_MESSAGENOTSUPPORTED;
52: }
53:
54: if (resultMajor == null) {
55: List<X509Certificate> queryResult = processRequest(req
56: .getQueryKeyBinding());
57:
58: if (resultMajor == null) {
59: Iterator<X509Certificate> iter = queryResult
60: .iterator();
61: while (iter.hasNext()) {
62: X509Certificate nextCert = iter.next();
63: result.getKeyBinding().add(
64: (KeyBindingType) getResponseValues(req
65: .getQueryKeyBinding(),
66: nextCert, true, false));
67:
68: }
69: }
70: }
71: }
72:
73: if (resultMajor == null) {
74: resultMajor = XKMSConstants.RESULTMAJOR_SUCCESS;
75: }
76:
77: setResult(result);
78:
79: return result;
80: }
81:
82: }
|