From 5b846baeab243fe5059e3f9d0d531371151f3642 Mon Sep 17 00:00:00 2001 From: Martin Haase <martin.haase@daasi.de> Date: Fri, 8 Jul 2011 09:08:27 +0000 Subject: [PATCH] internal UUIDs for TextGridResources now, sppeding up registerResource() and obsoleting the provisorical Demon git-svn-id: https://textgridlab.org/svn/textgrid/trunk/middleware/tgauth@10628 7c539038-3410-0410-b1ec-0f2a7bf1c452 --- .../rbacSoap/TgExtra.class.php | 94 ++----------------- .../rbacSoap/examples/tgCheckAccess.php | 1 + .../rbacSoap/examples/tgCrudCheckAccess.php | 4 +- 3 files changed, 11 insertions(+), 88 deletions(-) diff --git a/info.textgrid.middleware.tgauth.rbac/rbacSoap/TgExtra.class.php b/info.textgrid.middleware.tgauth.rbac/rbacSoap/TgExtra.class.php index 6e1a0fb..cb72358 100755 --- a/info.textgrid.middleware.tgauth.rbac/rbacSoap/TgExtra.class.php +++ b/info.textgrid.middleware.tgauth.rbac/rbacSoap/TgExtra.class.php @@ -2356,65 +2356,16 @@ class TgExtra { $objFaultDetail = new stdClass(); + // Create a new uuid for the new project + $strRbacResourceUuid = $this->uuidV4(); + + if( $inRequest->secret === $this->config->getValue( "crud", "secret" ) ) { // The TextGrid-resource naming-attribute $resourceNamingAttribute = $this->rbac->getConfiguration()->getValue( "resource", "namingattribute" ); - $sock = socket_create( AF_INET, SOCK_STREAM, SOL_TCP ); - - if( socket_connect( $sock, '127.0.0.1', $this->config->getValue( "resourcecounterdaemon", "port" ) ) ) { - - $freeNumber = socket_read( $sock, 1024 ); - - if( $freeNumber > 0 ) { - - $askedDaemon = true; - $registerTry = 1; - - } - - - socket_shutdown( $sock, 2 ); - socket_close( $sock ); - - } - else { - - // Look for the counter entry for resources. - $arrCounter = $this->connection['counter']->getEntry( "cn=resource," . $this->config->getValue( "counter", "base" ) ); - - - // If there is a counter entry, use it - if( isset( $arrCounter['dn'] ) ) { - - $freeNumber = $arrCounter['sn'][0] + 1; - - } - else { - - $arrResourceName = $this->connection['resource']->search( $this->config->getValue( "textGridResource", "base" ), - "(objectClass=textGridResource)", - "one", $resourceNamingAttribute ); - - - // Every returned resource has to be examined for - // its number to get the next free one. - for( $i = 0; $i < sizeof( $arrResourceName ); $i++ ) { - - $resourceName = preg_replace( "/^TGRS/i", "", $arrResourceName[$i][$resourceNamingAttribute][0] ); - $maxNumber = max( $maxNumber, intval( $resourceName ) ); - - } - - - $freeNumber = $maxNumber + 1; - - } - - } - if( $this->rbac->checkAccess( $inRequest->auth, "create", $inRequest->project ) ) { @@ -2439,7 +2390,7 @@ class TgExtra { } $arrEntry['tgprojectid'][] = $inRequest->project; $arrEntry['tgispublic'][] = "FALSE"; - $arrEntry[$resourceNamingAttribute][] = "TGRS" . ($freeNumber); + $arrEntry[$resourceNamingAttribute][] = "TGRS-" . $strRbacResourceUuid; //($freeNumber); $arrEntry['tgresourceowner'][] = $this->rbac->sessionUser( $inRequest->auth ); @@ -2472,48 +2423,20 @@ class TgExtra { // Try to add the resource with the appropriate number. If // this fails, we will try again (10 times). - $registered = $this->connection['resource']->add( $this->rbac->getConfiguration()->getValue( "resource", "namingattribute" ) . "=TGRS" - . $freeNumber . "," . $this->config->getValue( "textGridResource", "base" ), + $registered = $this->connection['resource']->add( $this->rbac->getConfiguration()->getValue( "resource", "namingattribute" ) . "=TGRS-" + . $strRbacResourceUuid . "," . $this->config->getValue( "textGridResource", "base" ), $arrEntry ); $registerTry--; - - $registered ? false : $freeNumber++; - - } - - - if( !$askedDaemon && $registered ) { - - // This entry will add or modify the directory that way - // that there is a counter entry. - $arrEntry = Array(); - $arrEntry['objectclass'][] = "person"; - $arrEntry['cn'][] = "resource"; - $arrEntry['sn'][] = $freeNumber; - - - if( !isset( $arrCounter['dn'] ) ) { - - $this->connection['counter']->add( "cn=resource," . $this->config->getValue( "counter", "base" ), $arrEntry ); - - } - else { - - $this->connection['counter']->modify( "cn=resource," . $this->config->getValue( "counter", "base" ), $arrEntry ); - - } - } // Create the set of operations the user has on // the new object. - $result->operation = $this->rbac->userOperationsOnObject( $this->rbac->sessionUser( $inRequest->auth ), "TGRS" . $freeNumber ); -// $result->result = $registered; + $result->operation = $this->rbac->userOperationsOnObject( $this->rbac->sessionUser( $inRequest->auth ), "TGRS-" . $strRbacResourceUuid ); } else { @@ -2527,7 +2450,6 @@ class TgExtra { "You are not allowed to create resources in this project.", get_class( $this ), $objFaultDetail ); -// $result->operation = Array(); } diff --git a/info.textgrid.middleware.tgauth.rbac/rbacSoap/examples/tgCheckAccess.php b/info.textgrid.middleware.tgauth.rbac/rbacSoap/examples/tgCheckAccess.php index 62df32c..dbb8f3a 100755 --- a/info.textgrid.middleware.tgauth.rbac/rbacSoap/examples/tgCheckAccess.php +++ b/info.textgrid.middleware.tgauth.rbac/rbacSoap/examples/tgCheckAccess.php @@ -43,6 +43,7 @@ if( isset( $_POST['auth'] ) ) { $checkResponse = $soapSystem->tgCheckAccess( $regReq ); + echo $soapSystem->__getLastRequest() . "\n\n"; echo $soapSystem->__getLastResponse(); if( $checkResponse->result ) { diff --git a/info.textgrid.middleware.tgauth.rbac/rbacSoap/examples/tgCrudCheckAccess.php b/info.textgrid.middleware.tgauth.rbac/rbacSoap/examples/tgCrudCheckAccess.php index 208437e..604069d 100755 --- a/info.textgrid.middleware.tgauth.rbac/rbacSoap/examples/tgCrudCheckAccess.php +++ b/info.textgrid.middleware.tgauth.rbac/rbacSoap/examples/tgCrudCheckAccess.php @@ -44,8 +44,8 @@ if( isset( $_POST['auth'] ) ) { $checkResponse = $soapSystem->tgCrudCheckAccess( $regReq ); - // echo $soapSystem->__getLastResponse(); - +// echo $soapSystem->__getLastRequest() . "\n\n"; +// echo $soapSystem->__getLastResponse(); if( $checkResponse->result ) { -- GitLab