You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@struts.apache.org by hu...@apache.org on 2005/06/25 03:39:21 UTC
svn commit: r201703 - in /struts/sandbox/trunk/overdrive/Nexus/Core:
Core.csproj Profile/ Profile/IProfile.cs Profile/UserIdentity.cs
Profile/UserPrincipal.cs Profile/UserProfile.cs
Author: husted
Date: Fri Jun 24 18:39:19 2005
New Revision: 201703
URL: http://svn.apache.org/viewcvs?rev=201703&view=rev
Log:
OVR-18
* Add IProfile, UserIdentiy, UserPrincipal, and UserProfile.
Added:
struts/sandbox/trunk/overdrive/Nexus/Core/Profile/
struts/sandbox/trunk/overdrive/Nexus/Core/Profile/IProfile.cs
struts/sandbox/trunk/overdrive/Nexus/Core/Profile/UserIdentity.cs
struts/sandbox/trunk/overdrive/Nexus/Core/Profile/UserPrincipal.cs
struts/sandbox/trunk/overdrive/Nexus/Core/Profile/UserProfile.cs
Modified:
struts/sandbox/trunk/overdrive/Nexus/Core/Core.csproj
Modified: struts/sandbox/trunk/overdrive/Nexus/Core/Core.csproj
URL: http://svn.apache.org/viewcvs/struts/sandbox/trunk/overdrive/Nexus/Core/Core.csproj?rev=201703&r1=201702&r2=201703&view=diff
==============================================================================
--- struts/sandbox/trunk/overdrive/Nexus/Core/Core.csproj (original)
+++ struts/sandbox/trunk/overdrive/Nexus/Core/Core.csproj Fri Jun 24 18:39:19 2005
@@ -179,6 +179,26 @@
BuildAction = "Compile"
/>
<File
+ RelPath = "Profile\IProfile.cs"
+ SubType = "Code"
+ BuildAction = "Compile"
+ />
+ <File
+ RelPath = "Profile\UserIdentity.cs"
+ SubType = "Code"
+ BuildAction = "Compile"
+ />
+ <File
+ RelPath = "Profile\UserPrincipal.cs"
+ SubType = "Code"
+ BuildAction = "Compile"
+ />
+ <File
+ RelPath = "Profile\UserProfile.cs"
+ SubType = "Code"
+ BuildAction = "Compile"
+ />
+ <File
RelPath = "Tables\FieldContext.cs"
SubType = "Code"
BuildAction = "Compile"
Added: struts/sandbox/trunk/overdrive/Nexus/Core/Profile/IProfile.cs
URL: http://svn.apache.org/viewcvs/struts/sandbox/trunk/overdrive/Nexus/Core/Profile/IProfile.cs?rev=201703&view=auto
==============================================================================
--- struts/sandbox/trunk/overdrive/Nexus/Core/Profile/IProfile.cs (added)
+++ struts/sandbox/trunk/overdrive/Nexus/Core/Profile/IProfile.cs Fri Jun 24 18:39:19 2005
@@ -0,0 +1,20 @@
+using System.Globalization;
+
+namespace Nexus.Core.Profile
+{
+ /// <summary>
+ /// Record user settings.
+ /// </summary>
+ public interface IProfile
+ {
+ /// <summary>
+ /// Record the User ID.
+ /// </summary>
+ string UserId { get; set; }
+
+ /// <summary>
+ /// Record the User Locale.
+ /// </summary>
+ CultureInfo UserLocale { get; set; }
+ }
+}
\ No newline at end of file
Added: struts/sandbox/trunk/overdrive/Nexus/Core/Profile/UserIdentity.cs
URL: http://svn.apache.org/viewcvs/struts/sandbox/trunk/overdrive/Nexus/Core/Profile/UserIdentity.cs?rev=201703&view=auto
==============================================================================
--- struts/sandbox/trunk/overdrive/Nexus/Core/Profile/UserIdentity.cs (added)
+++ struts/sandbox/trunk/overdrive/Nexus/Core/Profile/UserIdentity.cs Fri Jun 24 18:39:19 2005
@@ -0,0 +1,78 @@
+using System;
+using System.Security.Principal;
+
+namespace Nexus.Core.Profile
+{
+ /// <summary>
+ /// Implement IIdentity to capture user's login name.
+ /// </summary>
+ /// <remarks><p>
+ /// An identity object represents the user on whose behalf the code is running).
+ /// </p><p>
+ /// For this to work, we must update the Web.config and the server settings.
+ /// </p><p>
+ /// Web.config: <authentication mode="Windows" /> <identity impersonate="true"/>
+ /// </p><p>
+ /// IIS Admin: Disable Anon Access on the Directory Security tab.
+ /// </p></remarks>
+ [Serializable]
+ public class UserIdentity : IIdentity
+ {
+ private string _Name;
+ public string Name
+ {
+ get { return _Name; }
+ }
+
+ private string _AuthenticationType;
+ public string AuthenticationType
+ {
+ get { return _AuthenticationType; }
+ set { _AuthenticationType = value; }
+ }
+
+ private bool _IsAuthenticated = false;
+ public bool IsAuthenticated
+ {
+ get { return _IsAuthenticated; }
+ set { _IsAuthenticated = value; }
+ }
+
+ /// <summary>
+ /// Instantiate with zero parameters.
+ /// </summary>
+ public UserIdentity ()
+ {
+ }
+
+ /// <summary>
+ /// Instantiate with an IIdentity.
+ /// </summary>
+ /// <remarks>
+ /// Essentially, create a shallow copy of the given Identity.
+ /// </remarks>
+ /// <param name="id">Identity to copy</param>
+ public UserIdentity (IIdentity id)
+ {
+ if (null != id)
+ {
+ _Name = id.Name;
+ AuthenticationType = id.AuthenticationType;
+ IsAuthenticated = id.IsAuthenticated;
+ }
+ }
+
+ /// <summary>
+ /// Instantiate from passed values.
+ /// </summary>
+ /// <param name="name">Value for user's name</param>
+ /// <param name="authenticationType">Value for AuthenticationType</param>
+ /// <param name="isAuthenticated">Value for IsAuthenticated</param>
+ public UserIdentity (string name, string authenticationType, bool isAuthenticated)
+ {
+ _Name = name;
+ _AuthenticationType = authenticationType;
+ _IsAuthenticated = isAuthenticated;
+ }
+ }
+}
\ No newline at end of file
Added: struts/sandbox/trunk/overdrive/Nexus/Core/Profile/UserPrincipal.cs
URL: http://svn.apache.org/viewcvs/struts/sandbox/trunk/overdrive/Nexus/Core/Profile/UserPrincipal.cs?rev=201703&view=auto
==============================================================================
--- struts/sandbox/trunk/overdrive/Nexus/Core/Profile/UserPrincipal.cs (added)
+++ struts/sandbox/trunk/overdrive/Nexus/Core/Profile/UserPrincipal.cs Fri Jun 24 18:39:19 2005
@@ -0,0 +1,70 @@
+using System;
+using System.Security.Principal;
+
+namespace Nexus.Core.Profile
+{
+ /// <summary>
+ /// Implement IPrincipal to capture the user's login name.
+ /// </summary>
+ /// <remarks><p>
+ /// IPrincipal - A principal object represents the security context of the
+ /// user on whose behalf the code is running, including that user's identity
+ /// (IIdentity) and any roles to which they belong.
+ /// </p></remarks>
+ [Serializable]
+ public class UserPrincipal : IPrincipal
+ {
+ private IIdentity _Identity;
+ public IIdentity Identity
+ {
+ get { return _Identity; }
+ set { _Identity = value; }
+ }
+
+ public bool IsInRole (string role)
+ {
+ if ((null == _Roles) || (0 == _Roles.Length)) return false;
+ if ((null == role) || (0 == role.Length)) return false;
+ bool found = false;
+ for (int i = 0; i < _Roles.Length; i++)
+ found = found || role.Equals (_Roles [i]);
+ return found;
+ }
+
+ /// <summary>
+ /// Field for Roles property.
+ /// </summary>
+ private string[] _Roles;
+
+ /// <summary>
+ /// The roles for this principal representated as an array.
+ /// </summary>
+ public string[] Roles
+ {
+ get { return _Roles; }
+ set { _Roles = value; }
+ }
+
+ /// <summary>
+ /// Instantiate default NexusPrincipal with empty NexusIdentity.
+ /// </summary>
+ public UserPrincipal ()
+ {
+ Identity = new UserIdentity (); // FIXME: Spring?
+ }
+
+ /// <summary>
+ /// Instantiate from an IIdentity.
+ /// </summary>
+ /// <remarks>
+ /// The Roles for this principal will follow
+ /// those set by the Roles property, regardless of the
+ /// Identity or Authentication Type.
+ /// </remarks>
+ /// <param name="id">Value for user name</param>
+ public UserPrincipal (IIdentity id)
+ {
+ Identity = new UserIdentity (id); // FIXME: Spring?
+ }
+ }
+}
\ No newline at end of file
Added: struts/sandbox/trunk/overdrive/Nexus/Core/Profile/UserProfile.cs
URL: http://svn.apache.org/viewcvs/struts/sandbox/trunk/overdrive/Nexus/Core/Profile/UserProfile.cs?rev=201703&view=auto
==============================================================================
--- struts/sandbox/trunk/overdrive/Nexus/Core/Profile/UserProfile.cs (added)
+++ struts/sandbox/trunk/overdrive/Nexus/Core/Profile/UserProfile.cs Fri Jun 24 18:39:19 2005
@@ -0,0 +1,120 @@
+using System;
+using System.Globalization;
+using System.Security.Principal;
+
+namespace Nexus.Core.Profile
+{
+ /// <summary>
+ /// Represent a user.
+ /// </summary>
+ /// <remarks><p>
+ /// The UserProfile includes a standard Principal object for
+ /// authentification and authorization.
+ /// Any user-related properties may be added here, along with
+ /// convenience methods for determining roles, such as
+ /// IsEngineer, IsManager, et al.
+ /// </p></remarks>
+ [Serializable]
+ public class UserProfile : IProfile
+ {
+ /// <summary>
+ /// Identify attribute key for storing a user profile.
+ /// </summary>
+ public const string USER_PROFILE = "USER_PROFILE";
+
+ private IPrincipal _Principal;
+ /// <summary>
+ /// Provide the Principal object for this user.
+ /// </summary>
+ /// <remarks><p>
+ /// Usually, this is a UserPrincipal,
+ /// but any IPrincipal instance could be used.
+ /// </p></remarks>
+ public IPrincipal Principal
+ {
+ get { return _Principal; }
+ set { _Principal = value; }
+ }
+
+ #region UserId
+
+ /// <summary>
+ /// Identify the character separating a "machine name" from a "user id".
+ /// </summary>
+ public static char[] USER_ID_SEPARATOR = {'\\'}; // Backslash is the quote character, so you need to escape it.
+
+ /// <summary>
+ /// Trim any machine name reference from Principal Name.
+ /// </summary>
+ /// <param name="name">A Identity Name that may contain a machine name reference</param>
+ /// <returns>Identity name with machine name removed</returns>
+ protected string TrimMachineName (string name)
+ {
+ if (null == name) return String.Empty;
+ string[] logon = name.Split (USER_ID_SEPARATOR);
+ if (logon.Length > 1) return logon [1];
+ return logon [0];
+ }
+
+ private string _UserId;
+ /// <summary>
+ /// Record the user id portion of the Identity Name.
+ /// </summary>
+ /// <remarks><p>
+ /// The UserId can be used to related staff records to user logins.
+ /// </p></remarks>
+ public string UserId
+ {
+ get
+ {
+ if (null == _UserId)
+ _UserId = TrimMachineName (Principal.Identity.Name);
+ return (null == _UserId) ? String.Empty : _UserId;
+ }
+ set { _UserId = value; }
+ }
+
+ #endregion
+
+ #region UserLocale
+
+ private CultureInfo _UserLocale;
+ public CultureInfo UserLocale
+ {
+ get { return _UserLocale; }
+ set { _UserLocale = value; }
+ }
+
+ #endregion
+
+ #region Constructors
+
+ /// <summary>
+ /// Instantiate a default profile.
+ /// </summary>
+ public UserProfile ()
+ {
+ Principal = new UserPrincipal (); // FIXME: Spring?
+ }
+
+ /// <summary>
+ /// Instantiate from an IPrincipal.
+ /// </summary>
+ /// <param name="principal">Principal for this profile.</param>
+ public UserProfile (IPrincipal principal)
+ {
+ Principal = principal;
+ }
+
+ /// <summary>
+ /// Instantiate from an IIdentity.
+ /// </summary>
+ /// <param name="id">Identity to copy for this profile.</param>
+ public UserProfile (IIdentity id)
+ {
+ Principal = new UserPrincipal (id);
+ }
+
+ #endregion
+ }
+}
\ No newline at end of file
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@struts.apache.org
For additional commands, e-mail: dev-help@struts.apache.org