//----------------------------------------------------------------------- // // Copyright (c) Andrew Arnott. All rights reserved. // //----------------------------------------------------------------------- namespace DotNetOpenAuth.ApplicationBlock { using System; using System.Linq; using System.Runtime.InteropServices; using System.Security.Principal; /// /// Represents an OAuth consumer that is impersonating a known user on the system. /// [Serializable] [ComVisible(true)] internal class OAuthPrincipal : IPrincipal { /// /// The roles this user belongs to. /// private string[] roles; /// /// Initializes a new instance of the class. /// /// The identity. /// The roles this user belongs to. internal OAuthPrincipal(OAuthIdentity identity, string[] roles) { this.Identity = identity; this.roles = roles; } /// /// Initializes a new instance of the class. /// /// The username. /// The roles this user belongs to. internal OAuthPrincipal(string username, string[] roles) : this(new OAuthIdentity(username), roles) { } #region IPrincipal Members /// /// Gets the identity of the current principal. /// /// /// /// The object associated with the current principal. /// public IIdentity Identity { get; private set; } /// /// Determines whether the current principal belongs to the specified role. /// /// The name of the role for which to check membership. /// /// true if the current principal is a member of the specified role; otherwise, false. /// public bool IsInRole(string role) { return this.roles.Contains(role); } #endregion } }