dotgnu-pnet-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Dotgnu-pnet-commits] CVS: pnetlib/runtime/System/Security/Permissions S


From: Rhys Weatherley <address@hidden>
Subject: [Dotgnu-pnet-commits] CVS: pnetlib/runtime/System/Security/Permissions SiteIdentityPermission.cs,NONE,1.1 SiteIdentityPermissionAttribute.cs,NONE,1.1 UrlIdentityPermission.cs,NONE,1.1 UrlIdentityPermissionAttribute.cs,NONE,1.1 ZoneIdentityPermission.cs,NONE,1.1 ZoneIdentityPermissionAttribute.cs,NONE,1.1
Date: Mon, 31 Mar 2003 02:04:29 -0500

Update of /cvsroot/dotgnu-pnet/pnetlib/runtime/System/Security/Permissions
In directory subversions:/tmp/cvs-serv15176/runtime/System/Security/Permissions

Added Files:
        SiteIdentityPermission.cs SiteIdentityPermissionAttribute.cs 
        UrlIdentityPermission.cs UrlIdentityPermissionAttribute.cs 
        ZoneIdentityPermission.cs ZoneIdentityPermissionAttribute.cs 
Log Message:


More non-ECMA permissions classes.


--- NEW FILE ---
/*
 * SiteIdentityPermission.cs - Implementation of the
 *              "System.Security.Permissions.SiteIdentityPermission" class.
 *
 * Copyright (C) 2003  Southern Storm Software, Pty Ltd.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */

namespace System.Security.Permissions
{

#if !ECMA_COMPAT

using System;
using System.Security;

public sealed class SiteIdentityPermission : CodeAccessPermission
{
        // Internal state.
        private String[] sites;

        // Constructor.
        public SiteIdentityPermission(PermissionState state)
                        {
                                if(state != PermissionState.None)
                                {
                                        throw new 
ArgumentException(_("Arg_PermissionState"));
                                }
                                sites = null;
                        }
        public SiteIdentityPermission(String site)
                        {
                                sites = SplitSite(site);
                        }
        internal SiteIdentityPermission(String[] sites)
                        {
                                this.sites = sites;
                        }

        // Split a site value into individual pieces.
        private static String[] SplitSite(String site)
                        {
                                if(site == null || site == String.Empty)
                                {
                                        throw new 
ArgumentException(_("Arg_InvalidSite"));
                                }
                                String[] sites = site.Split('.');
                                foreach(String s in sites)
                                {
                                        if(s == null || s == String.Empty)
                                        {
                                                throw new 
ArgumentException(_("Arg_InvalidSite"));
                                        }
                                }
                                return sites;
                        }

        // Convert an XML value into a permissions value.
        public override void FromXml(SecurityElement esd)
                        {
                                String value;
                                if(esd == null)
                                {
                                        throw new ArgumentNullException("esd");
                                }
                                if(esd.Attribute("version") != "1")
                                {
                                        throw new 
ArgumentException(_("Arg_PermissionVersion"));
                                }
                                value = esd.Attribute("Site");
                                if(value == null)
                                {
                                        sites = null;
                                }
                                else
                                {
                                        sites = SplitSite(value);
                                }
                        }

        // Convert this permissions object into an XML value.
        public override SecurityElement ToXml()
                        {
                                SecurityElement element;
                                element = new SecurityElement("IPermission");
                                element.AddAttribute
                                        ("class",
                                         
SecurityElement.Escape(typeof(SiteIdentityPermission).
                                                                                
        AssemblyQualifiedName));
                                element.AddAttribute("version", "1");
                                if(sites != null)
                                {
                                        element.AddAttribute("Site", Site);
                                }
                                return element;
                        }

        // Implement the IPermission interface.
        public override IPermission Copy()
                        {
                                return new SiteIdentityPermission(sites);
                        }
        public override IPermission Intersect(IPermission target)
                        {
                                if(target == null)
                                {
                                        return target;
                                }
                                else if(!(target is SiteIdentityPermission))
                                {
                                        throw new 
ArgumentException(_("Arg_PermissionMismatch"));
                                }
                                else
                                {
                                        return new SiteIdentityPermission
                                                (EnvironmentPermission.Intersect
                                                        (sites, 
((SiteIdentityPermission)target).sites));
                                }
                        }
        public override bool IsSubsetOf(IPermission target)
                        {
                                if(target == null)
                                {
                                        return (sites == null || sites.Length 
== 0);
                                }
                                else if(!(target is SiteIdentityPermission))
                                {
                                        throw new 
ArgumentException(_("Arg_PermissionMismatch"));
                                }
                                else
                                {
                                        return EnvironmentPermission.IsSubsetOf
                                                (sites, 
((SiteIdentityPermission)target).sites);
                                }
                        }
        public override IPermission Union(IPermission target)
                        {
                                if(target == null)
                                {
                                        return Copy();
                                }
                                else if(!(target is SiteIdentityPermission))
                                {
                                        throw new 
ArgumentException(_("Arg_PermissionMismatch"));
                                }
                                else
                                {
                                        return new SiteIdentityPermission
                                                (EnvironmentPermission.Union
                                                        (sites, 
((SiteIdentityPermission)target).sites,
                                                         false));
                                }
                        }

        // Get or set the site string.
        public String Site
                        {
                                get
                                {
                                        if(sites == null)
                                        {
                                                return null;
                                        }
                                        else
                                        {
                                                return String.Join(".", sites);
                                        }
                                }
                                set
                                {
                                        sites = SplitSite(value);
                                }
                        }

}; // class SiteIdentityPermission

#endif // !ECMA_COMPAT

}; // namespace System.Security.Permissions

--- NEW FILE ---
/*
 * SiteIdentityPermissionAttribute.cs - Implementation of the
 *              "System.Security.Permissions.SiteIdentityPermissionAttribute" 
class.
 *
 * Copyright (C) 2003  Southern Storm Software, Pty Ltd.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */

namespace System.Security.Permissions
{

#if !ECMA_COMPAT

using System;
using System.Security;

[AttributeUsage(AttributeTargets.Assembly |
                                AttributeTargets.Class |
                                AttributeTargets.Struct |
                                AttributeTargets.Constructor |
                                AttributeTargets.Method,
                                AllowMultiple=true, Inherited=false)]
public sealed class SiteIdentityPermissionAttribute
        : CodeAccessSecurityAttribute
{
        // Internal state.
        private String site;

        // Constructors.
        public SiteIdentityPermissionAttribute(SecurityAction action)
                        : base(action)
                        {
                                // Nothing to do here.
                        }

        // Get or set the site value.
        public String Site
                        {
                                get
                                {
                                        return site;
                                }
                                set
                                {
                                        site = value;
                                }
                        }

        // Create a permission object that corresponds to this attribute.
        public override IPermission CreatePermission()
                        {
                                if(Unrestricted || site == null)
                                {
                                        throw new 
ArgumentException(_("Arg_PermissionState"));
                                }
                                else
                                {
                                        return new SiteIdentityPermission(site);
                                }
                        }

}; // class SiteIdentityPermissionAttribute

#endif // !ECMA_COMPAT

}; // namespace System.Security.Permissions

--- NEW FILE ---
/*
 * UrlIdentityPermission.cs - Implementation of the
 *              "System.Security.Permissions.UrlIdentityPermission" class.
 *
 * Copyright (C) 2003  Southern Storm Software, Pty Ltd.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */

namespace System.Security.Permissions
{

#if !ECMA_COMPAT

using System;
using System.Security;

public sealed class UrlIdentityPermission : CodeAccessPermission
{
        // Internal state.
        private String url;

        // Constructor.
        public UrlIdentityPermission(PermissionState state)
                        {
                                if(state != PermissionState.None)
                                {
                                        throw new 
ArgumentException(_("Arg_PermissionState"));
                                }
                                url = null;
                        }
        public UrlIdentityPermission(String site)
                        {
                                if(site == null)
                                {
                                        throw new ArgumentNullException("site");
                                }
                                url = site;
                        }

        // Convert an XML value into a permissions value.
        public override void FromXml(SecurityElement esd)
                        {
                                if(esd == null)
                                {
                                        throw new ArgumentNullException("esd");
                                }
                                if(esd.Attribute("version") != "1")
                                {
                                        throw new 
ArgumentException(_("Arg_PermissionVersion"));
                                }
                                url = esd.Attribute("Url");
                        }

        // Convert this permissions object into an XML value.
        public override SecurityElement ToXml()
                        {
                                SecurityElement element;
                                element = new SecurityElement("IPermission");
                                element.AddAttribute
                                        ("class",
                                         
SecurityElement.Escape(typeof(UrlIdentityPermission).
                                                                                
        AssemblyQualifiedName));
                                element.AddAttribute("version", "1");
                                if(url != null)
                                {
                                        element.AddAttribute("Url", url);
                                }
                                return element;
                        }

        // Implement the IPermission interface.
        public override IPermission Copy()
                        {
                                return new UrlIdentityPermission(url);
                        }
        public override IPermission Intersect(IPermission target)
                        {
                                if(target == null)
                                {
                                        return target;
                                }
                                else if(!(target is UrlIdentityPermission))
                                {
                                        throw new 
ArgumentException(_("Arg_PermissionMismatch"));
                                }
                                else if(url == 
((UrlIdentityPermission)target).url)
                                {
                                        return new UrlIdentityPermission(url);
                                }
                                else
                                {
                                        return new 
UrlIdentityPermission(PermissionState.None);
                                }
                        }
        public override bool IsSubsetOf(IPermission target)
                        {
                                if(target == null)
                                {
                                        return (url == null || url.Length == 0);
                                }
                                else if(!(target is UrlIdentityPermission))
                                {
                                        throw new 
ArgumentException(_("Arg_PermissionMismatch"));
                                }
                                else if(url == null ||
                                                url == 
((UrlIdentityPermission)target).url)
                                {
                                        return true;
                                }
                                else
                                {
                                        return false;
                                }
                        }
        public override IPermission Union(IPermission target)
                        {
                                if(target == null)
                                {
                                        return Copy();
                                }
                                else if(!(target is UrlIdentityPermission))
                                {
                                        throw new 
ArgumentException(_("Arg_PermissionMismatch"));
                                }
                                else if(url != null)
                                {
                                        // Return the first one, because 
union'ing two
                                        // non-empty url identities doesn't 
make sense.
                                        return Copy();
                                }
                                else
                                {
                                        return target.Copy();
                                }
                        }

        // Get or set the url string.
        public String Url
                        {
                                get
                                {
                                        return url;
                                }
                                set
                                {
                                        if(value == null)
                                        {
                                                throw new 
ArgumentNullException("value");
                                        }
                                        url = value;
                                }
                        }

}; // class UrlIdentityPermission

#endif // !ECMA_COMPAT

}; // namespace System.Security.Permissions

--- NEW FILE ---
/*
 * UrlIdentityPermissionAttribute.cs - Implementation of the
 *              "System.Security.Permissions.UrlIdentityPermissionAttribute" 
class.
 *
 * Copyright (C) 2003  Southern Storm Software, Pty Ltd.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */

namespace System.Security.Permissions
{

#if !ECMA_COMPAT

using System;
using System.Security;

[AttributeUsage(AttributeTargets.Assembly |
                                AttributeTargets.Class |
                                AttributeTargets.Struct |
                                AttributeTargets.Constructor |
                                AttributeTargets.Method,
                                AllowMultiple=true, Inherited=false)]
public sealed class UrlIdentityPermissionAttribute
        : CodeAccessSecurityAttribute
{
        // Internal state.
        private String url;

        // Constructors.
        public UrlIdentityPermissionAttribute(SecurityAction action)
                        : base(action)
                        {
                                // Nothing to do here.
                        }

        // Get or set the site value.
        public String Url
                        {
                                get
                                {
                                        return url;
                                }
                                set
                                {
                                        url = value;
                                }
                        }

        // Create a permission object that corresponds to this attribute.
        public override IPermission CreatePermission()
                        {
                                if(Unrestricted || url == null)
                                {
                                        throw new 
ArgumentException(_("Arg_PermissionState"));
                                }
                                else
                                {
                                        return new UrlIdentityPermission(url);
                                }
                        }

}; // class UrlIdentityPermissionAttribute

#endif // !ECMA_COMPAT

}; // namespace System.Security.Permissions

--- NEW FILE ---
/*
 * ZoneIdentityPermission.cs - Implementation of the
 *              "System.Security.Permissions.ZoneIdentityPermission" class.
 *
 * Copyright (C) 2003  Southern Storm Software, Pty Ltd.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */

namespace System.Security.Permissions
{

#if !ECMA_COMPAT

using System;
using System.Security;

public sealed class ZoneIdentityPermission : CodeAccessPermission
{
        // Internal state.
        private PermissionState state;
        private SecurityZone zone;

        // Constructor.
        public ZoneIdentityPermission(PermissionState state)
                        {
                                if(state != PermissionState.None)
                                {
                                        throw new 
ArgumentException(_("Arg_PermissionState"));
                                }
                                zone = SecurityZone.NoZone;
                        }
        public ZoneIdentityPermission(SecurityZone zone)
                        {
                                this.zone = zone;
                        }

        // Convert an XML value into a permissions value.
        public override void FromXml(SecurityElement esd)
                        {
                                String value;
                                if(esd == null)
                                {
                                        throw new ArgumentNullException("esd");
                                }
                                if(esd.Attribute("version") != "1")
                                {
                                        throw new 
ArgumentException(_("Arg_PermissionVersion"));
                                }
                                value = esd.Attribute("Zone");
                                if(value != null)
                                {
                                        zone = (SecurityZone)
                                                
Enum.Parse(typeof(SecurityZone), value);
                                }
                                else
                                {
                                        zone = SecurityZone.NoZone;
                                }
                        }

        // Convert this permissions object into an XML value.
        public override SecurityElement ToXml()
                        {
                                SecurityElement element;
                                element = new SecurityElement("IPermission");
                                element.AddAttribute
                                        ("class",
                                         
SecurityElement.Escape(typeof(ZoneIdentityPermission).
                                                                                
        AssemblyQualifiedName));
                                element.AddAttribute("version", "1");
                                element.AddAttribute("Zone", zone.ToString());
                                return element;
                        }

        // Implement the IPermission interface.
        public override IPermission Copy()
                        {
                                return new ZoneIdentityPermission(zone);
                        }
        public override IPermission Intersect(IPermission target)
                        {
                                FileDialogPermissionAccess newFlags;
                                if(target == null)
                                {
                                        return target;
                                }
                                else if(!(target is ZoneIdentityPermission))
                                {
                                        throw new 
ArgumentException(_("Arg_PermissionMismatch"));
                                }
                                SecurityZone otherZone = 
((ZoneIdentityPermission)target).zone;
                                if(zone != otherZone)
                                {
                                        return null;
                                }
                                else
                                {
                                        return Copy();
                                }
                        }
        public override bool IsSubsetOf(IPermission target)
                        {
                                if(target == null)
                                {
                                        return (zone == SecurityZone.NoZone);
                                }
                                else if(!(target is ZoneIdentityPermission))
                                {
                                        throw new 
ArgumentException(_("Arg_PermissionMismatch"));
                                }
                                else if(zone == SecurityZone.NoZone)
                                {
                                        return true;
                                }
                                else
                                {
                                        return (zone == 
((ZoneIdentityPermission)target).zone);
                                }
                        }
        public override IPermission Union(IPermission target)
                        {
                                if(target == null)
                                {
                                        return Copy();
                                }
                                else if(!(target is ZoneIdentityPermission))
                                {
                                        throw new 
ArgumentException(_("Arg_PermissionMismatch"));
                                }
                                SecurityZone otherZone = 
((ZoneIdentityPermission)target).zone;
                                if(zone == otherZone || otherZone == 
SecurityZone.NoZone)
                                {
                                        return Copy();
                                }
                                else if(zone == SecurityZone.NoZone)
                                {
                                        return target.Copy();
                                }
                                else
                                {
                                        return null;
                                }
                        }

        // Get or set the security zone on this permissions object.
        public SecurityZone SecurityZone
                        {
                                get
                                {
                                        return zone;
                                }
                                set
                                {
                                        zone = value;
                                }
                        }

}; // class ZoneIdentityPermission

#endif // !ECMA_COMPAT

}; // namespace System.Security.Permissions

--- NEW FILE ---
/*
 * ZoneIdentityPermissionAttribute.cs - Implementation of the
 *              "System.Security.Permissions.ZoneIdentityPermissionAttribute" 
class.
 *
 * Copyright (C) 2003  Southern Storm Software, Pty Ltd.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */

namespace System.Security.Permissions
{

#if !ECMA_COMPAT

using System;
using System.Security;

[AttributeUsage(AttributeTargets.Assembly |
                                AttributeTargets.Class |
                                AttributeTargets.Struct |
                                AttributeTargets.Constructor |
                                AttributeTargets.Method,
                                AllowMultiple=true, Inherited=false)]
public sealed class ZoneIdentityPermissionAttribute
        : CodeAccessSecurityAttribute
{
        // Internal state.
        private SecurityZone zone;

        // Constructors.
        public ZoneIdentityPermissionAttribute(SecurityAction action)
                        : base(action)
                        {
                                zone = SecurityZone.NoZone;
                        }

        // Get or set the zone value.
        public SecurityZone Zone
                        {
                                get
                                {
                                        return zone;
                                }
                                set
                                {
                                        zone = value;
                                }
                        }

        // Create a permission object that corresponds to this attribute.
        public override IPermission CreatePermission()
                        {
                                if(Unrestricted)
                                {
                                        throw new 
ArgumentException(_("Arg_PermissionState"));
                                }
                                else
                                {
                                        return new ZoneIdentityPermission(zone);
                                }
                        }

}; // class ZoneIdentityPermissionAttribute

#endif // !ECMA_COMPAT

}; // namespace System.Security.Permissions





reply via email to

[Prev in Thread] Current Thread [Next in Thread]