1
1
<?php
2
+
2
3
/*______________________________________________________
3
4
*======================================================
4
5
* File: edit_api_auth.php
5
6
* Author: George Ryall
6
- * Description: Processes a edit API Authentication entity request. If the user
7
- * hasn't POSTed any data we draw the new site
7
+ * Description: Processes a edit API Authentication entity request.
8
+ * If the user hasn't POSTed any data we draw the new site
8
9
* form. If they post data we assume they've posted it from
9
10
* the form and validate then insert it into the DB.
10
11
*
21
22
* See the License for the specific language governing permissions and
22
23
* limitations under the License.
23
24
/*======================================================*/
24
- require_once __DIR__ .'/../../../web_portal/components/Get_User_Principle.php ' ;
25
- require_once __DIR__ .'/../utils.php ' ;
26
- require_once __DIR__ .'/../../../../lib/Gocdb_Services/Factory.php ' ;
25
+ require_once __DIR__
26
+ . '/../../../web_portal/components/Get_User_Principle.php ' ;
27
+ require_once __DIR__ . '/../utils.php ' ;
28
+ require_once __DIR__ . '/../../../../lib/Gocdb_Services/Factory.php ' ;
29
+
30
+ use Exception ;
27
31
28
32
/**
29
33
* Controller to edit authentication entity request
30
- * @global array $_POST only set if the browser has POSTed data
34
+ *
35
+ * @global array $_POST only set if the browser has posted data
36
+ *
31
37
* @return null
32
38
*/
33
- function edit_entity () {
39
+ function edit_entity ()
40
+ {
34
41
$ dn = Get_User_Principle ();
35
42
$ user = \Factory::getUserService ()->getUserByPrinciple ($ dn );
36
43
37
- //Check the portal is not in read only mode, returns exception if it is and user is not an admin
44
+ /**
45
+ * Check the portal is not in read only mode,
46
+ * returns exception if it is and user is not an admin
47
+ */
38
48
checkPortalIsNotReadOnlyOrUserIsAdmin ($ user );
39
49
40
- if (!isset ($ _REQUEST ['authentityid ' ]) || !is_numeric ($ _REQUEST ['authentityid ' ]) ){
41
- throw new Exception ("A authentication entity id must be specified in the url " );
50
+ if (
51
+ !isset ($ _REQUEST ['authentityid ' ])
52
+ || !is_numeric ($ _REQUEST ['authentityid ' ])
53
+ ) {
54
+ throw new Exception (
55
+ "A authentication entity id must be specified in the url "
56
+ );
42
57
}
43
58
44
59
$ serv = \Factory::getSiteService ();
@@ -47,48 +62,67 @@ function edit_entity() {
47
62
48
63
// Validate the user has permission to edit properties
49
64
if (!$ serv ->userCanEditSite ($ user , $ site )) {
50
- throw new \Exception ("Permission denied: a site role is required to edit authentication entities at " . $ site ->getShortName ());
65
+ throw new Exception (
66
+ "Permission denied: a site role is required to edit "
67
+ . "authentication entities at "
68
+ . $ site ->getShortName ()
69
+ );
51
70
}
52
71
53
- if ($ _POST ) { // If we receive a POST request it's to edit an authentication entity
72
+ // If we receive a POST request it's to edit an authentication entity
73
+ if ($ _POST ) {
54
74
submit ($ user , $ authEnt , $ site , $ serv );
55
- } else { // If there is no post data, draw the edit authentication entity form
75
+ } else {
76
+ // If there is no post data, draw the edit authentication entity form
56
77
draw ($ user , $ authEnt , $ site );
57
78
}
58
79
}
59
80
60
- function draw (\User $ user = null , \APIAuthentication $ authEnt = null , \Site $ site = null ) {
61
- if (is_null ($ user )){
62
- throw new Exception ("Unregistered users can't edit authentication credentials " );
81
+ function draw (
82
+ \User $ user = null ,
83
+ \APIAuthentication $ authEnt = null ,
84
+ \Site $ site = null
85
+ ) {
86
+ if (is_null ($ user )) {
87
+ throw new Exception (
88
+ "Unregistered users can't edit authentication credentials "
89
+ );
63
90
}
64
91
65
92
$ params = array ();
66
93
$ params ['site ' ] = $ site ;
67
94
$ params ['authEnt ' ] = $ authEnt ;
68
95
$ params ['authTypes ' ] = array ();
69
- $ params ['authTypes ' ][]= 'X.509 ' ;
70
- $ params ['authTypes ' ][]= 'OIDC Subject ' ;
96
+ $ params ['authTypes ' ][] = 'X.509 ' ;
97
+ $ params ['authTypes ' ][] = 'OIDC Subject ' ;
71
98
$ params ['user ' ] = $ user ;
72
99
73
100
show_view ("site/edit_api_auth.php " , $ params );
101
+
74
102
die ();
75
103
}
76
104
77
- function submit (\User $ user , \APIAuthentication $ authEnt , \Site $ site , org \gocdb \services \Site $ serv ) {
105
+ function submit (
106
+ \User $ user ,
107
+ \APIAuthentication $ authEnt ,
108
+ \Site $ site ,
109
+ org \gocdb \services \Site $ serv
110
+ ) {
78
111
$ newValues = getAPIAuthenticationFromWeb ();
79
112
80
113
try {
81
114
$ authEnt = $ serv ->editAPIAuthEntity ($ authEnt , $ user , $ newValues );
82
- } catch (Exception $ e ) {
115
+ } catch (Exception $ e ) {
83
116
show_view ('error.php ' , $ e ->getMessage ());
117
+
84
118
die ();
85
119
}
86
120
87
121
$ params = array ();
88
122
$ params ['apiAuthenticationEntity ' ] = $ authEnt ;
89
123
$ params ['site ' ] = $ site ;
90
- show_view ("site/edited_api_auth.php " , $ params );
91
- die ();
92
124
125
+ show_view ("site/edited_api_auth.php " , $ params );
93
126
127
+ die ();
94
128
}
0 commit comments