merged tag ooo/OOO330_m14
[LibreOffice.git] / xmlsecurity / tools / uno / SecurityEntity.java
blob85ef5ed498919753d9acee46c173c9bb10a8d9dc
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 /* uno classes */
31 import com.sun.star.uno.UnoRuntime;
32 import com.sun.star.lang.XMultiComponentFactory;
33 import com.sun.star.uno.XComponentContext;
35 import com.sun.star.xml.crypto.*;
36 import com.sun.star.xml.crypto.sax.*;
39 * this class maintains the data for a security operation.
41 class SecurityEntity
44 * the security id, which identifies this security entity
45 * uniquely.
47 private static int m_nNextSecurityId = 1;
48 protected int m_nSecurityId;
51 * xml security related components
53 protected XXMLSecurityContext m_xXMLSecurityContext;
54 protected XXMLSignature m_xXMLSignature;
55 protected XXMLEncryption m_xXMLEncryption;
56 protected XMultiComponentFactory m_xRemoteServiceManager;
57 protected XComponentContext m_xRemoteContext;
58 protected XReferenceResolvedListener m_xReferenceResolvedListener;
59 protected XSecuritySAXEventKeeper m_xSAXEventKeeper;
62 * the uri of the key material of this security entity
64 private String m_keyURI;
66 SecurityEntity(
67 XSecuritySAXEventKeeper xSAXEventKeeper,
68 XXMLSecurityContext xXMLSecurityContext,
69 XXMLSignature xXMLSignature,
70 XXMLEncryption xXMLEncryption,
71 XMultiComponentFactory xRemoteServiceManager,
72 XComponentContext xRemoteContext)
74 m_xSAXEventKeeper = xSAXEventKeeper;
75 m_xXMLSecurityContext = xXMLSecurityContext;
76 m_xXMLSignature = xXMLSignature;
77 m_xXMLEncryption = xXMLEncryption;
78 m_xRemoteServiceManager = xRemoteServiceManager;
79 m_xRemoteContext = xRemoteContext;
81 m_nSecurityId = getNextSecurityId();
82 m_keyURI = null;
85 /**************************************************************************************
86 * private methods
87 **************************************************************************************/
90 * generates a new security id.
92 private static int getNextSecurityId()
94 int id = m_nNextSecurityId++;
95 return id;
98 /**************************************************************************************
99 * protected methods
100 **************************************************************************************/
103 * notifies the key collector about the key id, this key id
104 * is used to ask the SAXEventKeeper to release the bufferred
105 * key element.
106 * when the id is 0, that means there is no independant key
107 * element needed.
109 protected void setKeyId(int id)
113 XKeyCollector xKeyCollector =
114 (XKeyCollector)UnoRuntime.queryInterface(
115 XKeyCollector.class, m_xReferenceResolvedListener);
116 xKeyCollector.setKeyId(id);
118 catch( com.sun.star.uno.Exception e)
120 e.printStackTrace();
125 * set the key uri, which will be the value of the id attribute
126 * of the key element
128 protected void setKeyURI(String uri)
130 m_keyURI = new String(uri);
133 protected XReferenceResolvedListener getReferenceListener()
135 return m_xReferenceResolvedListener;
138 protected int getSecurityId()
140 return m_nSecurityId;
144 * configures the key material to the security entity.
146 * if the uri is the key, then:
147 * 1. askes the SAXEventKeeper to add a ElementCollector to the key
148 * element;
149 * 2. notifies the key collector;
150 * 3. configures this ElementCollector's security id;
151 * 4. tells the SAXEventKeeper which listener will receive the reference
152 * resolved notification.
154 protected boolean setKey(String uri, boolean isExporting)
156 boolean rc = false;
158 if (m_keyURI != null &&
159 m_keyURI.equals(uri))
161 int referenceId = m_xSAXEventKeeper.addSecurityElementCollector(
162 isExporting?
163 (ElementMarkPriority.BEFOREMODIFY):(ElementMarkPriority.AFTERMODIFY),
164 false );
166 setKeyId(referenceId);
167 m_xSAXEventKeeper.setSecurityId(referenceId, m_nSecurityId);
169 XReferenceResolvedBroadcaster xReferenceResolvedBroadcaster =
170 (XReferenceResolvedBroadcaster)UnoRuntime.queryInterface(
171 XReferenceResolvedBroadcaster.class, m_xSAXEventKeeper);
173 xReferenceResolvedBroadcaster.addReferenceResolvedListener(referenceId, m_xReferenceResolvedListener);
175 rc = true;
178 return rc;
182 * ends this misstion, asks the security engine to clear up all
183 * resources.
185 protected boolean endMission()
187 XMissionTaker xMissionTaker =
188 (XMissionTaker)UnoRuntime.queryInterface(
189 XMissionTaker.class, m_xReferenceResolvedListener);
191 boolean rc = xMissionTaker.endMission();
193 m_xXMLSecurityContext = null;
194 m_xXMLSignature = null;
195 m_xXMLEncryption = null;
196 m_xReferenceResolvedListener = null;
197 m_xSAXEventKeeper = null;
199 return rc;