using System;
using System.Collections.Generic;
using System.Text;
namespace ScrewTurn.Wiki.AclEngine {
///
/// Represents an ACL Entry.
///
public class AclEntry {
///
/// The full control action.
///
public const string FullControlAction = "*";
///
/// The controlled resource.
///
private string resource;
///
/// The controlled action on the resource.
///
private string action;
///
/// The subject whose access to the resource/action is controlled.
///
private string subject;
///
/// The entry value.
///
private Value value;
///
/// Initializes a new instance of the class.
///
/// The controlled resource.
/// The controlled action on the resource.
/// The subject whose access to the resource/action is controlled.
/// The entry value.
/// If , or are null.
/// If , or are empty.
public AclEntry(string resource, string action, string subject, Value value) {
if(resource == null) throw new ArgumentNullException("resource");
if(resource.Length == 0) throw new ArgumentException("Resource cannot be empty", "resource");
if(action == null) throw new ArgumentNullException("action");
if(action.Length == 0) throw new ArgumentException("Action cannot be empty", "action");
if(subject == null) throw new ArgumentNullException("subject");
if(subject.Length == 0) throw new ArgumentException("Subject cannot be empty", "subject");
this.resource = resource;
this.action = action;
this.subject = subject;
this.value = value;
}
///
/// Gets the controlled resource.
///
public string Resource {
get { return resource; }
}
///
/// Gets the controlled action on the resource.
///
public string Action {
get { return action; }
}
///
/// Gets the subject of the entry.
///
public string Subject {
get { return subject; }
}
///
/// Gets the value of the entry.
///
public Value Value {
get { return value; }
}
///
/// Gets a string representation of the current object.
///
/// The string representation.
public override string ToString() {
return resource + "->" + action + ": " + subject + " (" + value.ToString() + ")";
}
///
/// Gets a hash code for the current object.
///
/// The hash code.
public override int GetHashCode() {
return base.GetHashCode();
}
///
/// Determines whether this object equals another (by value).
///
/// The other object.
/// true if this object equals obj, false otherwise.
public override bool Equals(object obj) {
AclEntry other = obj as AclEntry;
if(other != null) return Equals(other);
else return false;
}
///
/// Determines whether this instance equals another (by value).
///
/// The other instance.
/// true if this instance equals other, false otherwise.
public bool Equals(AclEntry other) {
if(object.ReferenceEquals(other, null)) return false;
else return resource == other.Resource &&
action == other.Action && subject == other.Subject;
}
///
/// Determines whether two instances of are equal (by value).
///
/// The first instance.
/// The second instance.
/// true if x equals y, false otherwise.
public static bool Equals(AclEntry x, AclEntry y) {
if(object.ReferenceEquals(x, null) && !object.ReferenceEquals(x, null)) return false;
if(!object.ReferenceEquals(x, null) && object.ReferenceEquals(x, null)) return false;
if(object.ReferenceEquals(x, null) && object.ReferenceEquals(x, null)) return true;
return x.Equals(y);
}
}
///
/// Lists legal ACL Entry values.
///
public enum Value {
///
/// Deny the action.
///
Deny = 0,
///
/// Grant the action.
///
Grant = 1
}
}