diff options
author | Miklos Vajna <vmiklos@collabora.co.uk> | 2018-02-23 09:08:10 +0100 |
---|---|---|
committer | Miklos Vajna <vmiklos@collabora.co.uk> | 2018-02-26 09:08:52 +0100 |
commit | 0f62b798acf9c53cd6e151daf908a432a02e5771 (patch) | |
tree | 1d26174168a545f55761ea3d8bf6cac06ec90b6a /xmlsecurity | |
parent | 08ab1f46b192a188935fdffbefdc9f3973583cdf (diff) |
xmlsecurity nss: create XMLSecurityContext instances with a constructor
Change-Id: I0133469e08b6d48aaf949e928ec4436d309963eb
Reviewed-on: https://gerrit.libreoffice.org/50223
Tested-by: Jenkins <ci@libreoffice.org>
Reviewed-by: Miklos Vajna <vmiklos@collabora.co.uk>
Diffstat (limited to 'xmlsecurity')
5 files changed, 57 insertions, 161 deletions
diff --git a/xmlsecurity/source/xmlsec/nss/xmlsecuritycontext_nssimpl.cxx b/xmlsecurity/source/xmlsec/nss/xmlsecuritycontext_nssimpl.cxx index 17e709eead02..b894cd098330 100644 --- a/xmlsecurity/source/xmlsec/nss/xmlsecuritycontext_nssimpl.cxx +++ b/xmlsecurity/source/xmlsec/nss/xmlsecuritycontext_nssimpl.cxx @@ -18,12 +18,13 @@ */ #include <sal/config.h> +#include <vector> #include <rtl/uuid.h> +#include <cppuhelper/supportsservice.hxx> #include "securityenvironment_nssimpl.hxx" +#include <com/sun/star/xml/crypto/XXMLSecurityContext.hpp> -#include "xmlsecuritycontext_nssimpl.hxx" - -using namespace ::com::sun::star::uno ; +using namespace ::com::sun::star; using namespace ::com::sun::star::lang ; using ::com::sun::star::lang::XMultiServiceFactory ; using ::com::sun::star::lang::XSingleServiceFactory ; @@ -31,21 +32,52 @@ using ::com::sun::star::lang::XSingleServiceFactory ; using ::com::sun::star::xml::crypto::XSecurityEnvironment ; using ::com::sun::star::xml::crypto::XXMLSecurityContext ; -XMLSecurityContext_NssImpl::XMLSecurityContext_NssImpl() - : m_nDefaultEnvIndex(-1) +class XMLSecurityContext_NssImpl + : public ::cppu::WeakImplHelper<xml::crypto::XXMLSecurityContext, lang::XServiceInfo> { -} +private: + std::vector<uno::Reference<xml::crypto::XSecurityEnvironment>> m_vSecurityEnvironments; + + sal_Int32 m_nDefaultEnvIndex; + +public: + XMLSecurityContext_NssImpl(); + + //XXMLSecurityContext + virtual sal_Int32 SAL_CALL addSecurityEnvironment( + const uno::Reference<xml::crypto::XSecurityEnvironment>& aSecurityEnvironment) override; + + virtual ::sal_Int32 SAL_CALL getSecurityEnvironmentNumber() override; + + virtual uno::Reference<xml::crypto::XSecurityEnvironment> + SAL_CALL getSecurityEnvironmentByIndex(::sal_Int32 index) override; + + virtual uno::Reference<xml::crypto::XSecurityEnvironment> + SAL_CALL getSecurityEnvironment() override; + + virtual ::sal_Int32 SAL_CALL getDefaultSecurityEnvironmentIndex() override; + + virtual void SAL_CALL setDefaultSecurityEnvironmentIndex(sal_Int32 nDefaultEnvIndex) override; + + //XServiceInfo + virtual OUString SAL_CALL getImplementationName() override; -XMLSecurityContext_NssImpl::~XMLSecurityContext_NssImpl() + virtual sal_Bool SAL_CALL supportsService(const OUString& ServiceName) override; + + virtual uno::Sequence<OUString> SAL_CALL getSupportedServiceNames() override; +}; + +XMLSecurityContext_NssImpl::XMLSecurityContext_NssImpl() + : m_nDefaultEnvIndex(-1) { } sal_Int32 SAL_CALL XMLSecurityContext_NssImpl::addSecurityEnvironment( - const css::uno::Reference< css::xml::crypto::XSecurityEnvironment >& aSecurityEnvironment) + const uno::Reference< xml::crypto::XSecurityEnvironment >& aSecurityEnvironment) { if( !aSecurityEnvironment.is() ) { - throw RuntimeException() ; + throw uno::RuntimeException() ; } m_vSecurityEnvironments.push_back( aSecurityEnvironment ); @@ -59,21 +91,21 @@ sal_Int32 SAL_CALL XMLSecurityContext_NssImpl::getSecurityEnvironmentNumber( ) return m_vSecurityEnvironments.size(); } -css::uno::Reference< css::xml::crypto::XSecurityEnvironment > SAL_CALL +uno::Reference< xml::crypto::XSecurityEnvironment > SAL_CALL XMLSecurityContext_NssImpl::getSecurityEnvironmentByIndex( sal_Int32 index ) { if (index < 0 || index >= static_cast<sal_Int32>(m_vSecurityEnvironments.size())) - throw RuntimeException(); + throw uno::RuntimeException(); - css::uno::Reference< css::xml::crypto::XSecurityEnvironment > xSecurityEnvironment = m_vSecurityEnvironments[index]; + uno::Reference< xml::crypto::XSecurityEnvironment > xSecurityEnvironment = m_vSecurityEnvironments[index]; return xSecurityEnvironment; } -css::uno::Reference< css::xml::crypto::XSecurityEnvironment > SAL_CALL +uno::Reference< xml::crypto::XSecurityEnvironment > SAL_CALL XMLSecurityContext_NssImpl::getSecurityEnvironment( ) { if (m_nDefaultEnvIndex < 0 || m_nDefaultEnvIndex >= static_cast<sal_Int32>(m_vSecurityEnvironments.size())) - throw RuntimeException(); + throw uno::RuntimeException(); return getSecurityEnvironmentByIndex(m_nDefaultEnvIndex); } @@ -90,44 +122,25 @@ void SAL_CALL XMLSecurityContext_NssImpl::setDefaultSecurityEnvironmentIndex( sa /* XServiceInfo */ OUString SAL_CALL XMLSecurityContext_NssImpl::getImplementationName() { - return impl_getImplementationName() ; + return OUString("com.sun.star.xml.crypto.XMLSecurityContext"); } /* XServiceInfo */ sal_Bool SAL_CALL XMLSecurityContext_NssImpl::supportsService( const OUString& serviceName) { - Sequence< OUString > seqServiceNames = getSupportedServiceNames() ; - const OUString* pArray = seqServiceNames.getConstArray() ; - for( sal_Int32 i = 0 ; i < seqServiceNames.getLength() ; i ++ ) { - if( *( pArray + i ) == serviceName ) - return true ; - } - return false ; + return cppu::supportsService(this, serviceName); } /* XServiceInfo */ -Sequence< OUString > SAL_CALL XMLSecurityContext_NssImpl::getSupportedServiceNames() { - return impl_getSupportedServiceNames() ; -} - -//Helper for XServiceInfo -Sequence< OUString > XMLSecurityContext_NssImpl::impl_getSupportedServiceNames() { - ::osl::Guard< ::osl::Mutex > aGuard( ::osl::Mutex::getGlobalMutex() ) ; - Sequence<OUString> seqServiceNames { "com.sun.star.xml.crypto.XMLSecurityContext" }; +uno::Sequence< OUString > SAL_CALL XMLSecurityContext_NssImpl::getSupportedServiceNames() { + uno::Sequence<OUString> seqServiceNames { "com.sun.star.xml.crypto.XMLSecurityContext" }; return seqServiceNames ; } -OUString XMLSecurityContext_NssImpl::impl_getImplementationName() { - return OUString("com.sun.star.xml.security.bridge.xmlsec.XMLSecurityContext_NssImpl") ; -} - -//Helper for registry -Reference< XInterface > SAL_CALL XMLSecurityContext_NssImpl::impl_createInstance( const Reference< XMultiServiceFactory >& ) { - return Reference< XInterface >( *new XMLSecurityContext_NssImpl ) ; -} - -Reference< XSingleServiceFactory > XMLSecurityContext_NssImpl::impl_createFactory( const Reference< XMultiServiceFactory >& aServiceManager ) { - return ::cppu::createSingleFactory( aServiceManager , impl_getImplementationName() , impl_createInstance , impl_getSupportedServiceNames() ) ; +extern "C" SAL_DLLPUBLIC_EXPORT uno::XInterface* +com_sun_star_xml_crypto_XMLSecurityContext_get_implementation( + uno::XComponentContext* /*pCtx*/, uno::Sequence<uno::Any> const& /*rSeq*/) +{ + return cppu::acquire(new XMLSecurityContext_NssImpl); } - /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/xmlsecurity/source/xmlsec/nss/xmlsecuritycontext_nssimpl.hxx b/xmlsecurity/source/xmlsec/nss/xmlsecuritycontext_nssimpl.hxx deleted file mode 100644 index 3d611424a9f3..000000000000 --- a/xmlsecurity/source/xmlsec/nss/xmlsecuritycontext_nssimpl.hxx +++ /dev/null @@ -1,111 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* - * This file is part of the LibreOffice project. - * - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. - * - * This file incorporates work covered by the following license notice: - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed - * with this work for additional information regarding copyright - * ownership. The ASF licenses this file to you under the Apache - * License, Version 2.0 (the "License"); you may not use this file - * except in compliance with the License. You may obtain a copy of - * the License at http://www.apache.org/licenses/LICENSE-2.0 . - */ - -#ifndef INCLUDED_XMLSECURITY_SOURCE_XMLSEC_NSS_XMLSECURITYCONTEXT_NSSIMPL_HXX -#define INCLUDED_XMLSECURITY_SOURCE_XMLSEC_NSS_XMLSECURITYCONTEXT_NSSIMPL_HXX - -#include <sal/config.h> -#include <rtl/ustring.hxx> -#include <cppuhelper/factory.hxx> -#include <cppuhelper/implbase.hxx> -#include <com/sun/star/uno/Exception.hpp> - -#include <com/sun/star/uno/Reference.hxx> -#include <com/sun/star/lang/XSingleServiceFactory.hpp> - -#include <com/sun/star/lang/XServiceInfo.hpp> -#include <com/sun/star/lang/XUnoTunnel.hpp> -#include <com/sun/star/xml/crypto/XSecurityEnvironment.hpp> -#include <com/sun/star/xml/crypto/XXMLSecurityContext.hpp> - -#include <vector> - -class XMLSecurityContext_NssImpl : public ::cppu::WeakImplHelper< - css::xml::crypto::XXMLSecurityContext , - css::lang::XServiceInfo > -{ - private: - std::vector< css::uno::Reference< css::xml::crypto::XSecurityEnvironment > > m_vSecurityEnvironments; - - sal_Int32 m_nDefaultEnvIndex; - - public: - XMLSecurityContext_NssImpl() ; - virtual ~XMLSecurityContext_NssImpl() override ; - - //Methods from XXMLSecurityContext - virtual sal_Int32 SAL_CALL addSecurityEnvironment( - const css::uno::Reference< css::xml::crypto::XSecurityEnvironment >& aSecurityEnvironment - ) override; - - virtual ::sal_Int32 SAL_CALL getSecurityEnvironmentNumber( ) override; - - virtual css::uno::Reference< - css::xml::crypto::XSecurityEnvironment > SAL_CALL - getSecurityEnvironmentByIndex( ::sal_Int32 index ) override; - - virtual css::uno::Reference< - css::xml::crypto::XSecurityEnvironment > SAL_CALL - getSecurityEnvironment( ) override; - - virtual ::sal_Int32 SAL_CALL getDefaultSecurityEnvironmentIndex( ) override; - - virtual void SAL_CALL setDefaultSecurityEnvironmentIndex( sal_Int32 nDefaultEnvIndex ) override; - - //Methods from XServiceInfo - virtual OUString SAL_CALL getImplementationName() override ; - - virtual sal_Bool SAL_CALL supportsService( - const OUString& ServiceName - ) override ; - - virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override ; - - //Helper for XServiceInfo - static css::uno::Sequence< OUString > impl_getSupportedServiceNames() ; - - /// @throws css::uno::RuntimeException - static OUString impl_getImplementationName() ; - - //Helper for registry - /// @throws css::uno::RuntimeException - static css::uno::Reference< css::uno::XInterface > SAL_CALL impl_createInstance( const css::uno::Reference< css::lang::XMultiServiceFactory >& aServiceManager ) ; - - static css::uno::Reference< css::lang::XSingleServiceFactory > impl_createFactory( const css::uno::Reference< css::lang::XMultiServiceFactory >& aServiceManager ) ; - - /* - * Because of the issue of multi-securityenvironment, so the keyManager method is not useful any longer. - * - - //Methods from XUnoTunnel - virtual sal_Int64 SAL_CALL getSomething( const css::uno::Sequence< sal_Int8 >& aIdentifier ) - throw (css::uno::RuntimeException); - - static const css::uno::Sequence< sal_Int8 >& getUnoTunnelId() ; - static XMLSecurityContext_NssImpl* getImplementation( const css::uno::Reference< css::uno::XInterface > xObj ) ; - - //Native methods - virtual xmlSecKeysMngrPtr keysManager() throw( css::uno::Exception , css::uno::RuntimeException ) ; - - */ -} ; - -#endif // INCLUDED_XMLSECURITY_SOURCE_XMLSEC_NSS_XMLSECURITYCONTEXT_NSSIMPL_HXX - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/xmlsecurity/source/xmlsec/nss/xmlsignature_nssimpl.cxx b/xmlsecurity/source/xmlsec/nss/xmlsignature_nssimpl.cxx index 5eef5e80ae28..bc8d3ca2517f 100644 --- a/xmlsecurity/source/xmlsec/nss/xmlsignature_nssimpl.cxx +++ b/xmlsecurity/source/xmlsec/nss/xmlsignature_nssimpl.cxx @@ -27,8 +27,6 @@ #include "securityenvironment_nssimpl.hxx" -#include "xmlsecuritycontext_nssimpl.hxx" - #include <xmlsec-wrapper.h> #include <com/sun/star/xml/crypto/XXMLSignature.hpp> diff --git a/xmlsecurity/source/xmlsec/nss/xsec_nss.cxx b/xmlsecurity/source/xmlsec/nss/xsec_nss.cxx index 99582c3bf593..a6b489ffb189 100644 --- a/xmlsecurity/source/xmlsec/nss/xsec_nss.cxx +++ b/xmlsecurity/source/xmlsec/nss/xsec_nss.cxx @@ -25,7 +25,6 @@ #include <com/sun/star/lang/XSingleServiceFactory.hpp> #include "seinitializer_nssimpl.hxx" -#include "xmlsecuritycontext_nssimpl.hxx" #include <xsec_xmlsec.hxx> #include "securityenvironment_nssimpl.hxx" @@ -52,10 +51,6 @@ void* nss_component_getFactory( const sal_Char* pImplName , void* pServiceManage OUString::createFromAscii( pImplName ), SEInitializer_NssImpl_createInstance, SEInitializer_NssImpl_getSupportedServiceNames() ) ); } - else if( XMLSecurityContext_NssImpl::impl_getImplementationName().equalsAscii( pImplName ) ) - { - xFactory = XMLSecurityContext_NssImpl::impl_createFactory( static_cast< XMultiServiceFactory* >( pServiceManager ) ) ; - } else if( SecurityEnvironment_NssImpl::impl_getImplementationName().equalsAscii( pImplName ) ) { xFactory = SecurityEnvironment_NssImpl::impl_createFactory( static_cast< XMultiServiceFactory* >( pServiceManager ) ) ; diff --git a/xmlsecurity/util/xsec_xmlsec.component b/xmlsecurity/util/xsec_xmlsec.component index 7282c0efb67e..677e2c7ed93c 100644 --- a/xmlsecurity/util/xsec_xmlsec.component +++ b/xmlsecurity/util/xsec_xmlsec.component @@ -35,7 +35,8 @@ <implementation name="com.sun.star.xml.security.bridge.xmlsec.XMLElementWrapper_XmlSecImpl"> <service name="com.sun.star.xml.wrapper.XMLElementWrapper"/> </implementation> - <implementation name="com.sun.star.xml.security.bridge.xmlsec.XMLSecurityContext_NssImpl"> + <implementation name="com.sun.star.xml.crypto.XMLSecurityContext" + constructor="com_sun_star_xml_crypto_XMLSecurityContext_get_implementation"> <service name="com.sun.star.xml.crypto.XMLSecurityContext"/> </implementation> <implementation name="com.sun.star.xml.crypto.XMLSignature" |