-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAuthorization.cs
More file actions
184 lines (163 loc) · 4.14 KB
/
Copy pathAuthorization.cs
File metadata and controls
184 lines (163 loc) · 4.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.IO;
using System.Net;
using System.Xml;
namespace IconCMO
{
public class IconAuth
{
private string phone;
private string userName;
private string password;
private string session;
public IconAuth(string _phone, string _userName, string _password)
{
phone = _phone;
userName = _userName;
password = _password;
session = string.Empty;
}
public string Phone
{
get { return phone; }
set {
phone = value;
session = string.Empty;
}
}
public string UserName
{
get { return userName; }
set {
userName = value;
session = string.Empty;
}
}
public string Password
{
get { return password; }
set {
password = value;
session = string.Empty;
}
}
public string Session
{
get { return session; }
set {
session = value;
}
}
public string GetAuthXML()
{
string auth = string.Empty;
auth = "<Auth>";
if (session != string.Empty)
auth += "<Session>" + session + "</Session>";
else
{
auth += "<Phone>" + phone + "</Phone>" +
"<Username>" + userName + "</Username>" +
"<Password>" + password + "</Password>";
}
auth += "</Auth>";
return auth;
}
}
public class Permissions
{
private Collection<Permission> permissions;
private string role;
private XmlDocument xmlDoc;
private string httpRequest;
private IconAuth auth;
public Permissions(IconAuth _auth)
{
auth = _auth;
xmlDoc = new XmlDocument();
permissions = new Collection<Permission>();
// Form the http request
httpRequest = HttpRequestHandler.BuildRequest("<Module>user</Module>" +
"<Section>permissions</Section>",
null,
auth,
null);
// Send the request
HttpWebResponse response = HttpRequestHandler.SendRequest(httpRequest);
// Load the response into an XML document
xmlDoc.Load(new StreamReader(response.GetResponseStream()));
// Extract the security token from the response
HttpRequestHandler.GetSession(xmlDoc, ref auth);
// Load the permissions
LoadPermissions();
// Get the role
XmlNode wrkNode = xmlDoc.SelectSingleNode("/iconresponse/role");
role = wrkNode.InnerText;
}
public Collection<Permission> Entries
{
get { return permissions; }
}
public string Role
{
get { return role; }
}
public IconAuth Auth
{
get { return auth; }
set { auth = value; }
}
private void LoadPermissions()
{
// Get the permission nodes
XmlNodeList nodes = xmlDoc.SelectNodes("/iconresponse/Permissions/*");
foreach (XmlNode node in nodes)
{
// Create a permission entry and add to the collection
Permission entry = new Permission();
// This should be the Module node
entry.Module = node.Name;
// Get the group nodes
XmlNodeList sectionNodes = node.ChildNodes;
foreach (XmlNode sectionNode in sectionNodes)
{
entry.Section = sectionNode.Name;
XmlNode wrkNode = sectionNode.SelectSingleNode("create");
bool wrkBool = false;
bool.TryParse(wrkNode.InnerText, out wrkBool);
entry.Create = wrkBool;
wrkNode = sectionNode.SelectSingleNode("read");
bool.TryParse(wrkNode.InnerText, out wrkBool);
entry.Read = wrkBool;
wrkNode = sectionNode.SelectSingleNode("update");
bool.TryParse(wrkNode.InnerText, out wrkBool);
entry.Update = wrkBool;
wrkNode = sectionNode.SelectSingleNode("delete");
bool.TryParse(wrkNode.InnerText, out wrkBool);
entry.Delete = wrkBool;
}
}
}
}
public class Permission
{
public string Module { get; set; }
public string Section { get; set; }
public bool Create { get; set; }
public bool Read { get; set; }
public bool Update { get; set; }
public bool Delete { get; set; }
public Permission(string _module = "", string _section = "", bool _create = false,
bool _read = false, bool _update = false, bool _delete = false)
{
Module = _module;
Section = _section;
Create = _create;
Read = _read;
Update = _update;
Delete = _delete;
}
}
}