From 3b7b1962b88e25b868085995a3b510f9dc6f4ed0 Mon Sep 17 00:00:00 2001 From: Martin Haase <martin.haase@daasi.de> Date: Wed, 17 Feb 2010 13:51:56 +0000 Subject: [PATCH] new Function getUserRole(), for speeding up UserManagement from O(N) to O(1). git-svn-id: https://textgridlab.org/svn/textgrid/trunk/middleware/tgauth@5486 7c539038-3410-0410-b1ec-0f2a7bf1c452 --- .../rbacSoap/TgExtra.class.php | 60 +++++++++++++ .../rbacSoap/examples/getUserRole.php | 82 ++++++++++++++++++ .../rbacSoap/soapTypes.inc.php | 23 +++++ .../rbacSoap/wsdl-8081/tgextra.wsdl | 84 +++++++++++++++++++ 4 files changed, 249 insertions(+) create mode 100755 info.textgrid.middleware.tgauth.rbac/rbacSoap/examples/getUserRole.php diff --git a/info.textgrid.middleware.tgauth.rbac/rbacSoap/TgExtra.class.php b/info.textgrid.middleware.tgauth.rbac/rbacSoap/TgExtra.class.php index 5de29c9..ec96180 100755 --- a/info.textgrid.middleware.tgauth.rbac/rbacSoap/TgExtra.class.php +++ b/info.textgrid.middleware.tgauth.rbac/rbacSoap/TgExtra.class.php @@ -730,6 +730,66 @@ class TgExtra { } + // ----------------------------------------------------- + // Function: getUserRole + // Input: auth / xsd:string + // log / xsd:string + // project / xsd:string + // Output: UserRole[]: tns:UserRole + // Description + // Returns members in a project with their roles. + // ----------------------------------------------------- + public function getUserRole ( $inRequest ) { + + $result = new getUserRoleResponse(); // The return-result + $arrMember = Array(); // Result of the RBAC-search + + + $arrMember = $this->rbac->authorizedUsers( $this->rbac->getConfiguration()->getValue( "role", "namingattribute" ) . "=" . $inRequest->project . "," + . $this->rbac->getConfiguration()->getValue( "role", "namingattribute" ) . "=" + . $this->config->getValue( "project", "base" ) + . "," . $this->rbac->getConfiguration()->getValue( "role", "base" ) ); + + $strFilter .= "(objectClass=rbacRole)"; + + $arrRole = $this->rbac->getConnection( "role" )->search( + "rbacname=" . $inRequest->project . + ",rbacname=Projekt-Teilnehmer," . + $this->rbac->getConfiguration()->getValue( "role", "base" ), + $strFilter, "one" ); + +// $file = fopen ("/tmp/xxx.log", "w+"); + + // want to be case-independent + $arrMember = array_map ( "strtolower", $arrMember); + $arrMember = $this->rbac->removeDuplicates($arrMember); + + + // The user has to be in the project to be + // allowed to see other's roles + if( in_array( strtolower( $this->rbac->sessionUser( $inRequest->auth ) ), $arrMember ) ) { + $res = array(); + + for( $i = 0; $i < sizeof ( $arrMember ) ; $i++ ) { + $roles = array(); + for( $j = 0; $j < sizeof ( $arrRole ); $j++) { + if (in_array($arrMember[$i], $arrRole[$j]["rbacperformer"])) { + array_push($roles, $arrRole[$j]["rbacname"][0]); + } + } + $res[$i] = new userRole ( $arrMember[$i], $roles ); + } + + $result->userRole = $res; + + } + +// fwrite ($file, serialize ($result) ."\n"); +// fclose ($file); + return $result; + + } + // ----------------------------------------------------- diff --git a/info.textgrid.middleware.tgauth.rbac/rbacSoap/examples/getUserRole.php b/info.textgrid.middleware.tgauth.rbac/rbacSoap/examples/getUserRole.php new file mode 100755 index 0000000..43071e5 --- /dev/null +++ b/info.textgrid.middleware.tgauth.rbac/rbacSoap/examples/getUserRole.php @@ -0,0 +1,82 @@ +<?php +// ####################################################### +// Author: Markus Widmer +// Creation date: 07.04.2008 +// Modification date: 07.04.2008 +// Version: 0.1.0 +// ####################################################### + + +require_once( "../soapTypes.inc.php" ); + + + +// ----------------------------------------------------- +// You'll need these services +// ----------------------------------------------------- +$soapSystem = new SoapClient( "../wsdl/tgextra.wsdl" ); + + +echo "<BODY><HTML>"; + + + + +if( isset( $_POST['project'] ) ) { + + // ----------------------------------------------------- + // If this was successfull you can add a the user you + // wish to create + // ----------------------------------------------------- + $memReq = new getMembersRequest(); + $memReq->auth = $_POST['auth']; + $memReq->log = ""; + $memReq->project = $_POST['project']; + + + echo "<HR/>"; + echo "Searching UserRoles for project...<BR/>"; + + try { + + $memResponse = $soapSystem->getUserRole( $memReq ); + + if( is_array( $memResponse->userRole ) ) { + + for( $i = 0; $i < sizeof( $memResponse->userRole ); $i++ ) { + + echo serialize( $memResponse->userRole[$i]) . "<BR>"; + + } + + } + elseif( preg_match( "/.+/", $memResponse->userRole ) ) { + + echo serialize ($memResponse->userRole); + + } + else { + + echo "No UserRoles found!<BR>"; + + } + + } + catch( SoapFault $f ) { + + echo "SOAP FAULT!: " . $f->faultcode . " / " . $f->faultstring . " / " . $f->detail; + + } + +} + + +echo "<FORM action=\"getUserRole.php\" method=\"post\" enctype=\"multipart/form-data\">\n"; +echo "Auth: <INPUT type=\"text\" name=\"auth\" value=\"\"><BR>\n"; +echo "project: <INPUT type=\"text\" name=\"project\" value=\"\"><BR>\n"; +echo "<INPUT type=\"submit\" value=\"Commit...\">\n"; +echo "</FORM>\n"; + +echo "</BODY></HTML>"; + +?> diff --git a/info.textgrid.middleware.tgauth.rbac/rbacSoap/soapTypes.inc.php b/info.textgrid.middleware.tgauth.rbac/rbacSoap/soapTypes.inc.php index 50a7500..d1475bd 100755 --- a/info.textgrid.middleware.tgauth.rbac/rbacSoap/soapTypes.inc.php +++ b/info.textgrid.middleware.tgauth.rbac/rbacSoap/soapTypes.inc.php @@ -491,6 +491,12 @@ class getAllProjectsResponse { } +class getUserRoleResponse { + + public $userrole; + +} + class getAllProjectsRequest { public $log; @@ -564,6 +570,23 @@ class projectInfo { } +class userRole { + + public $username; + public $roles; + + public function __construct( $inUsername, $inRoles ) { + + $this->username = $inUsername; + $this->roles = $inRoles; + + } + +} + + + + class checkXACMLaccessRequest { public $request; diff --git a/info.textgrid.middleware.tgauth.rbac/rbacSoap/wsdl-8081/tgextra.wsdl b/info.textgrid.middleware.tgauth.rbac/rbacSoap/wsdl-8081/tgextra.wsdl index c1566f1..71764c3 100644 --- a/info.textgrid.middleware.tgauth.rbac/rbacSoap/wsdl-8081/tgextra.wsdl +++ b/info.textgrid.middleware.tgauth.rbac/rbacSoap/wsdl-8081/tgextra.wsdl @@ -321,6 +321,17 @@ </xsd:complexType> </xsd:element> + <!-- #### getUserRole #### //--> + <xsd:element name="getUserRoleRequest"> + <xsd:complexType> + <xsd:sequence> + <xsd:element name="auth" type="xsd:string" minOccurs="1" maxOccurs="1" /> + <xsd:element name="log" type="xsd:string" minOccurs="0" maxOccurs="1" /> + <xsd:element name="project" type="xsd:string" minOccurs="1" maxOccurs="1" /> + </xsd:sequence> + </xsd:complexType> + </xsd:element> + <!-- #### getRights #### //--> <xsd:element name="getRightsRequest"> @@ -495,6 +506,23 @@ </xsd:element> + <xsd:element name="getUserRoleResponse"> + <xsd:complexType> + <xsd:sequence> + <xsd:element name="userRole" type="tns:userRole" minOccurs="0" maxOccurs="unbounded" /> + </xsd:sequence> + </xsd:complexType> + </xsd:element> + + + <xsd:complexType name="userRole"> + <xsd:sequence> + <xsd:element name="username" type="xsd:string" minOccurs="1" maxOccurs="1" /> + <xsd:element name="roles" type="xsd:string" minOccurs="1" maxOccurs="unbounded" /> + </xsd:sequence> + </xsd:complexType> + + <xsd:complexType name="projectInfo"> <xsd:sequence> <xsd:element name="id" type="xsd:string" minOccurs="1" maxOccurs="1" /> @@ -728,6 +756,15 @@ <wsdl:part element="tns:usersetResponse" name="getMembersOutput" /> </wsdl:message> + <!-- #### getUserRole #### //--> + <wsdl:message name="getUserRoleRequest"> + <wsdl:part element="tns:getUserRoleRequest" name="getUserRoleInput" /> + </wsdl:message> + <wsdl:message name="getUserRoleResponse"> + <wsdl:part element="tns:getUserRoleResponse" name="getUserRoleOutput" /> + </wsdl:message> + + <!-- #### getRights #### //--> <wsdl:message name="getRightsRequest"> <wsdl:part element="tns:getRightsRequest" name="getRightsInput" /> @@ -1633,6 +1670,44 @@ <wsdl:fault name="authenticationFault" message="tns:authenticationFault" /> </wsdl:operation> + + <!-- #### getUserRole #### //--> + <wsdl:operation name="getUserRole"> + + <wsdl:documentation> + Returns ePPNs plus Array of Roles of all members in the project, + caller must be member herself. + <ul> + <li><b>Input Parameters</b> getUserRoleRequest, with elements + <ul> + <li>auth - String, SessionID of user that wants to query + for members</li> + <li>log - String for log information, optional</li> + <li>project - String, ProjectID, such as "TGPR123"</li> + </ul> + </li> + <li><b>Output Parameters</b> getUserRoleResponse. It contains 0...n userRoles, which themselves have elements + <ul> + <li>username - String holding ePPN of user </li> + <li>roles - array of Strings with roles the user has (e.g. "Bearbeiter").</li> + </ul> + </li> + <li><b>Faults</b> + <ul> + <li>authenticationFault</li> + <li>unknownProjectFault</li> + </ul> + </li> + </ul> + </wsdl:documentation> + + <wsdl:input message="tns:getUserRoleRequest" /> + <wsdl:output message="tns:getUserRoleResponse" /> + <wsdl:fault name="authenticationFault" message="tns:authenticationFault" /> + <wsdl:fault name="unknownProjectFault" message="tns:unknownProjectFault" /> + </wsdl:operation> + + <!-- #### getRights #### //--> <wsdl:operation name="getRights"> @@ -2095,6 +2170,15 @@ <wsdl:fault name="authenticationFault"><soap:fault name="authenticationFault" use="literal"/></wsdl:fault> </wsdl:operation> + <!-- #### getUserRole #### //--> + <wsdl:operation name="getUserRole"> + <soap:operation soapAction="http://textgrid.info/namespaces/middleware/tgauth/getUserRole" /> + <wsdl:input><soap:body use="literal" /></wsdl:input> + <wsdl:output><soap:body use="literal" /></wsdl:output> + <wsdl:fault name="authenticationFault"><soap:fault name="authenticationFault" use="literal"/></wsdl:fault> + <wsdl:fault name="unknownProjectFault"><soap:fault name="unknownProjectFault" use="literal"/></wsdl:fault> + </wsdl:operation> + <!-- #### getRights #### //--> <wsdl:operation name="getRights"> <soap:operation soapAction="http://textgrid.info/namespaces/middleware/tgauth/getRights" /> -- GitLab