update dev300-m58
[ooovba.git] / xmlsecurity / tools / uno / SecurityEntity.java
blobae2911dfc52c15163105501d50ba01aabc48e168
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: SecurityEntity.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 /* uno classes */
34 import com.sun.star.uno.UnoRuntime;
35 import com.sun.star.lang.XMultiComponentFactory;
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 security operation.
44 class SecurityEntity
47 * the security id, which identifies this security entity
48 * uniquely.
50 private static int m_nNextSecurityId = 1;
51 protected int m_nSecurityId;
54 * xml security related components
56 protected XXMLSecurityContext m_xXMLSecurityContext;
57 protected XXMLSignature m_xXMLSignature;
58 protected XXMLEncryption m_xXMLEncryption;
59 protected XMultiComponentFactory m_xRemoteServiceManager;
60 protected XComponentContext m_xRemoteContext;
61 protected XReferenceResolvedListener m_xReferenceResolvedListener;
62 protected XSecuritySAXEventKeeper m_xSAXEventKeeper;
65 * the uri of the key material of this security entity
67 private String m_keyURI;
69 SecurityEntity(
70 XSecuritySAXEventKeeper xSAXEventKeeper,
71 XXMLSecurityContext xXMLSecurityContext,
72 XXMLSignature xXMLSignature,
73 XXMLEncryption xXMLEncryption,
74 XMultiComponentFactory xRemoteServiceManager,
75 XComponentContext xRemoteContext)
77 m_xSAXEventKeeper = xSAXEventKeeper;
78 m_xXMLSecurityContext = xXMLSecurityContext;
79 m_xXMLSignature = xXMLSignature;
80 m_xXMLEncryption = xXMLEncryption;
81 m_xRemoteServiceManager = xRemoteServiceManager;
82 m_xRemoteContext = xRemoteContext;
84 m_nSecurityId = getNextSecurityId();
85 m_keyURI = null;
88 /**************************************************************************************
89 * private methods
90 **************************************************************************************/
93 * generates a new security id.
95 private static int getNextSecurityId()
97 int id = m_nNextSecurityId++;
98 return id;
101 /**************************************************************************************
102 * protected methods
103 **************************************************************************************/
106 * notifies the key collector about the key id, this key id
107 * is used to ask the SAXEventKeeper to release the bufferred
108 * key element.
109 * when the id is 0, that means there is no independant key
110 * element needed.
112 protected void setKeyId(int id)
116 XKeyCollector xKeyCollector =
117 (XKeyCollector)UnoRuntime.queryInterface(
118 XKeyCollector.class, m_xReferenceResolvedListener);
119 xKeyCollector.setKeyId(id);
121 catch( com.sun.star.uno.Exception e)
123 e.printStackTrace();
128 * set the key uri, which will be the value of the id attribute
129 * of the key element
131 protected void setKeyURI(String uri)
133 m_keyURI = new String(uri);
136 protected XReferenceResolvedListener getReferenceListener()
138 return m_xReferenceResolvedListener;
141 protected int getSecurityId()
143 return m_nSecurityId;
147 * configures the key material to the security entity.
149 * if the uri is the key, then:
150 * 1. askes the SAXEventKeeper to add a ElementCollector to the key
151 * element;
152 * 2. notifies the key collector;
153 * 3. configures this ElementCollector's security id;
154 * 4. tells the SAXEventKeeper which listener will receive the reference
155 * resolved notification.
157 protected boolean setKey(String uri, boolean isExporting)
159 boolean rc = false;
161 if (m_keyURI != null &&
162 m_keyURI.equals(uri))
164 int referenceId = m_xSAXEventKeeper.addSecurityElementCollector(
165 isExporting?
166 (ElementMarkPriority.BEFOREMODIFY):(ElementMarkPriority.AFTERMODIFY),
167 false );
169 setKeyId(referenceId);
170 m_xSAXEventKeeper.setSecurityId(referenceId, m_nSecurityId);
172 XReferenceResolvedBroadcaster xReferenceResolvedBroadcaster =
173 (XReferenceResolvedBroadcaster)UnoRuntime.queryInterface(
174 XReferenceResolvedBroadcaster.class, m_xSAXEventKeeper);
176 xReferenceResolvedBroadcaster.addReferenceResolvedListener(referenceId, m_xReferenceResolvedListener);
178 rc = true;
181 return rc;
185 * ends this misstion, asks the security engine to clear up all
186 * resources.
188 protected boolean endMission()
190 XMissionTaker xMissionTaker =
191 (XMissionTaker)UnoRuntime.queryInterface(
192 XMissionTaker.class, m_xReferenceResolvedListener);
194 boolean rc = xMissionTaker.endMission();
196 m_xXMLSecurityContext = null;
197 m_xXMLSignature = null;
198 m_xXMLEncryption = null;
199 m_xReferenceResolvedListener = null;
200 m_xSAXEventKeeper = null;
202 return rc;