1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: EncryptionEntity.java,v $
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
;
34 import com
.sun
.star
.uno
.UnoRuntime
;
35 import com
.sun
.star
.lang
.XMultiComponentFactory
;
36 import com
.sun
.star
.lang
.XInitialization
;
37 import com
.sun
.star
.uno
.XComponentContext
;
39 import com
.sun
.star
.xml
.crypto
.*;
40 import com
.sun
.star
.xml
.crypto
.sax
.*;
43 * this class maintains the data for an encryption operation.
45 class EncryptionEntity
extends SecurityEntity
47 private int m_nEncryptionElementCollectorId
;
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_nEncryptionElementCollectorId
= m_xSAXEventKeeper
.addSecurityElementCollector(
63 ElementMarkPriority
.AFTERMODIFY
,
66 m_xSAXEventKeeper
.setSecurityId(m_nEncryptionElementCollectorId
, m_nSecurityId
);
73 * creates a Encryptor.
75 Object encryptor
= m_xRemoteServiceManager
.createInstanceWithContext(
76 TestTool
.ENCRYPTOR_COMPONENT
, m_xRemoteContext
);
78 m_xReferenceResolvedListener
=
79 (XReferenceResolvedListener
)UnoRuntime
.queryInterface(
80 XReferenceResolvedListener
.class, encryptor
);
83 * initializes the Encryptor.
85 XInitialization xInitialization
=
86 (XInitialization
)UnoRuntime
.queryInterface(
87 XInitialization
.class, m_xReferenceResolvedListener
);
88 Object args
[]=new Object
[5];
89 args
[0] = new Integer(m_nSecurityId
).toString();
90 args
[1] = m_xSAXEventKeeper
;
91 args
[2] = new Integer(m_nEncryptionElementCollectorId
).toString();
92 args
[3] = m_xXMLSecurityContext
.getSecurityEnvironment();
93 args
[4] = m_xXMLEncryption
;
94 xInitialization
.initialize(args
);
97 * sets encryption result listener.
99 XEncryptionResultBroadcaster m_xEncryptionResultBroadcaster
=
100 (XEncryptionResultBroadcaster
)UnoRuntime
.queryInterface(
101 XEncryptionResultBroadcaster
.class, m_xReferenceResolvedListener
);
102 m_xEncryptionResultBroadcaster
.addEncryptionResultListener(
103 (XEncryptionResultListener
)UnoRuntime
.queryInterface(
104 XEncryptionResultListener
.class, resultListener
));
106 catch( com
.sun
.star
.uno
.Exception e
)
115 * creates a Decryptor.
117 Object decryptor
= m_xRemoteServiceManager
.createInstanceWithContext(
118 TestTool
.DECRYPTOR_COMPONENT
, m_xRemoteContext
);
120 m_xReferenceResolvedListener
=
121 (XReferenceResolvedListener
)UnoRuntime
.queryInterface(
122 XReferenceResolvedListener
.class, decryptor
);
125 * initializes the Decryptor.
127 XInitialization xInitialization
= (XInitialization
)UnoRuntime
.queryInterface(XInitialization
.class, m_xReferenceResolvedListener
);
128 Object args
[]=new Object
[5];
129 args
[0] = new Integer(m_nSecurityId
).toString();
130 args
[1] = m_xSAXEventKeeper
;
131 args
[2] = new Integer(m_nEncryptionElementCollectorId
).toString();
132 args
[3] = m_xXMLSecurityContext
;
133 args
[4] = m_xXMLEncryption
;
134 xInitialization
.initialize(args
);
137 * sets decryption result listener.
139 XDecryptionResultBroadcaster m_xDecryptionResultBroadcaster
=
140 (XDecryptionResultBroadcaster
)UnoRuntime
.queryInterface(
141 XDecryptionResultBroadcaster
.class, m_xReferenceResolvedListener
);
142 m_xDecryptionResultBroadcaster
.addDecryptionResultListener(
143 (XDecryptionResultListener
)UnoRuntime
.queryInterface(
144 XDecryptionResultListener
.class, resultListener
));
146 catch( com
.sun
.star
.uno
.Exception e
)
155 int blockerId
= m_xSAXEventKeeper
.addBlocker();
156 m_xSAXEventKeeper
.setSecurityId(blockerId
, m_nSecurityId
);
160 XBlockerMonitor xBlockerMonitor
= (XBlockerMonitor
)UnoRuntime
.queryInterface(
161 XBlockerMonitor
.class, m_xReferenceResolvedListener
);
162 xBlockerMonitor
.setBlockerId(blockerId
);
164 catch( com
.sun
.star
.uno
.Exception e
)
170 * configures the resolve listener for the encryption template.
172 XReferenceResolvedBroadcaster xReferenceResolvedBroadcaster
=
173 (XReferenceResolvedBroadcaster
)UnoRuntime
.queryInterface(
174 XReferenceResolvedBroadcaster
.class, m_xSAXEventKeeper
);
175 xReferenceResolvedBroadcaster
.addReferenceResolvedListener(m_nEncryptionElementCollectorId
, m_xReferenceResolvedListener
);
179 * add the reference to this encryption.
181 * 1. askes the SAXEventKeeper to add a ElementCollector to for the new
182 * referenced element;
183 * 2. configures this ElementCollector's security id;
184 * 3. tells the SAXEventKeeper which listener will receive the reference
185 * resolved notification.
186 * 4. notifies the SignatureCollector about the reference id.
188 protected boolean setReference(boolean isExporting
)
192 int referenceId
= m_xSAXEventKeeper
.addSecurityElementCollector(
194 (ElementMarkPriority
.AFTERMODIFY
):(ElementMarkPriority
.BEFOREMODIFY
),
197 m_xSAXEventKeeper
.setSecurityId(referenceId
, m_nSecurityId
);
199 XReferenceResolvedBroadcaster xReferenceResolvedBroadcaster
=
200 (XReferenceResolvedBroadcaster
)UnoRuntime
.queryInterface(
201 XReferenceResolvedBroadcaster
.class, m_xSAXEventKeeper
);
202 xReferenceResolvedBroadcaster
.addReferenceResolvedListener(
203 referenceId
, m_xReferenceResolvedListener
);
207 XReferenceCollector xReferenceCollector
=
208 (XReferenceCollector
)UnoRuntime
.queryInterface(
209 XReferenceCollector
.class, m_xReferenceResolvedListener
);
210 xReferenceCollector
.setReferenceId(referenceId
);
212 catch( com
.sun
.star
.uno
.Exception e
)