| 1 |
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ |
| 2 |
/* |
| 3 |
* This file is part of the LibreOffice project. |
| 4 |
* |
| 5 |
* This Source Code Form is subject to the terms of the Mozilla Public |
| 6 |
* License, v. 2.0. If a copy of the MPL was not distributed with this |
| 7 |
* file, You can obtain one at http://mozilla.org/MPL/2.0/. |
| 8 |
* |
| 9 |
* This file incorporates work covered by the following license notice: |
| 10 |
* |
| 11 |
* Licensed to the Apache Software Foundation (ASF) under one or more |
| 12 |
* contributor license agreements. See the NOTICE file distributed |
| 13 |
* with this work for additional information regarding copyright |
| 14 |
* ownership. The ASF licenses this file to you under the Apache |
| 15 |
* License, Version 2.0 (the "License"); you may not use this file |
| 16 |
* except in compliance with the License. You may obtain a copy of |
| 17 |
* the License at http://www.apache.org/licenses/LICENSE-2.0 . |
| 18 |
*/ |
| 19 |
|
| 20 |
#include <sal/config.h> |
| 21 |
#include <vector> |
| 22 |
#include <cppuhelper/implbase.hxx> |
| 23 |
#include <cppuhelper/supportsservice.hxx> |
| 24 |
#include <com/sun/star/lang/XServiceInfo.hpp> |
| 25 |
#include <com/sun/star/xml/crypto/XXMLSecurityContext.hpp> |
| 26 |
#include <o3tl/safeint.hxx> |
| 27 |
|
| 28 |
namespace com::sun::star::uno { class XComponentContext; } |
| 29 |
|
| 30 |
using namespace ::com::sun::star; |
| 31 |
using namespace ::com::sun::star::lang ; |
| 32 |
|
| 33 |
using ::com::sun::star::xml::crypto::XSecurityEnvironment ; |
| 34 |
using ::com::sun::star::xml::crypto::XXMLSecurityContext ; |
| 35 |
|
| 36 |
namespace { |
| 37 |
|
| 38 |
class XMLSecurityContext_NssImpl |
| 39 |
: public ::cppu::WeakImplHelper<xml::crypto::XXMLSecurityContext, lang::XServiceInfo> |
| 40 |
{ |
| 41 |
private: |
| 42 |
std::vector<uno::Reference<xml::crypto::XSecurityEnvironment>> m_vSecurityEnvironments; |
| 43 |
|
| 44 |
sal_Int32 m_nDefaultEnvIndex; |
| 45 |
|
| 46 |
public: |
| 47 |
XMLSecurityContext_NssImpl(); |
| 48 |
|
| 49 |
//XXMLSecurityContext |
| 50 |
virtual sal_Int32 SAL_CALL addSecurityEnvironment( |
| 51 |
const uno::Reference<xml::crypto::XSecurityEnvironment>& aSecurityEnvironment) override; |
| 52 |
|
| 53 |
virtual ::sal_Int32 SAL_CALL getSecurityEnvironmentNumber() override; |
| 54 |
|
| 55 |
virtual uno::Reference<xml::crypto::XSecurityEnvironment> |
| 56 |
SAL_CALL getSecurityEnvironmentByIndex(::sal_Int32 index) override; |
| 57 |
|
| 58 |
virtual uno::Reference<xml::crypto::XSecurityEnvironment> |
| 59 |
SAL_CALL getSecurityEnvironment() override; |
| 60 |
|
| 61 |
virtual ::sal_Int32 SAL_CALL getDefaultSecurityEnvironmentIndex() override; |
| 62 |
|
| 63 |
virtual void SAL_CALL setDefaultSecurityEnvironmentIndex(sal_Int32 nDefaultEnvIndex) override; |
| 64 |
|
| 65 |
//XServiceInfo |
| 66 |
virtual OUString SAL_CALL getImplementationName() override; |
| 67 |
|
| 68 |
virtual sal_Bool SAL_CALL supportsService(const OUString& ServiceName) override; |
| 69 |
|
| 70 |
virtual uno::Sequence<OUString> SAL_CALL getSupportedServiceNames() override; |
| 71 |
}; |
| 72 |
|
| 73 |
} |
| 74 |
|
| 75 |
XMLSecurityContext_NssImpl::XMLSecurityContext_NssImpl() |
| 76 |
: m_nDefaultEnvIndex(-1) |
| 77 |
{ |
| 78 |
} |
| 79 |
|
| 80 |
sal_Int32 SAL_CALL XMLSecurityContext_NssImpl::addSecurityEnvironment( |
| 81 |
const uno::Reference< xml::crypto::XSecurityEnvironment >& aSecurityEnvironment) |
| 82 |
{ |
| 83 |
if( !aSecurityEnvironment.is() ) |
| 84 |
{ |
| 85 |
throw uno::RuntimeException() ; |
| 86 |
} |
| 87 |
|
| 88 |
m_vSecurityEnvironments.push_back( aSecurityEnvironment ); |
| 89 |
|
| 90 |
return m_vSecurityEnvironments.size() - 1 ; |
| 91 |
} |
| 92 |
|
| 93 |
|
| 94 |
sal_Int32 SAL_CALL XMLSecurityContext_NssImpl::getSecurityEnvironmentNumber( ) |
| 95 |
{ |
| 96 |
return m_vSecurityEnvironments.size(); |
| 97 |
} |
| 98 |
|
| 99 |
uno::Reference< xml::crypto::XSecurityEnvironment > SAL_CALL |
| 100 |
XMLSecurityContext_NssImpl::getSecurityEnvironmentByIndex( sal_Int32 index ) |
| 101 |
{ |
| 102 |
if (index < 0 || o3tl::make_unsigned(index) >= m_vSecurityEnvironments.size()) |
| 103 |
throw uno::RuntimeException(); |
| 104 |
|
| 105 |
uno::Reference< xml::crypto::XSecurityEnvironment > xSecurityEnvironment = m_vSecurityEnvironments[index]; |
| 106 |
return xSecurityEnvironment; |
| 107 |
} |
| 108 |
|
| 109 |
uno::Reference< xml::crypto::XSecurityEnvironment > SAL_CALL |
| 110 |
XMLSecurityContext_NssImpl::getSecurityEnvironment( ) |
| 111 |
{ |
| 112 |
if (m_nDefaultEnvIndex < 0 || o3tl::make_unsigned(m_nDefaultEnvIndex) >= m_vSecurityEnvironments.size()) |
| 113 |
throw uno::RuntimeException(); |
| 114 |
|
| 115 |
return getSecurityEnvironmentByIndex(m_nDefaultEnvIndex); |
| 116 |
} |
| 117 |
|
| 118 |
sal_Int32 SAL_CALL XMLSecurityContext_NssImpl::getDefaultSecurityEnvironmentIndex( ) |
| 119 |
{ |
| 120 |
return m_nDefaultEnvIndex ; |
| 121 |
} |
| 122 |
|
| 123 |
void SAL_CALL XMLSecurityContext_NssImpl::setDefaultSecurityEnvironmentIndex( sal_Int32 nDefaultEnvIndex ) |
| 124 |
{ |
| 125 |
m_nDefaultEnvIndex = nDefaultEnvIndex; |
| 126 |
} |
| 127 |
|
| 128 |
/* XServiceInfo */ |
| 129 |
OUString SAL_CALL XMLSecurityContext_NssImpl::getImplementationName() { |
| 130 |
return u"com.sun.star.xml.crypto.XMLSecurityContext"_ustr; |
| 131 |
} |
| 132 |
|
| 133 |
/* XServiceInfo */ |
| 134 |
sal_Bool SAL_CALL XMLSecurityContext_NssImpl::supportsService( const OUString& serviceName) { |
| 135 |
return cppu::supportsService(this, serviceName); |
| 136 |
} |
| 137 |
|
| 138 |
/* XServiceInfo */ |
| 139 |
uno::Sequence< OUString > SAL_CALL XMLSecurityContext_NssImpl::getSupportedServiceNames() { |
| 140 |
return { u"com.sun.star.xml.crypto.XMLSecurityContext"_ustr }; |
| 141 |
} |
| 142 |
|
| 143 |
extern "C" SAL_DLLPUBLIC_EXPORT uno::XInterface* |
| 144 |
com_sun_star_xml_crypto_XMLSecurityContext_get_implementation( |
| 145 |
uno::XComponentContext* /*pCtx*/, uno::Sequence<uno::Any> const& /*rSeq*/) |
| 146 |
{ |
| 147 |
return cppu::acquire(new XMLSecurityContext_NssImpl); |
| 148 |
} |
| 149 |
|
| 150 |
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |