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
;
31 import com
.sun
.star
.uno
.UnoRuntime
;
32 import com
.sun
.star
.lang
.XMultiComponentFactory
;
33 import com
.sun
.star
.lang
.XInitialization
;
34 import com
.sun
.star
.uno
.XComponentContext
;
36 import com
.sun
.star
.xml
.crypto
.*;
37 import com
.sun
.star
.xml
.crypto
.sax
.*;
40 * this class maintains the data for an encryption operation.
42 class EncryptionEntity
extends SecurityEntity
44 private int m_nEncryptionElementCollectorId
;
47 XSecuritySAXEventKeeper xSAXEventKeeper
,
49 Object resultListener
,
50 XXMLSecurityContext xXMLSecurityContext
,
51 XXMLSignature xXMLSignature
,
52 XXMLEncryption xXMLEncryption
,
53 XMultiComponentFactory xRemoteServiceManager
,
54 XComponentContext xRemoteContext
)
56 super(xSAXEventKeeper
, xXMLSecurityContext
, xXMLSignature
,
57 xXMLEncryption
, xRemoteServiceManager
, xRemoteContext
);
59 m_nEncryptionElementCollectorId
= m_xSAXEventKeeper
.addSecurityElementCollector(
60 ElementMarkPriority
.AFTERMODIFY
,
63 m_xSAXEventKeeper
.setSecurityId(m_nEncryptionElementCollectorId
, m_nSecurityId
);
70 * creates a Encryptor.
72 Object encryptor
= m_xRemoteServiceManager
.createInstanceWithContext(
73 TestTool
.ENCRYPTOR_COMPONENT
, m_xRemoteContext
);
75 m_xReferenceResolvedListener
=
76 (XReferenceResolvedListener
)UnoRuntime
.queryInterface(
77 XReferenceResolvedListener
.class, encryptor
);
80 * initializes the Encryptor.
82 XInitialization xInitialization
=
83 (XInitialization
)UnoRuntime
.queryInterface(
84 XInitialization
.class, m_xReferenceResolvedListener
);
85 Object args
[]=new Object
[5];
86 args
[0] = new Integer(m_nSecurityId
).toString();
87 args
[1] = m_xSAXEventKeeper
;
88 args
[2] = new Integer(m_nEncryptionElementCollectorId
).toString();
89 args
[3] = m_xXMLSecurityContext
.getSecurityEnvironment();
90 args
[4] = m_xXMLEncryption
;
91 xInitialization
.initialize(args
);
94 * sets encryption result listener.
96 XEncryptionResultBroadcaster m_xEncryptionResultBroadcaster
=
97 (XEncryptionResultBroadcaster
)UnoRuntime
.queryInterface(
98 XEncryptionResultBroadcaster
.class, m_xReferenceResolvedListener
);
99 m_xEncryptionResultBroadcaster
.addEncryptionResultListener(
100 (XEncryptionResultListener
)UnoRuntime
.queryInterface(
101 XEncryptionResultListener
.class, resultListener
));
103 catch( com
.sun
.star
.uno
.Exception e
)
112 * creates a Decryptor.
114 Object decryptor
= m_xRemoteServiceManager
.createInstanceWithContext(
115 TestTool
.DECRYPTOR_COMPONENT
, m_xRemoteContext
);
117 m_xReferenceResolvedListener
=
118 (XReferenceResolvedListener
)UnoRuntime
.queryInterface(
119 XReferenceResolvedListener
.class, decryptor
);
122 * initializes the Decryptor.
124 XInitialization xInitialization
= (XInitialization
)UnoRuntime
.queryInterface(XInitialization
.class, m_xReferenceResolvedListener
);
125 Object args
[]=new Object
[5];
126 args
[0] = new Integer(m_nSecurityId
).toString();
127 args
[1] = m_xSAXEventKeeper
;
128 args
[2] = new Integer(m_nEncryptionElementCollectorId
).toString();
129 args
[3] = m_xXMLSecurityContext
;
130 args
[4] = m_xXMLEncryption
;
131 xInitialization
.initialize(args
);
134 * sets decryption result listener.
136 XDecryptionResultBroadcaster m_xDecryptionResultBroadcaster
=
137 (XDecryptionResultBroadcaster
)UnoRuntime
.queryInterface(
138 XDecryptionResultBroadcaster
.class, m_xReferenceResolvedListener
);
139 m_xDecryptionResultBroadcaster
.addDecryptionResultListener(
140 (XDecryptionResultListener
)UnoRuntime
.queryInterface(
141 XDecryptionResultListener
.class, resultListener
));
143 catch( com
.sun
.star
.uno
.Exception e
)
152 int blockerId
= m_xSAXEventKeeper
.addBlocker();
153 m_xSAXEventKeeper
.setSecurityId(blockerId
, m_nSecurityId
);
157 XBlockerMonitor xBlockerMonitor
= (XBlockerMonitor
)UnoRuntime
.queryInterface(
158 XBlockerMonitor
.class, m_xReferenceResolvedListener
);
159 xBlockerMonitor
.setBlockerId(blockerId
);
161 catch( com
.sun
.star
.uno
.Exception e
)
167 * configures the resolve listener for the encryption template.
169 XReferenceResolvedBroadcaster xReferenceResolvedBroadcaster
=
170 (XReferenceResolvedBroadcaster
)UnoRuntime
.queryInterface(
171 XReferenceResolvedBroadcaster
.class, m_xSAXEventKeeper
);
172 xReferenceResolvedBroadcaster
.addReferenceResolvedListener(m_nEncryptionElementCollectorId
, m_xReferenceResolvedListener
);
176 * add the reference to this encryption.
178 * 1. askes the SAXEventKeeper to add a ElementCollector to for the new
179 * referenced element;
180 * 2. configures this ElementCollector's security id;
181 * 3. tells the SAXEventKeeper which listener will receive the reference
182 * resolved notification.
183 * 4. notifies the SignatureCollector about the reference id.
185 protected boolean setReference(boolean isExporting
)
189 int referenceId
= m_xSAXEventKeeper
.addSecurityElementCollector(
191 (ElementMarkPriority
.AFTERMODIFY
):(ElementMarkPriority
.BEFOREMODIFY
),
194 m_xSAXEventKeeper
.setSecurityId(referenceId
, m_nSecurityId
);
196 XReferenceResolvedBroadcaster xReferenceResolvedBroadcaster
=
197 (XReferenceResolvedBroadcaster
)UnoRuntime
.queryInterface(
198 XReferenceResolvedBroadcaster
.class, m_xSAXEventKeeper
);
199 xReferenceResolvedBroadcaster
.addReferenceResolvedListener(
200 referenceId
, m_xReferenceResolvedListener
);
204 XReferenceCollector xReferenceCollector
=
205 (XReferenceCollector
)UnoRuntime
.queryInterface(
206 XReferenceCollector
.class, m_xReferenceResolvedListener
);
207 xReferenceCollector
.setReferenceId(referenceId
);
209 catch( com
.sun
.star
.uno
.Exception e
)