// Sebastien Pouliot <sebastien@ximian.com>
//
// (C) 2002
-// Copyright (C) 2004 Novell, Inc (http://www.novell.com)
+// Copyright (C) 2004-2005 Novell, Inc (http://www.novell.com)
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
protected ResourcePermissionBase (PermissionState state) : this ()
{
- // there are no validation of the permission state
+ PermissionHelper.CheckPermissionState (state, true);
_unrestricted = (state == PermissionState.Unrestricted);
- // but any invalid value results in a restricted set
}
public const string Any = "*";
[MonoTODO ("incomplete - need more test")]
public override void FromXml (SecurityElement securityElement)
{
-// duplicate MS behaviour - reported as FDBK15052
if (securityElement == null)
- throw new NullReferenceException ("securityElement");
+ throw new ArgumentNullException ("securityElement");
CheckSecurityElement (securityElement, "securityElement", version, version);
// Note: we do not (yet) care about the return value
// as we only accept version 1 (min/max values)
+ _list.Clear ();
_unrestricted = PermissionHelper.IsUnrestricted (securityElement);
- // TODO
+ if ((securityElement.Children == null) || (securityElement.Children.Count < 1))
+ return;
+
+ string[] names = new string [1];
+ foreach (SecurityElement child in securityElement.Children) {
+ // TODO: handle multiple names
+ names [0] = child.Attribute ("name");
+ int access = (int) Enum.Parse (PermissionAccessType, child.Attribute ("access"));
+ ResourcePermissionBaseEntry entry = new ResourcePermissionBaseEntry (access, names);
+ AddPermissionAccess (entry);
+ }
}
protected ResourcePermissionBaseEntry[] GetPermissionEntries ()
public override bool IsSubsetOf (IPermission target)
{
if (target == null) {
-#if NET_2_0
// do not use Cast - different permissions (and earlier Fx) return false :-/
return true;
-#else
- return false;
-#endif
}
ResourcePermissionBase rpb = (target as ResourcePermissionBase);
else {
foreach (ResourcePermissionBaseEntry entry in _list) {
SecurityElement container = se;
+ string access = null;
+ if (PermissionAccessType != null)
+ access = Enum.Format (PermissionAccessType, entry.PermissionAccess, "g");
+
for (int i=0; i < _tags.Length; i++) {
SecurityElement child = new SecurityElement (_tags [i]);
child.AddAttribute ("name", entry.PermissionAccessPath [i]);
+ if (access != null)
+ child.AddAttribute ("access", access);
container.AddChild (child);
child = container;
}
{
if (se == null)
throw new ArgumentNullException (parameterName);
-
+ // Tag is case-sensitive
+ if (se.Tag != "IPermission") {
+ string msg = String.Format (Locale.GetText ("Invalid tag {0}"), se.Tag);
+ throw new ArgumentException (msg, parameterName);
+ }
// Note: we do not care about the class attribute at
// this stage (in fact we don't even if the class
// attribute is present or not). Anyway the object has
throw new ArgumentException (msg, parameterName, e);
}
}
-
+ if ((version < minimumVersion) || (version > maximumVersion)) {
+ string msg = Locale.GetText ("Unknown version '{0}', expected versions between ['{1}','{2}'].");
+ msg = String.Format (msg, version, minimumVersion, maximumVersion);
+ throw new ArgumentException (msg, parameterName);
+ }
return version;
}