merge the formfield patch from ooo-build
[ooovba.git] / cppuhelper / source / access_control.cxx
blob3e90f58cac023b7473878d719fb6a0f0b437e69f
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: access_control.cxx,v $
10 * $Revision: 1.10 $
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 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_cppuhelper.hxx"
34 #include <cppuhelper/access_control.hxx>
36 #include <com/sun/star/security/XAccessController.hpp>
37 #include <com/sun/star/security/RuntimePermission.hpp>
38 #include <com/sun/star/io/FilePermission.hpp>
39 #include <com/sun/star/connection/SocketPermission.hpp>
41 #define OUSTR(x) ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM(x) )
44 using namespace ::rtl;
45 using namespace ::osl;
46 using namespace ::com::sun::star;
47 using namespace ::com::sun::star::uno;
49 namespace
51 inline OUString str_ac_singleton()
53 return OUSTR("/singletons/com.sun.star.security.theAccessController");
57 namespace cppu
59 //__________________________________________________________________________________________________
60 AccessControl::AccessControl( Reference< XComponentContext > const & xContext )
61 SAL_THROW( (RuntimeException) )
63 if (! (xContext->getValueByName( str_ac_singleton() ) >>= m_xController))
65 throw SecurityException(
66 OUSTR("no access controller!"), Reference< XInterface >() );
69 //__________________________________________________________________________________________________
70 AccessControl::AccessControl(
71 Reference< security::XAccessController > const & xController )
72 SAL_THROW( (RuntimeException) )
73 : m_xController( xController )
75 if (! m_xController.is())
77 throw SecurityException(
78 OUSTR("no access controller!"), Reference< XInterface >() );
81 //__________________________________________________________________________________________________
82 AccessControl::AccessControl( AccessControl const & ac )
83 SAL_THROW( (RuntimeException) )
84 : m_xController( ac.m_xController )
86 if (! m_xController.is())
88 throw SecurityException(
89 OUSTR("no access controller!"), Reference< XInterface >() );
93 #ifdef SAL_W32
94 #pragma pack(push, 8)
95 #endif
96 // binary comp. to all Permission structs
97 struct __permission
99 rtl_uString * m_str1;
100 rtl_uString * m_str2;
102 #ifdef SAL_W32
103 #pragma pack(pop)
104 #endif
106 //--------------------------------------------------------------------------------------------------
107 inline void __checkPermission(
108 Reference< security::XAccessController > const & xController,
109 Type const & type, rtl_uString * str1, rtl_uString * str2 )
110 SAL_THROW( (RuntimeException) )
112 __permission perm;
113 perm.m_str1 = str1;
114 perm.m_str2 = str2;
116 uno_Any a;
117 a.pType = type.getTypeLibType();
118 a.pData = &perm;
120 xController->checkPermission( * static_cast< Any * >( &a ) );
122 //__________________________________________________________________________________________________
123 void AccessControl::checkRuntimePermission(
124 OUString const & name )
125 SAL_THROW( (RuntimeException) )
127 __checkPermission(
128 m_xController,
129 ::getCppuType( (security::RuntimePermission *)0 ), name.pData, 0 );
131 //__________________________________________________________________________________________________
132 void AccessControl::checkFilePermission(
133 OUString const & url,
134 OUString const & actions )
135 SAL_THROW( (RuntimeException) )
137 __checkPermission(
138 m_xController,
139 ::getCppuType( (io::FilePermission *)0 ), url.pData, actions.pData );
141 //__________________________________________________________________________________________________
142 void AccessControl::checkSocketPermission(
143 OUString const & host,
144 OUString const & actions )
145 SAL_THROW( (RuntimeException) )
147 __checkPermission(
148 m_xController,
149 ::getCppuType( (connection::SocketPermission *)0 ), host.pData, actions.pData );