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