1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2000, 2010 Oracle and/or its affiliates.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * This file is part of OpenOffice.org.
11 * OpenOffice.org is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU Lesser General Public License version 3
13 * only, as published by the Free Software Foundation.
15 * OpenOffice.org is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Lesser General Public License version 3 for more details
19 * (a copy is included in the LICENSE file that accompanied this code).
21 * You should have received a copy of the GNU Lesser General Public License
22 * version 3 along with OpenOffice.org. If not, see
23 * <http://www.openoffice.org/license.html>
24 * for a copy of the LGPLv3 License.
26 ************************************************************************/
28 package com
.sun
.star
.xml
.security
.uno
;
30 import java
.util
.Vector
;
33 import com
.sun
.star
.uno
.UnoRuntime
;
34 import com
.sun
.star
.lang
.XMultiComponentFactory
;
35 import com
.sun
.star
.lang
.XInitialization
;
36 import com
.sun
.star
.uno
.XComponentContext
;
38 import com
.sun
.star
.xml
.crypto
.*;
39 import com
.sun
.star
.xml
.crypto
.sax
.*;
42 * this class maintains the data for a signature operation.
44 class SignatureEntity
extends SecurityEntity
46 private Vector m_vReferenceIds
;
47 private int m_nSignatureElementCollectorId
;
50 XSecuritySAXEventKeeper xSAXEventKeeper
,
52 Object resultListener
,
53 XXMLSecurityContext xXMLSecurityContext
,
54 XXMLSignature xXMLSignature
,
55 XXMLEncryption xXMLEncryption
,
56 XMultiComponentFactory xRemoteServiceManager
,
57 XComponentContext xRemoteContext
)
59 super(xSAXEventKeeper
, xXMLSecurityContext
, xXMLSignature
,
60 xXMLEncryption
, xRemoteServiceManager
, xRemoteContext
);
62 m_vReferenceIds
= new Vector();
66 m_nSignatureElementCollectorId
= m_xSAXEventKeeper
.addSecurityElementCollector(
67 ElementMarkPriority
.AFTERMODIFY
,
70 m_xSAXEventKeeper
.setSecurityId(m_nSignatureElementCollectorId
, m_nSecurityId
);
75 * creates a SignatureCreator.
77 Object signatureCreator
= m_xRemoteServiceManager
.createInstanceWithContext(
78 TestTool
.SIGNATURECREATOR_COMPONENT
, m_xRemoteContext
);
80 m_xReferenceResolvedListener
=
81 (XReferenceResolvedListener
)UnoRuntime
.queryInterface(
82 XReferenceResolvedListener
.class, signatureCreator
);
85 * initializes the SignatureCreator.
87 XInitialization xInitialization
=
88 (XInitialization
)UnoRuntime
.queryInterface(
89 XInitialization
.class, m_xReferenceResolvedListener
);
91 Object args
[]=new Object
[5];
92 args
[0] = new Integer(m_nSecurityId
).toString();
93 args
[1] = m_xSAXEventKeeper
;
94 args
[2] = new Integer(m_nSignatureElementCollectorId
).toString();
95 args
[3] = m_xXMLSecurityContext
.getSecurityEnvironment();
96 args
[4] = m_xXMLSignature
;
97 xInitialization
.initialize(args
);
102 int blockerId
= m_xSAXEventKeeper
.addBlocker();
103 m_xSAXEventKeeper
.setSecurityId(blockerId
, m_nSecurityId
);
105 XBlockerMonitor xBlockerMonitor
= (XBlockerMonitor
)UnoRuntime
.queryInterface(
106 XBlockerMonitor
.class, m_xReferenceResolvedListener
);
107 xBlockerMonitor
.setBlockerId(blockerId
);
110 * sets signature creation result listener.
112 XSignatureCreationResultBroadcaster xSignatureCreationResultBroadcaster
=
113 (XSignatureCreationResultBroadcaster
)UnoRuntime
.queryInterface(
114 XSignatureCreationResultBroadcaster
.class, m_xReferenceResolvedListener
);
115 xSignatureCreationResultBroadcaster
.addSignatureCreationResultListener(
116 (XSignatureCreationResultListener
)UnoRuntime
.queryInterface(
117 XSignatureCreationResultListener
.class, resultListener
));
119 catch( com
.sun
.star
.uno
.Exception e
)
127 m_nSignatureElementCollectorId
= m_xSAXEventKeeper
.addSecurityElementCollector(
128 ElementMarkPriority
.BEFOREMODIFY
, false);
130 m_xSAXEventKeeper
.setSecurityId(m_nSignatureElementCollectorId
, m_nSecurityId
);
135 * creates a SignatureVerifier.
137 Object signatureVerifier
= m_xRemoteServiceManager
.createInstanceWithContext(
138 TestTool
.SIGNATUREVERIFIER_COMPONENT
, m_xRemoteContext
);
140 m_xReferenceResolvedListener
=
141 (XReferenceResolvedListener
)UnoRuntime
.queryInterface(
142 XReferenceResolvedListener
.class, signatureVerifier
);
145 * initializes the SignatureVerifier.
147 XInitialization xInitialization
=
148 (XInitialization
)UnoRuntime
.queryInterface(
149 XInitialization
.class, m_xReferenceResolvedListener
);
150 Object args
[]=new Object
[5];
151 args
[0] = new Integer(m_nSecurityId
).toString();
152 args
[1] = m_xSAXEventKeeper
;
153 args
[2] = new Integer(m_nSignatureElementCollectorId
).toString();
154 args
[3] = m_xXMLSecurityContext
;
155 args
[4] = m_xXMLSignature
;
156 xInitialization
.initialize(args
);
159 * sets signature verify result listener.
161 XSignatureVerifyResultBroadcaster xSignatureVerifyResultBroadcaster
=
162 (XSignatureVerifyResultBroadcaster
)UnoRuntime
.queryInterface(
163 XSignatureVerifyResultBroadcaster
.class, m_xReferenceResolvedListener
);
164 xSignatureVerifyResultBroadcaster
.addSignatureVerifyResultListener(
165 (XSignatureVerifyResultListener
)UnoRuntime
.queryInterface(
166 XSignatureVerifyResultListener
.class, resultListener
));
168 catch( com
.sun
.star
.uno
.Exception e
)
175 * configures the resolve listener for the signature template.
177 XReferenceResolvedBroadcaster xReferenceResolvedBroadcaster
=
178 (XReferenceResolvedBroadcaster
)UnoRuntime
.queryInterface(
179 XReferenceResolvedBroadcaster
.class, m_xSAXEventKeeper
);
180 xReferenceResolvedBroadcaster
.addReferenceResolvedListener(
181 m_nSignatureElementCollectorId
, m_xReferenceResolvedListener
);
184 /**************************************************************************************
186 **************************************************************************************/
189 * checks whether this signature has a reference with
192 private boolean hasReference(String id
)
196 int length
= m_vReferenceIds
.size();
197 for (int i
=0; i
<length
; ++i
)
199 if (id
.equals((String
)m_vReferenceIds
.elementAt(i
)))
210 /**************************************************************************************
212 **************************************************************************************/
215 * adds a new reference id.
217 protected void addReferenceId(String referenceId
)
219 m_vReferenceIds
.add(referenceId
);
223 * notifies how many reference in this signature.
225 protected void setReferenceNumber()
229 XReferenceCollector xReferenceCollector
=
230 (XReferenceCollector
)UnoRuntime
.queryInterface(
231 XReferenceCollector
.class, m_xReferenceResolvedListener
);
232 xReferenceCollector
.setReferenceCount(m_vReferenceIds
.size());
234 catch( com
.sun
.star
.uno
.Exception e
)
241 * tries to add a reference to this signature.
243 * If the specific id belongs to this signature's references, then:
244 * 1. askes the SAXEventKeeper to add a ElementCollector to for the new
245 * referenced element;
246 * 2. configures this ElementCollector's security id;
247 * 3. tells the SAXEventKeeper which listener will receive the reference
248 * resolved notification.
249 * 4. notifies the SignatureCollector about the reference id.
251 protected boolean setReference(String id
, boolean isExporting
)
255 if (hasReference(id
))
257 int referenceId
= m_xSAXEventKeeper
.addSecurityElementCollector(
259 (ElementMarkPriority
.AFTERMODIFY
):(ElementMarkPriority
.BEFOREMODIFY
),
262 m_xSAXEventKeeper
.setSecurityId(referenceId
, m_nSecurityId
);
264 XReferenceResolvedBroadcaster xReferenceResolvedBroadcaster
=
265 (XReferenceResolvedBroadcaster
)UnoRuntime
.queryInterface(
266 XReferenceResolvedBroadcaster
.class, m_xSAXEventKeeper
);
267 xReferenceResolvedBroadcaster
.addReferenceResolvedListener(
268 referenceId
, m_xReferenceResolvedListener
);
272 XReferenceCollector xReferenceCollector
=
273 (XReferenceCollector
)UnoRuntime
.queryInterface(
274 XReferenceCollector
.class, m_xReferenceResolvedListener
);
275 xReferenceCollector
.setReferenceId(referenceId
);
277 catch( com
.sun
.star
.uno
.Exception e
)