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_.LocateRequestType;
20: import org.w3._2002._03.xkms_.LocateResultType;
21: import org.w3._2002._03.xkms_.UnverifiedKeyBindingType;
22:
23: /**
24: * Class generating a response for a locate call
25: *
26: *
27: * @author Philip Vendil 2006 sep 27
28: *
29: * @version $Id: LocateResponseGenerator.java,v 1.2 2007/01/05 05:32:51 herrvendil Exp $
30: */
31:
32: public class LocateResponseGenerator extends KISSResponseGenerator {
33:
34: public LocateResponseGenerator(String remoteIP,
35: LocateRequestType req) {
36: super (remoteIP, req);
37: }
38:
39: /**
40: * Returns a locate response
41: */
42: public LocateResultType getResponse(boolean requestVerifies) {
43: LocateResultType result = xkmsFactory.createLocateResultType();
44: super .populateResponse(result, requestVerifies);
45: LocateRequestType req = (LocateRequestType) this .req;
46:
47: if (resultMajor == null) {
48: if (!checkValidRespondWithRequest(req.getRespondWith())) {
49: resultMajor = XKMSConstants.RESULTMAJOR_SENDER;
50: resultMinor = XKMSConstants.RESULTMINOR_MESSAGENOTSUPPORTED;
51: }
52:
53: if (resultMajor == null) {
54: List<X509Certificate> queryResult = processRequest(req
55: .getQueryKeyBinding());
56:
57: if (resultMajor == null) {
58: Iterator<X509Certificate> iter = queryResult
59: .iterator();
60: while (iter.hasNext()) {
61: X509Certificate nextCert = iter.next();
62: result
63: .getUnverifiedKeyBinding()
64: .add(
65: (UnverifiedKeyBindingType) getResponseValues(
66: req
67: .getQueryKeyBinding(),
68: nextCert, false, false));
69:
70: }
71: }
72: }
73: }
74:
75: if (resultMajor == null) {
76: resultMajor = XKMSConstants.RESULTMAJOR_SUCCESS;
77: }
78:
79: setResult(result);
80:
81: return result;
82: }
83:
84: }
|