-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathrolemanager.html
383 lines (304 loc) · 16.6 KB
/
rolemanager.html
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
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Ness PHP Framework | Docs</title>
<link rel="stylesheet" type="text/css" href="assets/css/bootstrap.min.css">
<link rel="stylesheet" type="text/css" href="assets/fnt-aw/css/font-awesome.min.css">
<link rel="stylesheet" type="text/css" href="assets/css/style.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<!--Load highlightjs package -->
<link rel="stylesheet" href="assets/js/highlightjs/styles/vs2015.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
</head>
<body>
<div class="wrapper">
<!-- Sidebar -->
<nav id="sidebar">
<div id="sidebar-header" class="text-center">
<br>
<a href="index.html" id="logo-area-link">
<img src="assets/img/nessphp_bordered.png" alt="Ness PHP Documentation" width="70%"/>
<h3>Ness PHP</h3>
<h4>Documentation</h4>
</a>
<a href="index.html" class="btn btn-light btn-sm" style="width: 100%;">
<i class="fa fa-angle-left" aria-hidden="true"></i> Back
</a>
</div>
<br>
<!--Load LATER-->
<div id="sidebar-loader" class="sidebar-contents">
</div>
</nav>
<div id="content">
<!--Nabvar:start-->
<nav class="navbar navbar-expand-lg">
<div class="container-fluid">
<button id="sidebarCollapse" class="btn-circle">
<i class="fa fa-bars" aria-hidden="true"></i>
</button>
<ul class="nav navbar-nav">
<li class="nav-item">
<a href="index.html" class="navbar-text-header">
Ness PHP Framework
</a>
</li>
</ul>
<button class="btn-circle d-inline-block d-lg-none ml-auto" type="button" data-toggle="collapse" data-target="#headernav-links" aria-controls="headernav-links" aria-expanded="false" aria-label="Toggle Menu">
<i class="fa fa-ellipsis-v" aria-hidden="true"></i>
</button>
<div class="collapse navbar-collapse" id="headernav-links">
<ul class="nav navbar-nav ml-auto">
<li class="nav-item">
<a class="nav-link " href="https://nessphp.github.io/">
<i class="fa fa-terminal" aria-hidden="true"></i>
Ness PHP
</a>
</li>
<li class="nav-item">
<a class="nav-link " href="https://github.com/nessphp/application">
<i class="fa fa-github" aria-hidden="true"></i>
GitHub
</a>
</li>
<li class="nav-item">
<a class="nav-link" href="support.html">
<i class="fa fa-heart" aria-hidden="true"></i>
Support
</a>
</li>
</ul>
</div>
</div>
</nav>
<!--Nabvar:end-->
<!-- ========================content:start======================== -->
<div id="holder">
<span class="pageheader">Role Manager & Role Provider</span>
<br>
<div class="row">
<div class="col-lg-8">
<ul class="hash-toc">
<li>Contents
<ul>
<li><a href="#about">About Role Manager</a></li>
<li><a href="#methods">Methods</a></li>
<li><a href="#example">Example</a></li>
</ul>
</li>
</ul>
</div>
<!--Required Namespace -->
<div class="col-lg-4">
<div class="card bg-dark text-white">
<div class="card-header">Required Namespace</div>
<div class="card-body" >
<ul class="tree">
<li style="color:#28A745;">Ness
<ul>
<li style="color:#fff;">Security
<ul><li>RoleManager</li></ul>
</li>
</ul>
</li>
</ul>
<br>
<ul class="tree">
<li style="color:#28A745;">Ness
<ul>
<li style="color:#fff;">Security
<ul><li>RoleProvider</li></ul>
</li>
</ul>
</li>
</ul>
<hr>
<span><small>You can include this library to your code file by typing the below code;</small></span>
<br><br>
<span style="color:#3490CF;">use</span>
<span style="color:#28A745;">Ness\Security</span>\RoleManager
<br><br>
<span style="color:#3490CF;">use</span>
<span style="color:#28A745;">Ness\Security</span>\RoleProvider
</div>
</div>
</div>
<!--end: Required Namespace -->
</div>
<br><br>
<!--start: topic-->
<h4 id="about">About Role Manager & Role Provider <small><a href="#content">#top</a></small></h4>
<p>
<h5>Role Provider</h5>
This class is used to provide roles from database and set them in application register function. Role Manager class will access available roles and manage controller or Action permissions.
<h5>Role Manager</h5>
A basic role mananer class for Ness Framework. You can get available roles from database and set them in application register function, to manage user accesses to specific controllers.
</p>
<br>
<!--end: topic-->
<!--start: topic-->
<h4 id="methods">Methods <small><a href="#content">#top</a></small></h4>
<p>
<!---->
<h5>FillRoles</h5>
<pre><code class="php">RoleProvider::FillRoles(Array $roles);</code></pre>
<table class="code-desc">
<tr>
<td colspan="3">This function is used to fill roles with id and value from database. This is necessary for using role manager class.</td>
</tr>
<tr>
<td>Return</td>
<td colspan="2">void</td>
</tr>
<tr>
<td>Parameters</td>
<td colspan="2">$roles Array; Set all roles to role provider class. Array key is id in database and value is a named provision of role
You need to fill all roles in Application / Register()</td>
</tr>
</table><br><br><br>
<!---->
<h5>RequiredRoles</h5>
<pre><code class="php">RoleProvider::RequiredRoles(Array $roles);</code></pre>
<table class="code-desc">
<tr>
<td colspan="3">This function is used to set required roles for controller or controller action. If you want to affect a whole controller with set role you must setup role manager in construct method.</td>
</tr>
<tr>
<td>Return</td>
<td colspan="2">void</td>
</tr>
<tr>
<td>Parameters</td>
<td colspan="2">$roles Array; Required roles for a action in a controller or in whole controller.</td>
</tr>
</table><br><br><br>
<!---->
<h5>ProvidedRoles</h5>
<pre><code class="php">RoleProvider::ProvidedRoles(Array $roles);</code></pre>
<table class="code-desc">
<tr>
<td colspan="3">This function is User's provided roles. Can be filled from database. Later you will have the opportunity to check it with isAuthorized method.</td>
</tr>
<tr>
<td>Return</td>
<td colspan="2">void</td>
</tr>
<tr>
<td>Parameters</td>
<td colspan="2">$roles Array; provided roles for user.</td>
</tr>
</table><br><br><br>
<hr>
<!---->
<h5>isAuthorized</h5>
<pre><code class="php">RoleManager::isAuthorized();</code></pre>
<table class="code-desc">
<tr>
<td colspan="3">Checks if user is authorized.</td>
</tr>
<tr>
<td>Return</td>
<td colspan="2">Boolean</td>
</tr>
<tr>
<td>Parameters</td>
<td colspan="2">None</td>
</tr>
</table><br><br><br>
<!---->
<h5>ClearRequired</h5>
<pre><code class="php">RoleManager::ClearRequired();</code></pre>
<table class="code-desc">
<tr>
<td colspan="3">Clear All required roles.</td>
</tr>
<tr>
<td>Return</td>
<td colspan="2">None</td>
</tr>
<tr>
<td>Parameters</td>
<td colspan="2">None</td>
</tr>
</table><br><br>
</p>
<br>
<!--end: topic-->
<!--start: topic-->
<h4 id="example">Example <small><a href="#content">#top</a></small></h4>
<p>
Let's say you have a Index controller and IndexAction, and 3 roles(User, Administrator, Guest) available totally. You have a 'x' user which has roles, (Guest, User) and wants to access IndexAction which requires role 'Administrator'. For checking if your user 'x' can access to IndexAction you need to do followings;
<ol>
<li>Setup All Roles in Application Register</li>
<li>Do a control in Index controller and IndexAction</li>
<li>If Not Authorized show message or redirect.</li>
</ol>
<br><br>
<b>Application Confiuration; app_config.php</b>
<pre>
<code class="php">
/***********************************************
* Application Class
*/
class Application
{
/**
* This function is called automatically by framework on entry...
* You can do all your global object definitions or user-based settings...
*/
public function Register()
{
//Fill Roles
//We are filling manually, but you can get all roles from your database.
$data_set = array("1"=>"User", "2"=>"Administrator", "3"=>"Guest");
RoleProvider::FillRoles($data_set);
}
}
</code>
</pre>
<br><br>
<b>Controller Configuration; Controller/indexController.php</b>
<pre>
<code class="php">
class indexController extends Ness/Controller{
public function __construct() {
parent::__construct();
//You can get required roles from database we will give manually in this example.
RoleProvider::RequiredRoles(array("2"=>"Administrator"));
//User's roles: you can get them from your database we will fill manually...
RoleProvider::ProvidedRoles(array("1"=>"User"));
//now make the controls. You can block all contents of a controller or you can
//allow your user some Actions. We will block our user to access index page.
}
public function IndexAction($param=0){
if(RoleManager::isAuthorized())
{
$this->View->Render("index.php");
}else{
echo "You are not allowed";
exit();
//Do redirections or anything else;
}
}
}
</code>
</pre>
<br><br>
<div class="alert alert-info">
<strong>Reminder: </strong>In indexController.php controller RoleManager checks authorization for IndexAction, but you can control it in __construct and block all Controller actions.
</div>
</p>
<br>
<!--end: topic-->
</div>
<!-- ========================content:end======================== -->
</div>
</div>
<script src="assets/js/bootstrap.min.js"></script>
<script src="assets/js/nessphp.js"></script>
<script src="assets/js/highlightjs/highlight.pack.js"></script>
<script>hljs.initHighlightingOnLoad();</script>
</body>
</html>