adding usernameExists methods to Keycloack class

Project: http://git-wip-us.apache.org/repos/asf/airavata-php-gateway/repo
Commit: 
http://git-wip-us.apache.org/repos/asf/airavata-php-gateway/commit/f83e0e51
Tree: http://git-wip-us.apache.org/repos/asf/airavata-php-gateway/tree/f83e0e51
Diff: http://git-wip-us.apache.org/repos/asf/airavata-php-gateway/diff/f83e0e51

Branch: refs/heads/develop
Commit: f83e0e51daf8ba6ffd73c1b475940dad2fc9c3a2
Parents: 0d34e17
Author: scnakandala <[email protected]>
Authored: Fri Mar 24 12:25:07 2017 -0400
Committer: scnakandala <[email protected]>
Committed: Fri Mar 24 12:25:07 2017 -0400

----------------------------------------------------------------------
 app/controllers/AccountController.php |  2 +-
 app/controllers/AdminController.php   |  2 +-
 app/libraries/Keycloak/Keycloak.php   | 15 +++++++++++++++
 app/libraries/SharingUtilities.php    |  6 +++---
 4 files changed, 20 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/airavata-php-gateway/blob/f83e0e51/app/controllers/AccountController.php
----------------------------------------------------------------------
diff --git a/app/controllers/AccountController.php 
b/app/controllers/AccountController.php
index 86f3259..0c3a3fc 100644
--- a/app/controllers/AccountController.php
+++ b/app/controllers/AccountController.php
@@ -47,7 +47,7 @@ class AccountController extends BaseController
         $im = isset($_POST['im']) ? $_POST['im'] : null;
         $url = isset($_POST['url']) ? $_POST['url'] : null;
 
-        if (WSIS::usernameExists($username)) {
+        if (Keycloak::usernameExists($username)) {
             return Redirect::to("create")
                 ->withInput(Input::except('password', 'password_confirm'))
                 ->with("username_exists", true);

http://git-wip-us.apache.org/repos/asf/airavata-php-gateway/blob/f83e0e51/app/controllers/AdminController.php
----------------------------------------------------------------------
diff --git a/app/controllers/AdminController.php 
b/app/controllers/AdminController.php
index e1a4ea5..94b11b8 100644
--- a/app/controllers/AdminController.php
+++ b/app/controllers/AdminController.php
@@ -150,7 +150,7 @@ class AdminController extends BaseController {
 
        public function addGatewayAdminSubmit(){
                //check if username exists
-               if(WSIS::usernameExists( Input::get("username")) )
+               if(Keycloak::usernameExists( Input::get("username")) )
                {
                        // FIXME: this requires the user id not the username
             Keycloak::updateUserRoles(Input::get("username"), array( 
"new"=>array( Config::get('wsis::admin-role-name')), "deleted"=>array() ) );

http://git-wip-us.apache.org/repos/asf/airavata-php-gateway/blob/f83e0e51/app/libraries/Keycloak/Keycloak.php
----------------------------------------------------------------------
diff --git a/app/libraries/Keycloak/Keycloak.php 
b/app/libraries/Keycloak/Keycloak.php
index 56e2680..819541d 100644
--- a/app/libraries/Keycloak/Keycloak.php
+++ b/app/libraries/Keycloak/Keycloak.php
@@ -232,6 +232,21 @@ class Keycloak {
         return $result;
     }
 
+    /**
+     * Function to check whether a user exists with the given userId
+     * @param $user_id
+     * @return bool
+     */
+    public function usernameExists($user_id){
+        try{
+            $user = $this->users->getUser($this->realm, $user_id);
+            return $user != null;
+        }catch (Exception $ex){
+            // Username does not exists
+            return false;
+        }
+    }
+
     private function getOpenIDConnectDiscoveryConfiguration() {
 
         // TODO: cache the result of the request

http://git-wip-us.apache.org/repos/asf/airavata-php-gateway/blob/f83e0e51/app/libraries/SharingUtilities.php
----------------------------------------------------------------------
diff --git a/app/libraries/SharingUtilities.php 
b/app/libraries/SharingUtilities.php
index aea9675..5822a04 100755
--- a/app/libraries/SharingUtilities.php
+++ b/app/libraries/SharingUtilities.php
@@ -66,13 +66,13 @@ class SharingUtilities {
         $write = GrouperUtilities::getAllAccessibleUsers($resourceId, 
$dataResourceType, ResourcePermissionType::WRITE);
 
         foreach($read as $uid) {
-            if ($uid !== Session::get('username') && 
WSIS::usernameExists($uid)) {
+            if ($uid !== Session::get('username') && 
Keycloak::usernameExists($uid)) {
                 $users[$uid] = array('read' => true, 'write' => false);
             }
         }
 
         foreach($write as $uid) {
-            if ($uid !== Session::get('username') && 
WSIS::usernameExists($uid)) {
+            if ($uid !== Session::get('username') && 
Keycloak::usernameExists($uid)) {
                 $users[$uid]['write'] = true;
             }
         }
@@ -88,7 +88,7 @@ class SharingUtilities {
      */
     public static function getUserProfiles($uids) {
         $uids = array_filter($uids, function($uid) {
-            return ($uid !== Session::get('username') && 
WSIS::usernameExists($uid));
+            return ($uid !== Session::get('username') && 
Keycloak::usernameExists($uid));
         });
         $profiles = array();
         foreach ($uids as $uid) {

Reply via email to