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 #ifndef _CPPUHELPER_ACCESS_CONTROL_HXX_
24 #define _CPPUHELPER_ACCESS_CONTROL_HXX_
25 
26 #include <com/sun/star/uno/XComponentContext.hpp>
27 #include <com/sun/star/security/XAccessController.hpp>
28 
29 #include "cppuhelper/cppuhelperdllapi.h"
30 
31 
32 namespace cppu
33 {
34 
35 /** Helper class retriving access controller singleton from component context.
36 */
37 class CPPUHELPER_DLLPUBLIC AccessControl
38 {
39     ::com::sun::star::uno::Reference< ::com::sun::star::security::XAccessController > m_xController;
40 
41 public:
42     /** Ctor.
43 
44         @param xContext component context to retrieve access controller singleton
45     */
46     AccessControl(
47         ::com::sun::star::uno::Reference<
48             ::com::sun::star::uno::XComponentContext > const & xContext )
49         SAL_THROW( (::com::sun::star::uno::RuntimeException) );
50     /** Ctor.
51 
52         @param xController access controller
53     */
54     AccessControl(
55         ::com::sun::star::uno::Reference<
56             ::com::sun::star::security::XAccessController > const & xController )
57         SAL_THROW( (::com::sun::star::uno::RuntimeException) );
58     /** Copy ctor.
59 
60         @param another object
61     */
62     AccessControl( ::cppu::AccessControl const & ac )
63         SAL_THROW( (::com::sun::star::uno::RuntimeException) );
64 
65     /** Clears the access controller reference being used.
66     */
clear()67     inline void SAL_CALL clear() SAL_THROW( () )
68         { m_xController.clear(); }
69 
70     /** Returns access to the access controller reference being used.
71 
72         @return access controller
73     */
74     inline ::com::sun::star::uno::Reference<
get() const75         ::com::sun::star::security::XAccessController > const & SAL_CALL get() const SAL_THROW( () )
76         { return m_xController; }
77 
78     /** Returns access to the access controller reference being used.
79 
80         @return access controller
81     */
operator ->() const82 	inline ::com::sun::star::security::XAccessController * SAL_CALL operator -> () const SAL_THROW( () )
83 		{ return m_xController.get(); }
84 
85 
86     /** A com.sun.star.security.RuntimePermission is for runtime permissions.
87         A RuntimePermission contains a name (also referred to as a "target name") but no
88         actions list; you either have the named permission or you don't.
89 
90         @param name name of permission
91     */
92     void SAL_CALL checkRuntimePermission(
93         ::rtl::OUString const & name )
94         SAL_THROW( (::com::sun::star::uno::RuntimeException) );
95 
96     /** A com.sun.star.io.FilePermission represents access to a file or directory.
97         A FilePermission consists of a file url and a set of actions valid for that pathname.
98 
99         @param url file url
100         @param actions actions list
101     */
102     void SAL_CALL checkFilePermission(
103         ::rtl::OUString const & url,
104         ::rtl::OUString const & actions )
105         SAL_THROW( (::com::sun::star::uno::RuntimeException) );
106 
107     /** A com.sun.star.connection.SocketPermission represents access to a network via sockets.
108         A SocketPermission consists of a host specification and a set of "actions"
109         specifying ways to connect to that host.
110 
111         @param host host and optional portrange
112         @param actions actions list
113     */
114     void SAL_CALL checkSocketPermission(
115         ::rtl::OUString const & host,
116         ::rtl::OUString const & actions )
117         SAL_THROW( (::com::sun::star::uno::RuntimeException) );
118 };
119 
120 }
121 
122 #endif
123