1 | using System;
|
---|
2 | using System.Diagnostics;
|
---|
3 | using System.Text;
|
---|
4 | using System.IO;
|
---|
5 | using System.Net.Sockets;
|
---|
6 | using System.Net;
|
---|
7 | using System.Security.Cryptography;
|
---|
8 | using System.Security.Permissions;
|
---|
9 | using System.Security.Principal;
|
---|
10 | using System.Threading;
|
---|
11 | using System.Timers;
|
---|
12 | using IndianHealthService.BMXNet.Services;
|
---|
13 | using IndianHealthService.BMXNet.Model;
|
---|
14 |
|
---|
15 | namespace IndianHealthService.BMXNet.Net
|
---|
16 | {
|
---|
17 | /// <summary>
|
---|
18 | /// BMXNetBroker implements low-level socket connectivity to RPMS databases.
|
---|
19 | /// The VA RPC Broker must be running on the RPMS server in order for
|
---|
20 | /// BMXNetBroker to connect.
|
---|
21 | /// </summary>
|
---|
22 |
|
---|
23 | [DnsPermission(SecurityAction.Assert, Unrestricted = true)]
|
---|
24 | internal class BMXNetSocketBroker : BMXNetBroker, BMXNetSessionConnectionSource
|
---|
25 | {
|
---|
26 | public BMXNetSocketBroker()
|
---|
27 | {
|
---|
28 | }
|
---|
29 |
|
---|
30 | private BMXRemoteSessionPool _sessionPool = null;
|
---|
31 |
|
---|
32 | internal BMXRemoteSessionPool SessionPool
|
---|
33 | {
|
---|
34 | get { return _sessionPool; }
|
---|
35 | set { _sessionPool = value; }
|
---|
36 | }
|
---|
37 |
|
---|
38 | public override RemoteSessionPool RemoteSessionPool
|
---|
39 | {
|
---|
40 | get { return this.SessionPool; }
|
---|
41 | }
|
---|
42 |
|
---|
43 | public override void Close()
|
---|
44 | {
|
---|
45 | if (this.SessionPool != null)
|
---|
46 | {
|
---|
47 | this.SessionPool.Close();
|
---|
48 | this.SessionPool = null;
|
---|
49 | }
|
---|
50 | }
|
---|
51 |
|
---|
52 | public User FriendUser
|
---|
53 | {
|
---|
54 | set
|
---|
55 | {
|
---|
56 | this.User = value;
|
---|
57 | }
|
---|
58 | }
|
---|
59 |
|
---|
60 | private bool _loggedInWithWindowsIdentity = false;
|
---|
61 |
|
---|
62 | public bool LoggedInWithWindowsIdentity
|
---|
63 | {
|
---|
64 | get { return _loggedInWithWindowsIdentity; }
|
---|
65 | set { _loggedInWithWindowsIdentity = value; }
|
---|
66 | }
|
---|
67 |
|
---|
68 | private BMXNetSocketConnectionSpec _connectionSpec = null;
|
---|
69 |
|
---|
70 | public BMXNetSocketConnectionSpec ConnectionSpec
|
---|
71 | {
|
---|
72 | get { return _connectionSpec; }
|
---|
73 | set { _connectionSpec = value; }
|
---|
74 | }
|
---|
75 |
|
---|
76 |
|
---|
77 | public override bool IsConnected
|
---|
78 | {
|
---|
79 | get
|
---|
80 | {
|
---|
81 | return this.PrimarySession != null && this.PrimarySession.SessionConnection.IsConnected;
|
---|
82 | }
|
---|
83 | }
|
---|
84 |
|
---|
85 |
|
---|
86 | public override RemoteSession PrimaryRemoteSession
|
---|
87 | {
|
---|
88 | get
|
---|
89 | {
|
---|
90 | return (RemoteSession)this.PrimarySession;
|
---|
91 | }
|
---|
92 | }
|
---|
93 |
|
---|
94 | private BMXNetRemoteSession _primarySession = null;
|
---|
95 |
|
---|
96 | internal BMXNetRemoteSession PrimarySession
|
---|
97 | {
|
---|
98 | get { return _primarySession; }
|
---|
99 | set { _primarySession = value; }
|
---|
100 | }
|
---|
101 |
|
---|
102 |
|
---|
103 | void BMXNetSessionConnectionSource.CloseConnection(BMXNetSessionConnection aConnection)
|
---|
104 | {
|
---|
105 | if (aConnection == null)
|
---|
106 | {
|
---|
107 | return;
|
---|
108 | }
|
---|
109 |
|
---|
110 | this.Log.Log("BMX NET", "Debug", "Closing Socket Session Connection");
|
---|
111 |
|
---|
112 | aConnection.Close();
|
---|
113 | }
|
---|
114 |
|
---|
115 |
|
---|
116 | BMXNetSessionConnection BMXNetSessionConnectionSource.OpenConnection()
|
---|
117 | {
|
---|
118 | this.Log.Log("BMX NET", "Debug", "Opening Socket Session Connection");
|
---|
119 | BMXNetSessionSocketConnection connection = new BMXNetSessionSocketConnection(this);
|
---|
120 |
|
---|
121 | connection.OpenConnection(this.ConnectionSpec);
|
---|
122 |
|
---|
123 | return connection.IsConnected ? connection : null;
|
---|
124 | }
|
---|
125 |
|
---|
126 |
|
---|
127 | public override bool Open(string aServer, int aPort, string aNameSpace, string anAccessCode, string aVerifyCode,int sendTimeout,int receiveTimeout)
|
---|
128 | {
|
---|
129 | BMXNetSocketConnectionSpec spec = new BMXNetSocketConnectionSpec();
|
---|
130 | spec.SendTimeout = sendTimeout;
|
---|
131 | spec.ReceiveTimeout = receiveTimeout;
|
---|
132 | spec.Server = aServer;
|
---|
133 | spec.Port = aPort;
|
---|
134 | spec.NameSpace = aNameSpace;
|
---|
135 | spec.EncryptedAccessVerifyCode = new BMXNetSessionSocketConnection(this).EncryptAccessVerifyCode(anAccessCode, aVerifyCode);
|
---|
136 |
|
---|
137 | this.ConnectionSpec = spec;
|
---|
138 |
|
---|
139 | return this.Open(spec);
|
---|
140 | }
|
---|
141 |
|
---|
142 |
|
---|
143 | public override bool Open(string aServer, int aPort, string aNameSpace, WindowsIdentity windowsIdentity, int sendTimeout, int receiveTimeout)
|
---|
144 | {
|
---|
145 | BMXNetSocketConnectionSpec spec = new BMXNetSocketConnectionSpec();
|
---|
146 | spec.SendTimeout = sendTimeout;
|
---|
147 | spec.ReceiveTimeout = receiveTimeout;
|
---|
148 | spec.Server = aServer;
|
---|
149 | spec.Port = aPort;
|
---|
150 | spec.NameSpace = aNameSpace;
|
---|
151 | spec.WindowsIdentity = windowsIdentity;
|
---|
152 |
|
---|
153 | this.ConnectionSpec = spec;
|
---|
154 |
|
---|
155 | return this.Open(spec);
|
---|
156 | }
|
---|
157 |
|
---|
158 |
|
---|
159 | private bool Open(BMXNetSocketConnectionSpec aSpec)
|
---|
160 | {
|
---|
161 | this.ConnectionSpec = aSpec;
|
---|
162 | this.SessionPool = new BMXRemoteSessionPool();
|
---|
163 | this.SessionPool.Log = this.Log;
|
---|
164 | this.SessionPool.Begin(this);
|
---|
165 | this.PrimarySession = (BMXNetRemoteSession)this.SessionPool.OpenSession();
|
---|
166 |
|
---|
167 | return this.PrimarySession != null;
|
---|
168 | }
|
---|
169 |
|
---|
170 | public override String RegisterWindowsIdentityForWindowsAuthenication(WindowsIdentity aWindowsIdentity)
|
---|
171 | {
|
---|
172 | if (this.PrimarySession.IsConnected)
|
---|
173 | {
|
---|
174 | if (aWindowsIdentity.IsAuthenticated)
|
---|
175 | {
|
---|
176 | return this.PrimarySession.TransmitRPC("BMXNetSetUser", aWindowsIdentity.Name);
|
---|
177 | }
|
---|
178 | else
|
---|
179 | {
|
---|
180 | throw new BMXNetException("Current Windows User is not authenticated");
|
---|
181 | }
|
---|
182 | }
|
---|
183 | else
|
---|
184 | {
|
---|
185 | throw new BMXNetException("Connection disconnected immediately after login.");
|
---|
186 | }
|
---|
187 | }
|
---|
188 |
|
---|
189 |
|
---|
190 | }
|
---|
191 |
|
---|
192 | /*
|
---|
193 | 1 ;;1;Signons not currently allowed on this processor.
|
---|
194 | 2 ;;1;Maximum number of users already signed on to this processor.
|
---|
195 | 3 ;;1;This device has not been defined to the system -- contact system manager.
|
---|
196 | 4 ;;0;Not a valid Windows Identity map value.
|
---|
197 | 5 ;;0;No Access Allowed for this User.
|
---|
198 | 6 ;;0;Invalid device password.
|
---|
199 | 7 ;;0;Device locked due to too many invalid sign-on attempts.
|
---|
200 | 8 ;;1;This device is out of service.
|
---|
201 | 9 ;;0;*** MULTIPLE SIGN-ONS NOT ALLOWED ***
|
---|
202 | 10 ;;1;You don't have access to this device!
|
---|
203 | 11 ;;0;Your access code has been terminated. Please see your site manager!
|
---|
204 | 12 ;;0;VERIFY CODE MUST be changed before continued use.
|
---|
205 | 13 ;;1;This device may only be used outside of this time frame |
|
---|
206 | 14 ;;0;'|' is not a valid UCI!
|
---|
207 | 15 ;;0;'|' is not a valid program name!
|
---|
208 | 16 ;;0;No PRIMARY MENU assigned to user or User is missing KEY to menu!
|
---|
209 | 17 ;;0;Your access to the system is prohibited from |.
|
---|
210 | 18 ;;0;Windows Integrated Security Not Allowed on this port.*/
|
---|
211 |
|
---|
212 |
|
---|
213 | }
|
---|