History

Renamed folders and separated GSF.Media and GSF.Net into separate projects.

StephenCWills committed 14 years ago

Commit ac1ef661 parent 45bce55628 files · +733 −461Browse files

Showing the changes to Source/Libraries/GSF.ServiceProcess/ClientInfo.cs (1 of 628 files). Show all

Unified · Split

Source/Libraries/GSF.ServiceProcess/ClientInfo.cs+201−0
@@ -0,0 +1,201 @@
1+//******************************************************************************************************
2+// ClientInfo.cs - Gbtc
3+//
4+// Copyright � 2010, Grid Protection Alliance. All Rights Reserved.
5+//
6+// Licensed to the Grid Protection Alliance (GPA) under one or more contributor license agreements. See
7+// the NOTICE file distributed with this work for additional information regarding copyright ownership.
8+// The GPA licenses this file to you under the Eclipse Public License -v 1.0 (the "License"); you may
9+// not use this file except in compliance with the License. You may obtain a copy of the License at:
10+//
11+// http://www.opensource.org/licenses/eclipse-1.0.php
12+//
13+// Unless agreed to in writing, the subject software distributed under the License is distributed on an
14+// "AS-IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. Refer to the
15+// License for the specific language governing permissions and limitations.
16+//
17+// Code Modification History:
18+// ----------------------------------------------------------------------------------------------------
19+// 09/12/2006 - Pinal C. Patel
20+// Generated original version of source code.
21+// 09/30/2008 - James R. Carroll
22+// Converted to C#.
23+// 03/09/2009 - Pinal C. Patel
24+// Edited code comments.
25+// 07/10/2009 - Pinal C. Patel
26+// Modified to transmit serialized identity token used for authentication by the ServiceHelper.
27+// 07/21/2009 - Pinal C. Patel
28+// Modified identity token generation to use the new ClientHelper.AuthenticationInput property.
29+// 09/14/2009 - Stephen C. Wills
30+// Added new header and license agreement.
31+// 02/08/2010 - Pinal C. Patel
32+// Corrected the assignment of ClientName property for web applications.
33+// 06/16/2010 - Pinal C. Patel
34+// Made changes necessary to implement role-based security.
35+// 10/8/2012 - Danyelle Gilliam
36+// Modified Header
37+//
38+//******************************************************************************************************
39+
40+
41+
42+using GSF.Identity;
43+using GSF.Reflection;
44+using System;
45+using System.Security.Principal;
46+using System.Web.Hosting;
47+
48+namespace GSF.ServiceProcess
49+{
50+ /// <summary>
51+ /// Represents information about a client using <see cref="ClientHelper"/> for connecting to a Windows Service that uses <see cref="ServiceHelper"/>.
52+ /// </summary>
53+ /// <remarks>
54+ /// <see cref="ClientInfo"/> can be serialized and deserialized using <see cref="System.Runtime.Serialization.Formatters.Binary.BinaryFormatter"/> only.
55+ /// </remarks>
56+ /// <seealso cref="ClientHelper"/>
57+ /// <seealso cref="ServiceHelper"/>
58+ [Serializable()]
59+ public class ClientInfo
60+ {
61+ #region [ Members ]
62+
63+ // Fields
64+ private Guid m_clientID;
65+ private ApplicationType m_clientType;
66+ private string m_clientName;
67+ private IPrincipal m_clientUser;
68+ private string m_clientUserCredentials;
69+ private string m_machineName;
70+ private DateTime m_connectedAt;
71+
72+ #endregion
73+
74+ #region [ Constructors ]
75+
76+ /// <summary>
77+ /// Initializes a new instance of the <see cref="ClientInfo"/> class.
78+ /// </summary>
79+ public ClientInfo()
80+ : this(null)
81+ {
82+ }
83+
84+ /// <summary>
85+ /// Initializes a new instance of the <see cref="ClientInfo"/> class.
86+ /// </summary>
87+ /// <param name="parent">An <see cref="ClientHelper"/> object.</param>
88+ public ClientInfo(ClientHelper parent)
89+ {
90+ // Initialize member variables.
91+ m_clientType = Common.GetApplicationType();
92+ m_machineName = Environment.MachineName;
93+
94+ // Initialize user principal.
95+ if (m_clientType == ApplicationType.Web)
96+ m_clientUser = new GenericPrincipal(new GenericIdentity(UserInfo.RemoteUserID), new string[] { });
97+ else
98+ m_clientUser = new GenericPrincipal(new GenericIdentity(UserInfo.CurrentUserID), new string[] { });
99+
100+ // TODO: Must validate that SSL is enabled before sending unencrypted username/password across the wire.
101+ // Initialize user credentials.
102+ if (parent == null || string.IsNullOrEmpty(parent.Username) || string.IsNullOrEmpty(parent.Password))
103+ m_clientUserCredentials = string.Empty;
104+ else
105+ m_clientUserCredentials = string.Format("{0}:{1}", parent.Username, parent.Password);
106+
107+ // Initialize client application name.
108+ if (m_clientType == ApplicationType.Web)
109+ {
110+ if (HostingEnvironment.ApplicationVirtualPath == "/")
111+ m_clientName = HostingEnvironment.SiteName;
112+ else
113+ m_clientName = HostingEnvironment.ApplicationVirtualPath.Trim('/');
114+ }
115+ else
116+ {
117+ m_clientName = AssemblyInfo.EntryAssembly.Name;
118+ }
119+ }
120+
121+ #endregion
122+
123+ #region [ Properties ]
124+
125+ /// <summary>
126+ /// Gets the identifier of the remote client application.
127+ /// </summary>
128+ public Guid ClientID
129+ {
130+ get { return m_clientID; }
131+ set { m_clientID = value; }
132+ }
133+
134+ /// <summary>
135+ /// Gets the <see cref="ApplicationType"/> of the remote client application.
136+ /// </summary>
137+ public ApplicationType ClientType
138+ {
139+ get { return m_clientType; }
140+ }
141+
142+ /// <summary>
143+ /// Gets the friendly name of the remote client application.
144+ /// </summary>
145+ public string ClientName
146+ {
147+ get { return m_clientName; }
148+ }
149+
150+ /// <summary>
151+ /// Gets the <see cref="IPrincipal"/> of the remote client application's user.
152+ /// </summary>
153+ public IPrincipal ClientUser
154+ {
155+ get { return m_clientUser; }
156+ }
157+
158+ /// <summary>
159+ /// Gets the credentials in 'username:password' format for authenticating the remote client application's user if a valid <see cref="ClientUser"/> is not available.
160+ /// </summary>
161+ public string ClientUserCredentials
162+ {
163+ get { return m_clientUserCredentials; }
164+ }
165+
166+ /// <summary>
167+ /// Gets the name of the machine running the remote client application.
168+ /// </summary>
169+ public string MachineName
170+ {
171+ get { return m_machineName; }
172+ }
173+
174+ /// <summary>
175+ /// Gets or sets the <see cref="DateTime"/> when the remote client application connected to the <see cref="ServiceHelper"/>.
176+ /// </summary>
177+ public DateTime ConnectedAt
178+ {
179+ get { return m_connectedAt; }
180+ set { m_connectedAt = value; }
181+ }
182+
183+ #endregion
184+
185+ #region [ Methods ]
186+
187+ /// <summary>
188+ /// Updates the <see cref="ClientUser"/>.
189+ /// </summary>
190+ /// <param name="user">New <see cref="IPrincipal"/> object to be assigned to <see cref="ClientUser"/>.</param>
191+ internal void SetClientUser(IPrincipal user)
192+ {
193+ if (user == null)
194+ throw new ArgumentNullException("user");
195+
196+ m_clientUser = user;
197+ }
198+
199+ #endregion
200+ }
201+}

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t