update dev300-m58
[ooovba.git] / xmlsecurity / tools / uno / SignatureEntity.java
blobd0825ffd53e3a752e3a76565cfd9b47eaca3bb5b
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: SignatureEntity.java,v $
10 * $Revision: 1.4 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 package com.sun.star.xml.security.uno;
33 import java.util.Vector;
35 /* uno classes */
36 import com.sun.star.uno.UnoRuntime;
37 import com.sun.star.lang.XMultiComponentFactory;
38 import com.sun.star.lang.XInitialization;
39 import com.sun.star.uno.XComponentContext;
41 import com.sun.star.xml.crypto.*;
42 import com.sun.star.xml.crypto.sax.*;
45 * this class maintains the data for a signature operation.
47 class SignatureEntity extends SecurityEntity
49 private Vector m_vReferenceIds;
50 private int m_nSignatureElementCollectorId;
52 SignatureEntity(
53 XSecuritySAXEventKeeper xSAXEventKeeper,
54 boolean isExporting,
55 Object resultListener,
56 XXMLSecurityContext xXMLSecurityContext,
57 XXMLSignature xXMLSignature,
58 XXMLEncryption xXMLEncryption,
59 XMultiComponentFactory xRemoteServiceManager,
60 XComponentContext xRemoteContext)
62 super(xSAXEventKeeper, xXMLSecurityContext, xXMLSignature,
63 xXMLEncryption, xRemoteServiceManager, xRemoteContext);
65 m_vReferenceIds = new Vector();
67 if (isExporting)
69 m_nSignatureElementCollectorId = m_xSAXEventKeeper.addSecurityElementCollector(
70 ElementMarkPriority.AFTERMODIFY,
71 true);
73 m_xSAXEventKeeper.setSecurityId(m_nSignatureElementCollectorId, m_nSecurityId);
75 try
78 * creates a SignatureCreator.
80 Object signatureCreator = m_xRemoteServiceManager.createInstanceWithContext(
81 TestTool.SIGNATURECREATOR_COMPONENT, m_xRemoteContext);
83 m_xReferenceResolvedListener =
84 (XReferenceResolvedListener)UnoRuntime.queryInterface(
85 XReferenceResolvedListener.class, signatureCreator);
88 * initializes the SignatureCreator.
90 XInitialization xInitialization =
91 (XInitialization)UnoRuntime.queryInterface(
92 XInitialization.class, m_xReferenceResolvedListener);
94 Object args[]=new Object[5];
95 args[0] = new Integer(m_nSecurityId).toString();
96 args[1] = m_xSAXEventKeeper;
97 args[2] = new Integer(m_nSignatureElementCollectorId).toString();
98 args[3] = m_xXMLSecurityContext.getSecurityEnvironment();
99 args[4] = m_xXMLSignature;
100 xInitialization.initialize(args);
103 * creates a Blocker.
105 int blockerId = m_xSAXEventKeeper.addBlocker();
106 m_xSAXEventKeeper.setSecurityId(blockerId, m_nSecurityId);
108 XBlockerMonitor xBlockerMonitor = (XBlockerMonitor)UnoRuntime.queryInterface(
109 XBlockerMonitor.class, m_xReferenceResolvedListener);
110 xBlockerMonitor.setBlockerId(blockerId);
113 * sets signature creation result listener.
115 XSignatureCreationResultBroadcaster xSignatureCreationResultBroadcaster =
116 (XSignatureCreationResultBroadcaster)UnoRuntime.queryInterface(
117 XSignatureCreationResultBroadcaster.class, m_xReferenceResolvedListener);
118 xSignatureCreationResultBroadcaster.addSignatureCreationResultListener(
119 (XSignatureCreationResultListener)UnoRuntime.queryInterface(
120 XSignatureCreationResultListener.class, resultListener));
122 catch( com.sun.star.uno.Exception e)
124 e.printStackTrace();
128 else
130 m_nSignatureElementCollectorId = m_xSAXEventKeeper.addSecurityElementCollector(
131 ElementMarkPriority.BEFOREMODIFY, false);
133 m_xSAXEventKeeper.setSecurityId(m_nSignatureElementCollectorId, m_nSecurityId);
138 * creates a SignatureVerifier.
140 Object signatureVerifier = m_xRemoteServiceManager.createInstanceWithContext(
141 TestTool.SIGNATUREVERIFIER_COMPONENT, m_xRemoteContext);
143 m_xReferenceResolvedListener =
144 (XReferenceResolvedListener)UnoRuntime.queryInterface(
145 XReferenceResolvedListener.class, signatureVerifier);
148 * initializes the SignatureVerifier.
150 XInitialization xInitialization =
151 (XInitialization)UnoRuntime.queryInterface(
152 XInitialization.class, m_xReferenceResolvedListener);
153 Object args[]=new Object[5];
154 args[0] = new Integer(m_nSecurityId).toString();
155 args[1] = m_xSAXEventKeeper;
156 args[2] = new Integer(m_nSignatureElementCollectorId).toString();
157 args[3] = m_xXMLSecurityContext;
158 args[4] = m_xXMLSignature;
159 xInitialization.initialize(args);
162 * sets signature verify result listener.
164 XSignatureVerifyResultBroadcaster xSignatureVerifyResultBroadcaster =
165 (XSignatureVerifyResultBroadcaster)UnoRuntime.queryInterface(
166 XSignatureVerifyResultBroadcaster.class, m_xReferenceResolvedListener);
167 xSignatureVerifyResultBroadcaster.addSignatureVerifyResultListener(
168 (XSignatureVerifyResultListener)UnoRuntime.queryInterface(
169 XSignatureVerifyResultListener.class, resultListener));
171 catch( com.sun.star.uno.Exception e)
173 e.printStackTrace();
178 * configures the resolve listener for the signature template.
180 XReferenceResolvedBroadcaster xReferenceResolvedBroadcaster =
181 (XReferenceResolvedBroadcaster)UnoRuntime.queryInterface(
182 XReferenceResolvedBroadcaster.class, m_xSAXEventKeeper);
183 xReferenceResolvedBroadcaster.addReferenceResolvedListener(
184 m_nSignatureElementCollectorId, m_xReferenceResolvedListener);
187 /**************************************************************************************
188 * private methods
189 **************************************************************************************/
192 * checks whether this signature has a reference with
193 * the particular id.
195 private boolean hasReference(String id)
197 boolean rc = false;
199 int length = m_vReferenceIds.size();
200 for (int i=0; i<length; ++i)
202 if (id.equals((String)m_vReferenceIds.elementAt(i)))
204 rc = true;
205 break;
209 return rc;
213 /**************************************************************************************
214 * protected methods
215 **************************************************************************************/
218 * adds a new reference id.
220 protected void addReferenceId(String referenceId)
222 m_vReferenceIds.add(referenceId);
226 * notifies how many reference in this signature.
228 protected void setReferenceNumber()
232 XReferenceCollector xReferenceCollector =
233 (XReferenceCollector)UnoRuntime.queryInterface(
234 XReferenceCollector.class, m_xReferenceResolvedListener);
235 xReferenceCollector.setReferenceCount(m_vReferenceIds.size());
237 catch( com.sun.star.uno.Exception e)
239 e.printStackTrace();
244 * tries to add a reference to this signature.
246 * If the specific id belongs to this signature's references, then:
247 * 1. askes the SAXEventKeeper to add a ElementCollector to for the new
248 * referenced element;
249 * 2. configures this ElementCollector's security id;
250 * 3. tells the SAXEventKeeper which listener will receive the reference
251 * resolved notification.
252 * 4. notifies the SignatureCollector about the reference id.
254 protected boolean setReference(String id, boolean isExporting)
256 boolean rc = false;
258 if (hasReference(id))
260 int referenceId = m_xSAXEventKeeper.addSecurityElementCollector(
261 isExporting?
262 (ElementMarkPriority.AFTERMODIFY):(ElementMarkPriority.BEFOREMODIFY),
263 false );
265 m_xSAXEventKeeper.setSecurityId(referenceId, m_nSecurityId);
267 XReferenceResolvedBroadcaster xReferenceResolvedBroadcaster =
268 (XReferenceResolvedBroadcaster)UnoRuntime.queryInterface(
269 XReferenceResolvedBroadcaster.class, m_xSAXEventKeeper);
270 xReferenceResolvedBroadcaster.addReferenceResolvedListener(
271 referenceId, m_xReferenceResolvedListener);
275 XReferenceCollector xReferenceCollector =
276 (XReferenceCollector)UnoRuntime.queryInterface(
277 XReferenceCollector.class, m_xReferenceResolvedListener);
278 xReferenceCollector.setReferenceId(referenceId);
280 catch( com.sun.star.uno.Exception e)
282 e.printStackTrace();
285 rc = true;
288 return rc;