99 */
1010class sspmod_perun_AdapterRpc extends sspmod_perun_Adapter
1111{
12+ const DEFAULT_CONFIG_FILE_NAME = 'module_perun.php ' ;
13+ const RPC_URL = 'rpc.url ' ;
14+ const RPC_USER = 'rpc.username ' ;
15+ const RPC_PASSWORD = 'rpc.password ' ;
1216
17+ private $ rpcUrl ;
18+ private $ rpcUser ;
19+ private $ rpcPassword ;
1320
21+ protected $ connector ;
22+
23+ public function __construct ($ configFileName = null )
24+ {
25+ if (is_null ($ configFileName )) {
26+ $ configFileName = self ::DEFAULT_CONFIG_FILE_NAME ;
27+ }
28+
29+ $ conf = SimpleSAML_Configuration::getConfig ($ configFileName );
30+
31+ $ this ->rpcUrl = $ conf ->getString (self ::RPC_URL );
32+ $ this ->rpcUser = $ conf ->getString (self ::RPC_USER );
33+ $ this ->rpcPassword = $ conf ->getString (self ::RPC_PASSWORD );
34+
35+ $ this ->connector = new sspmod_perun_RpcConnector ($ this ->rpcUrl , $ this ->rpcUser , $ this ->rpcPassword );
36+ }
37+
1438 public function getPerunUser ($ idpEntityId , $ uids )
1539 {
1640 $ user = null ;
1741
1842 foreach ($ uids as $ uid ) {
1943 try {
20- $ user = sspmod_perun_RpcConnector:: get ('usersManager ' , 'getUserByExtSourceNameAndExtLogin ' , array (
44+ $ user = $ this -> connector -> get ('usersManager ' , 'getUserByExtSourceNameAndExtLogin ' , array (
2145 'extSourceName ' => $ idpEntityId ,
2246 'extLogin ' => $ uid ,
2347 ));
@@ -49,13 +73,13 @@ public function getPerunUser($idpEntityId, $uids)
4973 public function getMemberGroups ($ user , $ vo )
5074 {
5175 try {
52- $ member = sspmod_perun_RpcConnector:: get ('membersManager ' , 'getMemberByUser ' , array (
76+ $ member = $ this -> connector -> get ('membersManager ' , 'getMemberByUser ' , array (
5377 'vo ' => $ vo ->getId (),
5478 'user ' => $ user ->getId (),
5579 ));
5680
5781
58- $ memberGroups = sspmod_perun_RpcConnector:: get ('groupsManager ' , 'getAllMemberGroups ' , array (
82+ $ memberGroups = $ this -> connector -> get ('groupsManager ' , 'getAllMemberGroups ' , array (
5983 'member ' => $ member ['id ' ],
6084 ));
6185 } catch (sspmod_perun_Exception $ e ) {
@@ -73,15 +97,15 @@ public function getMemberGroups($user, $vo)
7397
7498 public function getSpGroups ($ spEntityId , $ vo )
7599 {
76- $ resources = sspmod_perun_RpcConnector:: get ('resourcesManager ' , 'getResources ' , array (
100+ $ resources = $ this -> connector -> get ('resourcesManager ' , 'getResources ' , array (
77101 'vo ' => $ vo ->getId (),
78102 ));
79103
80104 $ spFacilityIds = array ();
81105 $ spResources = array ();
82106 foreach ($ resources as $ resource ) {
83107 if (!array_key_exists ($ resource ['facilityId ' ], $ spFacilityIds )) {
84- $ attribute = sspmod_perun_RpcConnector:: get ('attributesManager ' , 'getAttribute ' , array (
108+ $ attribute = $ this -> connector -> get ('attributesManager ' , 'getAttribute ' , array (
85109 'facility ' => $ resource ['facilityId ' ],
86110 'attributeName ' => 'urn:perun:facility:attribute-def:def:entityID ' ,
87111 ));
@@ -98,7 +122,7 @@ public function getSpGroups($spEntityId, $vo)
98122
99123 $ spGroups = array ();
100124 foreach ($ spResources as $ spResource ) {
101- $ groups = sspmod_perun_RpcConnector:: get ('resourcesManager ' , 'getAssignedGroups ' , array (
125+ $ groups = $ this -> connector -> get ('resourcesManager ' , 'getAssignedGroups ' , array (
102126 'resource ' => $ spResource ['id ' ],
103127 ));
104128 $ convertedGroups = array ();
@@ -116,7 +140,7 @@ public function getSpGroups($spEntityId, $vo)
116140
117141 public function getGroupByName ($ vo , $ name )
118142 {
119- $ group = sspmod_perun_RpcConnector:: get ('groupsManager ' , 'getGroupByName ' , array (
143+ $ group = $ this -> connector -> get ('groupsManager ' , 'getGroupByName ' , array (
120144 'vo ' => $ vo ->getId (),
121145 'name ' => $ name ,
122146 ));
@@ -127,7 +151,7 @@ public function getGroupByName($vo, $name)
127151
128152 public function getVoByShortName ($ voShortName )
129153 {
130- $ vo = sspmod_perun_RpcConnector:: get ('vosManager ' , 'getVoByShortName ' , array (
154+ $ vo = $ this -> connector -> get ('vosManager ' , 'getVoByShortName ' , array (
131155 'shortName ' => $ voShortName ,
132156 ));
133157
@@ -137,7 +161,7 @@ public function getVoByShortName($voShortName)
137161
138162 public function getUserAttributes ($ user , $ attrNames )
139163 {
140- $ perunAttrs = sspmod_perun_RpcConnector:: get ('attributesManager ' , 'getAttributes ' , array (
164+ $ perunAttrs = $ this -> connector -> get ('attributesManager ' , 'getAttributes ' , array (
141165 'user ' => $ user ->getId (),
142166 'attrNames ' => $ attrNames ,
143167 ));
@@ -155,7 +179,7 @@ public function getUserAttributes($user, $attrNames)
155179
156180 public function getEntitylessAttribute ($ attrName )
157181 {
158- $ perunAttrs = sspmod_perun_RpcConnector:: get ('attributesManager ' , 'getEntitylessAttributes ' , array (
182+ $ perunAttrs = $ this -> connector -> get ('attributesManager ' , 'getEntitylessAttributes ' , array (
159183 'attrName ' => $ attrName ,
160184 ));
161185
@@ -170,7 +194,7 @@ public function getEntitylessAttribute($attrName)
170194
171195 public function getVoAttributes ($ vo , $ attrNames )
172196 {
173- $ perunAttrs = sspmod_perun_RpcConnector:: get ('attributesManager ' , 'getAttributes ' , array (
197+ $ perunAttrs = $ this -> connector -> get ('attributesManager ' , 'getAttributes ' , array (
174198 'vo ' => $ vo ->getId (),
175199 'attrNames ' => $ attrNames ,
176200 ));
@@ -188,7 +212,7 @@ public function getVoAttributes($vo, $attrNames)
188212
189213 public function getFacilityAttribute ($ facility , $ attrName )
190214 {
191- $ perunAttr = sspmod_perun_RpcConnector:: get ('attributesManager ' , 'getAttribute ' , array (
215+ $ perunAttr = $ this -> connector -> get ('attributesManager ' , 'getAttribute ' , array (
192216 'facility ' => $ facility ->getId (),
193217 'attributeName ' => $ attrName ,
194218 ));
@@ -197,22 +221,22 @@ public function getFacilityAttribute($facility, $attrName)
197221 }
198222
199223
200- public function getUsersGroupsOnFacility ($ spEntityId , $ userId )
224+ public function getUsersGroupsOnFacility ($ spEntityId , $ userId )
201225 {
202- $ facilities = sspmod_perun_RpcConnector:: get ('facilitiesManager ' , 'getFacilitiesByAttribute ' , array (
226+ $ facilities = $ this -> connector -> get ('facilitiesManager ' , 'getFacilitiesByAttribute ' , array (
203227 'attributeName ' => 'urn:perun:facility:attribute-def:def:entityID ' ,
204228 'attributeValue ' => $ spEntityId ,
205229 ));
206230
207231 $ allowedResources = array ();
208232 foreach ($ facilities as $ facility ) {
209- $ resources = sspmod_perun_RpcConnector:: get ('facilitiesManager ' , 'getAssignedResources ' , array (
233+ $ resources = $ this -> connector -> get ('facilitiesManager ' , 'getAssignedResources ' , array (
210234 'facility ' => $ facility ['id ' ],
211235 ));
212236 $ allowedResources = array_merge ($ allowedResources , $ resources );
213237 }
214238
215- $ members = sspmod_perun_RpcConnector:: get ('membersManager ' , 'getMembersByUser ' , array (
239+ $ members = $ this -> connector -> get ('membersManager ' , 'getMembersByUser ' , array (
216240 'user ' => $ userId ,
217241 ));
218242
@@ -226,7 +250,7 @@ public function getUsersGroupsOnFacility($spEntityId, $userId)
226250 $ allGroups = array ();
227251 foreach ($ allowedResources as $ resource ) {
228252 foreach ($ validMembers as $ member ) {
229- $ groups = sspmod_perun_RpcConnector:: get ('resourcesManager ' , 'getAssignedGroups ' , array (
253+ $ groups = $ this -> connector -> get ('resourcesManager ' , 'getAssignedGroups ' , array (
230254 'resource ' => $ resource ['id ' ],
231255 'member ' => $ member ['id ' ],
232256 ));
@@ -242,7 +266,7 @@ public function getUsersGroupsOnFacility($spEntityId, $userId)
242266
243267 public function getFacilitiesByEntityId ($ spEntityId )
244268 {
245- $ perunAttrs = sspmod_perun_RpcConnector:: get ('facilitiesManager ' , 'getFacilitiesByAttribute ' , array (
269+ $ perunAttrs = $ this -> connector -> get ('facilitiesManager ' , 'getFacilitiesByAttribute ' , array (
246270 'attributeName ' => 'urn:perun:facility:attribute-def:def:entityID ' ,
247271 'attributeValue ' => $ spEntityId ,
248272 ));
@@ -252,5 +276,4 @@ public function getFacilitiesByEntityId($spEntityId)
252276 }
253277 return $ facilities ;
254278 }
255-
256279}
0 commit comments