1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_xmlsecurity.hxx"
26 #include <sal/config.h>
27 #include <rtl/ustring.hxx>
28 #include <rtl/uuid.h>
29 #include "xmlsignaturetemplateimpl.hxx"
30 
31 using namespace ::com::sun::star::uno ;
32 using ::com::sun::star::lang::XMultiServiceFactory ;
33 using ::com::sun::star::lang::XSingleServiceFactory ;
34 using ::rtl::OUString ;
35 
36 using ::com::sun::star::xml::wrapper::XXMLElementWrapper ;
37 using ::com::sun::star::xml::crypto::XXMLSignatureTemplate ;
38 
XMLSignatureTemplateImpl(const Reference<XMultiServiceFactory> & aFactory)39 XMLSignatureTemplateImpl :: XMLSignatureTemplateImpl( const Reference< XMultiServiceFactory >& aFactory )
40 	:m_xTemplate( NULL ),
41      m_xServiceManager( aFactory ),
42 	 m_nStatus ( ::com::sun::star::xml::crypto::SecurityOperationStatus_UNKNOWN )
43 {
44 }
45 
~XMLSignatureTemplateImpl()46 XMLSignatureTemplateImpl :: ~XMLSignatureTemplateImpl() {
47 }
48 
49 /* XXMLSignatureTemplate */
setTemplate(const Reference<XXMLElementWrapper> & aTemplate)50 void SAL_CALL XMLSignatureTemplateImpl :: setTemplate( const Reference< XXMLElementWrapper >& aTemplate )
51 	throw( com::sun::star::uno::RuntimeException, com::sun::star::lang::IllegalArgumentException)
52 {
53 	m_xTemplate = aTemplate ;
54 }
55 
56 /* XXMLSignatureTemplate */
getTemplate()57 Reference< XXMLElementWrapper > SAL_CALL XMLSignatureTemplateImpl :: getTemplate()
58 	throw (com::sun::star::uno::RuntimeException)
59 {
60 	return m_xTemplate ;
61 }
62 
setTarget(const::com::sun::star::uno::Reference<::com::sun::star::xml::wrapper::XXMLElementWrapper> & aXmlElement)63 void SAL_CALL XMLSignatureTemplateImpl :: setTarget( const ::com::sun::star::uno::Reference< ::com::sun::star::xml::wrapper::XXMLElementWrapper >& aXmlElement )
64 	throw( com::sun::star::uno::RuntimeException, com::sun::star::lang::IllegalArgumentException)
65 {
66 	targets.push_back( aXmlElement );
67 }
68 
getTargets()69 ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Reference< ::com::sun::star::xml::wrapper::XXMLElementWrapper > > SAL_CALL XMLSignatureTemplateImpl :: getTargets()
70 	throw (com::sun::star::uno::RuntimeException)
71 {
72 	sal_Int32 length = targets.size();
73 	::com::sun::star::uno::Sequence<
74 		::com::sun::star::uno::Reference< ::com::sun::star::xml::wrapper::XXMLElementWrapper >
75 		> aTargets (length);
76 
77 	sal_Int32 i;
78 
79 	for (i=0; i<length; i++)
80 	{
81 		aTargets[i] = targets[i];
82 	}
83 
84 	return aTargets;
85 }
86 
setBinding(const::com::sun::star::uno::Reference<::com::sun::star::xml::crypto::XUriBinding> & aUriBinding)87 void SAL_CALL XMLSignatureTemplateImpl::setBinding(
88 	const ::com::sun::star::uno::Reference<
89 		::com::sun::star::xml::crypto::XUriBinding >& aUriBinding )
90 	throw (::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException)
91 {
92 	m_xUriBinding = aUriBinding;
93 }
94 
getBinding()95 ::com::sun::star::uno::Reference< ::com::sun::star::xml::crypto::XUriBinding > SAL_CALL XMLSignatureTemplateImpl::getBinding()
96 	throw (::com::sun::star::uno::RuntimeException)
97 {
98 	return m_xUriBinding;
99 }
100 
setStatus(::com::sun::star::xml::crypto::SecurityOperationStatus status)101 void SAL_CALL XMLSignatureTemplateImpl::setStatus(
102 	::com::sun::star::xml::crypto::SecurityOperationStatus status )
103 	throw (::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException)
104 {
105 	m_nStatus = status;
106 }
107 
getStatus()108 ::com::sun::star::xml::crypto::SecurityOperationStatus SAL_CALL XMLSignatureTemplateImpl::getStatus(  )
109 	throw (::com::sun::star::uno::RuntimeException)
110 {
111 	return m_nStatus;
112 }
113 
114 /* XInitialization */
initialize(const Sequence<Any> &)115 void SAL_CALL XMLSignatureTemplateImpl :: initialize( const Sequence< Any >& /*aArguments*/ ) throw( Exception, RuntimeException ) {
116 	// TBD
117 } ;
118 
119 /* XServiceInfo */
getImplementationName()120 OUString SAL_CALL XMLSignatureTemplateImpl :: getImplementationName() throw( RuntimeException ) {
121 	return impl_getImplementationName() ;
122 }
123 
124 /* XServiceInfo */
supportsService(const OUString & serviceName)125 sal_Bool SAL_CALL XMLSignatureTemplateImpl :: supportsService( const OUString& serviceName) throw( RuntimeException ) {
126 	Sequence< OUString > seqServiceNames = getSupportedServiceNames() ;
127 	const OUString* pArray = seqServiceNames.getConstArray() ;
128 	for( sal_Int32 i = 0 ; i < seqServiceNames.getLength() ; i ++ ) {
129 		if( *( pArray + i ) == serviceName )
130 			return sal_True ;
131 	}
132 	return sal_False ;
133 }
134 
135 /* XServiceInfo */
getSupportedServiceNames()136 Sequence< OUString > SAL_CALL XMLSignatureTemplateImpl :: getSupportedServiceNames() throw( RuntimeException ) {
137 	return impl_getSupportedServiceNames() ;
138 }
139 
140 //Helper for XServiceInfo
impl_getSupportedServiceNames()141 Sequence< OUString > XMLSignatureTemplateImpl :: impl_getSupportedServiceNames() {
142 	::osl::Guard< ::osl::Mutex > aGuard( ::osl::Mutex::getGlobalMutex() ) ;
143 	Sequence< OUString > seqServiceNames( 1 ) ;
144 	seqServiceNames.getArray()[0] = OUString::createFromAscii( "com.sun.star.xml.crypto.XMLSignatureTemplate" ) ;
145 	return seqServiceNames ;
146 }
147 
impl_getImplementationName()148 OUString XMLSignatureTemplateImpl :: impl_getImplementationName() throw( RuntimeException ) {
149 	return OUString::createFromAscii( "com.sun.star.xml.security.framework.XMLSignatureTemplateImpl" ) ;
150 }
151 
152 //Helper for registry
impl_createInstance(const Reference<XMultiServiceFactory> & aServiceManager)153 Reference< XInterface > SAL_CALL XMLSignatureTemplateImpl :: impl_createInstance( const Reference< XMultiServiceFactory >& aServiceManager ) throw( RuntimeException ) {
154 	return Reference< XInterface >( *new XMLSignatureTemplateImpl( aServiceManager ) ) ;
155 }
156 
impl_createFactory(const Reference<XMultiServiceFactory> & aServiceManager)157 Reference< XSingleServiceFactory > XMLSignatureTemplateImpl :: impl_createFactory( const Reference< XMultiServiceFactory >& aServiceManager ) {
158 	//Reference< XSingleServiceFactory > xFactory ;
159 	//xFactory = ::cppu::createSingleFactory( aServiceManager , impl_getImplementationName , impl_createInstance , impl_getSupportedServiceNames ) ;
160 	//return xFactory ;
161 	return ::cppu::createSingleFactory( aServiceManager , impl_getImplementationName() , impl_createInstance , impl_getSupportedServiceNames() ) ;
162 }
163 
164