1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
21 #include <cppuhelper/access_control.hxx>
23 #include <com/sun/star/security/XAccessController.hpp>
24 #include <com/sun/star/security/RuntimePermission.hpp>
25 #include <com/sun/star/io/FilePermission.hpp>
26 #include <com/sun/star/connection/SocketPermission.hpp>
28 using namespace ::osl
;
29 using namespace ::com::sun::star
;
30 using namespace ::com::sun::star::uno
;
36 inline OUString
str_ac_singleton()
38 return OUString("/singletons/com.sun.star.security.theAccessController");
45 AccessControl::AccessControl( Reference
< XComponentContext
> const & xContext
)
47 if (! (xContext
->getValueByName( str_ac_singleton() ) >>= m_xController
))
49 throw SecurityException( "no access controller!" );
53 AccessControl::AccessControl(
54 Reference
< security::XAccessController
> const & xController
)
55 : m_xController( xController
)
57 if (! m_xController
.is())
59 throw SecurityException( "no access controller!" );
63 AccessControl::AccessControl( AccessControl
const & ac
)
64 : m_xController( ac
.m_xController
)
66 if (! m_xController
.is())
68 throw SecurityException( "no access controller!" );
75 // binary comp. to all Permission structs
86 inline void __checkPermission(
87 Reference
< security::XAccessController
> const & xController
,
88 Type
const & type
, rtl_uString
* str1
, rtl_uString
* str2
)
95 a
.pType
= type
.getTypeLibType();
98 xController
->checkPermission( * static_cast< Any
* >( &a
) );
101 void AccessControl::checkRuntimePermission(
102 OUString
const & name
)
106 cppu::UnoType
<security::RuntimePermission
>::get(), name
.pData
, 0 );
109 void AccessControl::checkFilePermission(
110 OUString
const & url
,
111 OUString
const & actions
)
115 cppu::UnoType
<io::FilePermission
>::get(), url
.pData
, actions
.pData
);
118 void AccessControl::checkSocketPermission(
119 OUString
const & host
,
120 OUString
const & actions
)
124 cppu::UnoType
<connection::SocketPermission
>::get(), host
.pData
, actions
.pData
);
129 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */