2 // System.Net.WebPermissionAttribute.cs
5 // Andreas Nahr (ClassDevelopment@A-SoftTech.com)
6 // Sebastien Pouliot <sebastien@ximian.com>
8 // (C) 2003 Andreas Nahr
9 // Copyright (C) 2004 Novell, Inc (http://www.novell.com)
11 // Permission is hereby granted, free of charge, to any person obtaining
12 // a copy of this software and associated documentation files (the
13 // "Software"), to deal in the Software without restriction, including
14 // without limitation the rights to use, copy, modify, merge, publish,
15 // distribute, sublicense, and/or sell copies of the Software, and to
16 // permit persons to whom the Software is furnished to do so, subject to
17 // the following conditions:
19 // The above copyright notice and this permission notice shall be
20 // included in all copies or substantial portions of the Software.
22 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
23 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
24 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
25 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
26 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
27 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
28 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
31 using System
.Security
;
32 using System
.Security
.Permissions
;
34 namespace System
.Net
{
36 [AttributeUsage (AttributeTargets
.Assembly
| AttributeTargets
.Class
37 | AttributeTargets
.Struct
| AttributeTargets
.Constructor
38 | AttributeTargets
.Method
, AllowMultiple
= true, Inherited
= false)]
40 public sealed class WebPermissionAttribute
: CodeAccessSecurityAttribute
{
47 public WebPermissionAttribute (SecurityAction action
)
54 public string Accept
{
58 return (m_accept
as WebPermissionInfo
).Info
;
62 AlreadySet ("Accept", "Accept");
64 m_accept
= new WebPermissionInfo (WebPermissionInfoType
.InfoString
, value);
68 public string AcceptPattern
{
72 return (m_accept
as WebPermissionInfo
).Info
;
76 AlreadySet ("Accept", "AcceptPattern");
78 throw new ArgumentNullException ("AcceptPattern");
80 m_accept
= new WebPermissionInfo (WebPermissionInfoType
.InfoUnexecutedRegex
, value);
84 public string Connect
{
86 if (m_connect
== null)
88 return (m_connect
as WebPermissionInfo
).Info
;
91 if (m_connect
!= null)
92 AlreadySet ("Connect", "Connect");
94 m_connect
= new WebPermissionInfo (WebPermissionInfoType
.InfoString
, value);
98 public string ConnectPattern
{
100 if (m_connect
== null)
102 return (m_connect
as WebPermissionInfo
).Info
;
105 if (m_connect
!= null)
106 AlreadySet ("Connect", "ConnectConnectPattern");
108 throw new ArgumentNullException ("ConnectPattern");
110 m_connect
= new WebPermissionInfo (WebPermissionInfoType
.InfoUnexecutedRegex
, value);
116 public override IPermission
CreatePermission ()
118 if (this.Unrestricted
)
119 return new WebPermission (PermissionState
.Unrestricted
);
121 WebPermission newPermission
= new WebPermission ();
122 if (m_accept
!= null) {
123 newPermission
.AddPermission (NetworkAccess
.Accept
, (WebPermissionInfo
) m_accept
);
125 if (m_connect
!= null) {
126 newPermission
.AddPermission (NetworkAccess
.Connect
, (WebPermissionInfo
) m_connect
);
128 return newPermission
;
133 internal void AlreadySet (string parameter
, string property
)
135 string msg
= Locale
.GetText ("The parameter '{0}' can be set only once.");
136 throw new ArgumentException (String
.Format (msg
, parameter
), property
);