Merge pull request #2250 from esdrubal/master
[mono.git] / mcs / class / referencesource / System.Web / Util / Permission.cs
1 //------------------------------------------------------------------------------
2 // <copyright file="Permission.cs" company="Microsoft">
3 //     Copyright (c) Microsoft Corporation.  All rights reserved.
4 // </copyright>                                                                
5 //------------------------------------------------------------------------------
6
7 /*
8  * 
9  * Copyright (c) 1998-1999, Microsoft Corporation
10  * 
11  */
12
13 namespace System.Web.Util {
14     using System.Security.Permissions;
15     using System.Security;
16     using System.Data.SqlClient;
17     
18     static class Permission {
19         internal static bool HasSqlClientPermission() {
20             NamedPermissionSet  permissionset = HttpRuntime.NamedPermissionSet;
21             
22             // If we don't have a NamedPermissionSet, we're in full trust
23             if (permissionset == null)
24                 return true;
25
26             // Check that the user has unrestricted SqlClientPermission
27             IPermission allowedPermission = permissionset.GetPermission(typeof(SqlClientPermission));
28
29             if (allowedPermission == null) {
30                 return false;
31             }
32             
33             IPermission askedPermission = null;
34             try {
35                 askedPermission = new SqlClientPermission(PermissionState.Unrestricted);
36             }
37             catch {
38                 return false;
39             }
40             
41             return askedPermission.IsSubsetOf(allowedPermission);
42         }
43         
44     }
45 }