forked from SciGaP/PHP-Reference-Gateway
-
Notifications
You must be signed in to change notification settings - Fork 0
/
wsis_utilities.php
243 lines (216 loc) · 6.29 KB
/
wsis_utilities.php
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
<?php
require_once 'id_utilities.php';
$GLOBALS['WSIS_ROOT'] = './lib/WSIS/';
require_once $GLOBALS['WSIS_ROOT'] . 'WSISClient.php';
/**
* Utilities for ID management with a WSO2 IS 4.6.0
*/
class WSISUtilities implements IdUtilities{
const WSIS_CONFIG_PATH = 'wsis_config.ini';
/**
* wso2 IS client
*
* @var WSISClient
* @access private
*/
private $wsis_client;
/**
* Connect to the identity store.
* @return mixed|void
*/
public function connect() {
$wsis_config = null;
try {
if (file_exists(self::WSIS_CONFIG_PATH)) {
$wsis_config = parse_ini_file(self::WSIS_CONFIG_PATH);
} else {
throw new Exception("Error: Cannot open wsis_config.xml file!");
}
if (!$wsis_config) {
throw new Exception('Error: Unable to read wsis_config.xml!');
}
if(substr($wsis_config['service-url'], -1) !== "/"){
$wsis_config['service-url'] = $wsis_config['service-url'] . "/";
}
if(!substr($wsis_config['cafile-path'], 0) !== "/"){
$wsis_config['cafile-path'] = "/" . $wsis_config['cafile-path'];
}
$wsis_config['cafile-path'] = ROOT_DIR . $wsis_config['cafile-path'];
$this->wsis_client = new WSISClient(
$wsis_config['admin-username'],
$wsis_config['admin-password'],
$wsis_config['server'],
$wsis_config['service-url'],
$wsis_config['cafile-path'],
$wsis_config['verify-peer'],
$wsis_config['allow-self-signed']
);
} catch (Exception $e) {
throw new Exception('Unable to instantiate Identity Server client. Try editing the cafile-path within wsis_config.ini.', 0, NULL);
}
}
/**
* Return true if the given username exists in the identity server.
* @param $username
* @return bool
*/
public function username_exists($username) {
try{
return $this->wsis_client->username_exists($username);
} catch (Exception $ex) {
throw new Exception("Unable to check whether username exists", 0, NULL);
}
}
/**
* authenticate a given user
* @param $username
* @param $password
* @return boolean
*/
public function authenticate($username, $password) {
try{
return $this->wsis_client->authenticate($username, $password);
} catch (Exception $ex) {
throw new Exception("Unable to authenticate user", 0, NULL);
}
}
/**
* Add a new user to the identity server.
* @param $username
* @param $password
* @return void
*/
public function add_user($username, $password, $first_name, $last_name, $email, $organization,
$address, $country,$telephone, $mobile, $im, $url) {
try{
$this->wsis_client->addUser($username, $password);
} catch (Exception $ex) {
var_dump($ex);
throw new Exception("Unable to add new user", 0, NULL);
}
}
/**
* Get the user profile
* @param $username
* @return mixed|void
*/
public function get_user_profile($username)
{
// TODO: Implement get_user_profile() method.
}
/**
* Update the user profile
*
* @param $username
* @param $first_name
* @param $last_name
* @param $email
* @param $organization
* @param $address
* @param $country
* @param $telephone
* @param $mobile
* @param $im
* @param $url
* @return mixed
*/
public function update_user_profile($username, $first_name, $last_name, $email, $organization, $address,
$country, $telephone, $mobile, $im, $url)
{
// TODO: Implement update_user_profile() method.
}
/**
* Function to update user password
*
* @param $username
* @param $current_password
* @param $new_password
* @return mixed
*/
public function change_password($username, $current_password, $new_password)
{
// TODO: Implement change_password() method.
}
/**
* Function to remove an existing user
*
* @param $username
* @return void
*/
public function remove_user($username)
{
// TODO: Implement remove_user() method.
}
/**
* Function to check whether a user has permission for a particular permission string(api method).
*
* @param $username
* @param $permission_string
* @return bool
*/
public function checkPermissionForUser($username, $permission_string)
{
// TODO: Implement checkPermissionForUser() method.
}
/**
* Function to get all the permissions that a particular user has.
*
* @param $username
* @return mixed
*/
public function getUserPermissions($username)
{
// TODO: Implement getUserPermissions() method.
}
/**
* Function to get the entire list of roles in the application
*
* @return mixed
*/
public function getRoleList()
{
// TODO: Implement getRoleList() method.
}
/**
* Function to get the role list of a user
*
* @param $username
* @return mixed
*/
public function getRoleListOfUser($username)
{
// TODO: Implement getRoleListOfUser() method.
}
/**
* Function to get the user list of a particular role
*
* @param $role
* @return mixed
*/
public function getUserListOfRole($role)
{
// TODO: Implement getUserListOfRole() method.
}
/**
* Function to add a role to a user
*
* @param $username
* @param $role
* @return void
*/
public function addUserToRole($username, $role)
{
// TODO: Implement addUserToRole() method.
}
/**
* Function to role from user
*
* @param $username
* @param $role
* @return void
*/
public function removeUserFromRole($username, $role)
{
// TODO: Implement removeUserFromRole() method.
}
}