Auth samples

Basics

The class openkm\bean\Permission contains permission values ( READ, WRITE, etc. ). You should use it in combination with methods that are changing or getting security grants.

To set READ and WRITE access you should do:

$permission = Permission::READ + Permission::WRITE;

To check if you have permission access you should do:

// permission is a valid integer value
if (($permission | Permission::WRITE) = Permission::WRITE) {
  // Has WRITE grants.
}

On almost methods you'll see parameter named "nodeId". The value of this parameter can be some valid node UUID ( folder, document, mail, record ) or node path.

Example of nodeId:

  • Using UUID -> "96c44de6-1d0d-45fb-b380-4984f46bbeb3";
  • Using path -> "/okm:root/SDK4PHP/sample.pdf"

Methods

getGrantedRoles

Description:

MethodReturn valuesDescription

getGrantedRoles($nodeId)

array

Returns the granted roles of a node.

Parameters:

$nodeId string type is the uuid or path of the document, folder, mail or record.

Example:

<?php

include '../src/openkm/OpenKM.php';

use openkm\OKMWebServicesFactory;
use openkm\OpenKM;

class ExampleAuth {

    const HOST = "http://localhost:8080/OpenKM/";
    const USER = "okmAdmin";
    const PASSWORD = "admin";

    private $ws;

    public function __construct() {
        $this->ws = OKMWebServicesFactory::build(self::HOST, self::USER, self::PASSWORD);
    }

    public function testGetGrantedRoles() {
        try {
            $grantedRoles = $this->ws->getGrantedRoles('/okm:root/SDK4PHP');
            foreach ($grantedRoles as $role) {
                var_dump($role);
            }
        } catch (Exception $e) {
            var_dump($e);
        }
    }

}

$openkm = new OpenKM(); //autoload
$exampleAuth = new ExampleAuth();
$exampleAuth->testGetGrantedRoles();
?>

getGrantedUsers

Description:

MethodReturn valuesDescription

getGrantedUsers($nodeId)

array

Returns the granted users of a node.

Parameters:

$nodeId string type is the uuid or path of the document, folder, mail or record.

Example:

<?php

include '../src/openkm/OpenKM.php';

use openkm\OKMWebServicesFactory;
use openkm\OpenKM;

class ExampleAuth {

    const HOST = "http://localhost:8080/OpenKM/";
    const USER = "okmAdmin";
    const PASSWORD = "admin";

    private $ws;

    public function __construct() {
        $this->ws = OKMWebServicesFactory::build(self::HOST, self::USER, self::PASSWORD);
    }
    
    public function testGetGrantedUsers() {
        try {
            $grantedUsers = $this->ws->getGrantedUsers('/okm:root/SDK4PHP');
            foreach ($grantedUsers as $user) {
                var_dump($user);
            }
        } catch (Exception $e) {
            var_dump($e);
        }
    }

}

$openkm = new OpenKM(); //autoload
$exampleAuth = new ExampleAuth();
$exampleAuth->testGetGrantedUsers();
?>

getRoles

Description:

MethodReturn valuesDescription

getRoles()

array

Returns the list of all the roles.

Example:

<?php

include '../src/openkm/OpenKM.php';

use openkm\OKMWebServicesFactory;
use openkm\OpenKM;

class ExampleAuth {

    const HOST = "http://localhost:8080/OpenKM/";
    const USER = "okmAdmin";
    const PASSWORD = "admin";

    private $ws;

    public function __construct() {
        $this->ws = OKMWebServicesFactory::build(self::HOST, self::USER, self::PASSWORD);
    }

    public function testGetRoles() {
        try {
            $roles = $this->ws->getRoles();
            foreach ($roles as $role) {
                var_dump($role);
            }
        } catch (Exception $e) {
            var_dump($e);
        }
    }

}

$openkm = new OpenKM(); //autoload
$exampleAuth = new ExampleAuth();
$exampleAuth->testGetRoles();
?>

getUsers

Description:

MethodReturn valuesDescription

getUsers()

array

Returns the list of all the users.

Example:

<?php

include '../src/openkm/OpenKM.php';

use openkm\OKMWebServicesFactory;
use openkm\OpenKM;

class ExampleAuth {

    const HOST = "http://localhost:8080/OpenKM/";
    const USER = "okmAdmin";
    const PASSWORD = "admin";

    private $ws;

    public function __construct() {
        $this->ws = OKMWebServicesFactory::build(self::HOST, self::USER, self::PASSWORD);
    }

    public function testGetUsers() {
        try {
            $users = $this->ws->getUsers();
            foreach ($users as $user) {
                var_dump($user);
            }
        } catch (Exception $e) {
            var_dump($e);
        }
    }

}

$openkm = new OpenKM(); //autoload
$exampleAuth = new ExampleAuth();
$exampleAuth->testGetUsers();
?>

grantRole

Description:

MethodReturn valuesDescription

grantRole($nodeId, $role, $permissions, $recursive)

void

Adds a role grant on a node.

Parameters:

$nodeId string type is the uuid or path of the document, folder, mail or record.

$role string type

$permissions int type

$recursive bool type

The parameter recursive only has sense when the nodeId is a folder or record node.

When the parameter recursive is true, the change will be applied to the node and descendants.

Example:

<?php

include '../src/openkm/OpenKM.php';

use openkm\OKMWebServicesFactory;
use openkm\OpenKM;

class ExampleAuth {

    const HOST = "http://localhost:8080/OpenKM/";
    const USER = "okmAdmin";
    const PASSWORD = "admin";

    private $ws;

    public function __construct() {
        $this->ws = OKMWebServicesFactory::build(self::HOST, self::USER, self::PASSWORD);
    }

    public function testGrantRole() {
        try {
            // Add ROLE_USER write grants at the node but not descendants
            $this->ws->grantRole("/okm:root/SDK4PHP", "ROLE_USER", openkm\bean\Permission::ALL_GRANTS, false);

            // Add all ROLE_ADMIN grants to the node and descendants
            $this->ws->grantRole("/okm:root/SDK4PHP", "ROLE_ADMIN", openkm\bean\Permission::ALL_GRANTS, true);
            
            echo 'grant Role';
        } catch (Exception $e) {
            var_dump($e);
        }
    }

}

$openkm = new OpenKM(); //autoload
$exampleAuth = new ExampleAuth();
$exampleAuth->testGrantRole();
?>

grantUser

Description:

MethodReturn valuesDescription

grantUser($nodeId, $user, $permissions, $recursive)

void

Adds a user grant on a node.

Parameters:

$nodeId string type is the uuid or path of the document, folder, mail or record.

$user string type

$permissions int type

$recursive bool type

The parameter recursive only has sense when the nodeId is a folder or record node.

When parameter recursive is true, the change will be applied to the node and descendants.

Example:

<?php

include '../src/openkm/OpenKM.php';

use openkm\OKMWebServicesFactory;
use openkm\OpenKM;

class ExampleAuth {

    const HOST = "http://localhost:8080/OpenKM/";
    const USER = "okmAdmin";
    const PASSWORD = "admin";

    private $ws;

    public function __construct() {
        $this->ws = OKMWebServicesFactory::build(self::HOST, self::USER, self::PASSWORD);
    }
    
    public function testGrantUser() {
        try {
            // Add sochoa write grants at the node but not descendants
            $this->ws->grantUser("/okm:root/SDK4PHP", "sochoa", \openkm\bean\Permission::ALL_GRANTS, false);

            // Add all okmAdmin grants at the node and descendants
            $this->ws->grantUser("/okm:root/SDK4PHP", "okmAdmin", \openkm\bean\Permission::ALL_GRANTS, true);

            echo 'grant User';
        } catch (Exception $e) {
            var_dump($e);
        }
    }

}

$openkm = new OpenKM(); //autoload
$exampleAuth = new ExampleAuth();
$exampleAuth->testGrantUser();
?>

revokeRole

Description:

MethodReturn valuesDescription

revokeRole($nodeId, $role, $permissions, $recursive)

void

Removes a role grant on a node.

Parameters:

$nodeId string type is the uuid or path of the document, folder, mail or record.

$role string type

$permissions int type

$recursive bool type

The parameter recursive only has sense when the nodeId is a folder or record node.

When the parameter recursive is true, the change will be applied to the node and descendants.

Example:

<?php

include '../src/openkm/OpenKM.php';

use openkm\OKMWebServicesFactory;
use openkm\OpenKM;

class ExampleAuth {

    const HOST = "http://localhost:8080/OpenKM/";
    const USER = "okmAdmin";
    const PASSWORD = "admin";

    private $ws;

    public function __construct() {
        $this->ws = OKMWebServicesFactory::build(self::HOST, self::USER, self::PASSWORD);
    }

    public function testRevokeRole() {
        try {
            // Remove ROLE_USER write grants at the node but not descendants
            $this->ws->revokeRole("/okm:root/SDK4PHP", "ROLE_USER", \openkm\bean\Permission::ALL_GRANTS, false);

            // Remove all ROLE_ADMIN grants to the node and descendants
            $this->ws->revokeRole("/okm:root/SDK4PHP", "ROLE_ADMIN", \openkm\bean\Permission::ALL_GRANTS, true);

            echo 'revoke Role';
        } catch (Exception $e) {
            var_dump($e);
        }
    }

}

$openkm = new OpenKM(); //autoload
$exampleAuth = new ExampleAuth();
$exampleAuth->testRevokeRole();
?>

revokeUser

Description:

MethodReturn valuesDescription

revokeUser($nodeId, $user, $permissions, $recursive)

void

Removes a user grant on a node.

Parameters:

$nodeId string type is the uuid or path of the document, folder, mail or record.

$user string type

$permissions int type

$recursive bool type

The parameter recursive only has sense when the nodeId is a folder or record node.

When parameter recursive is true, the change will be applied to the node and descendants.

Example:

<?php

include '../src/openkm/OpenKM.php';

use openkm\OKMWebServicesFactory;
use openkm\OpenKM;

class ExampleAuth {

    const HOST = "http://localhost:8080/OpenKM/";
    const USER = "okmAdmin";
    const PASSWORD = "admin";

    private $ws;

    public function __construct() {
        $this->ws = OKMWebServicesFactory::build(self::HOST, self::USER, self::PASSWORD);
    }

    public function testRevokeUser() {
        try {
            // Remove sochoa write grants at the node but not descendants
            $this->ws->revokeUser("/okm:root/SDK4PHP", "sochoa", \openkm\bean\Permission::ALL_GRANTS, false);

            // Remove all okmAdmin grants at the node and descendants
            $this->ws->revokeUser("/okm:root/SDK4PHP", "okmAdmin", \openkm\bean\Permission::ALL_GRANTS, true);
            echo 'revoke User';
        } catch (Exception $e) {
            var_dump($e);
        }
    }

}

$openkm = new OpenKM(); //autoload
$exampleAuth = new ExampleAuth();
$exampleAuth->testRevokeUser();
?>

getRolesByUser

Description:

MethodReturn valuesDescription

getRolesByUser($user)

array

Returns the list of all the roles assigned to a user.

Parameters:

$user string type is the user

Example:

<?php

include '../src/openkm/OpenKM.php';

use openkm\OKMWebServicesFactory;
use openkm\OpenKM;

class ExampleAuth {

    const HOST = "http://localhost:8080/OpenKM/";
    const USER = "okmAdmin";
    const PASSWORD = "admin";

    private $ws;

    public function __construct() {
        $this->ws = OKMWebServicesFactory::build(self::HOST, self::USER, self::PASSWORD);
    }

    public function testGetRolesByUser() {
        try {
            $roles = $this->ws->getRolesByUser('okmAdmin');
            foreach ($roles as $role) {
                var_dump($role);
            }
        } catch (Exception $e) {
            var_dump($e);
        }
    }

}

$openkm = new OpenKM(); //autoload
$exampleAuth = new ExampleAuth();
$exampleAuth->testGetRolesByUser();
?>

getUsersByRole

Description:

MethodReturn valuesDescription

getUsersByRole($role)

array

Returns the list of all the users who have assigned a role.

Parameters:

$role string type is the role

Example:

<?php

include '../src/openkm/OpenKM.php';

use openkm\OKMWebServicesFactory;
use openkm\OpenKM;

class ExampleAuth {

    const HOST = "http://localhost:8080/OpenKM/";
    const USER = "okmAdmin";
    const PASSWORD = "admin";

    private $ws;

    public function __construct() {
        $this->ws = OKMWebServicesFactory::build(self::HOST, self::USER, self::PASSWORD);
    }

    public function testGetUsersByRole() {
        try {
            $users = $this->ws->getUsersByRole('ROLE_ADMIN');
            foreach ($users as $user) {
                var_dump($user);
            }
        } catch (Exception $e) {
            var_dump($e);
        }
    }

}

$openkm = new OpenKM(); //autoload
$exampleAuth = new ExampleAuth();
$exampleAuth->testGetUsersByRole();
?>

getMail

Description:

MethodReturn valuesDescription

getMail($user)

string

Returns the mail of a valid user.

Parameters:

$user string type is the user

Example:

<?php

include '../src/openkm/OpenKM.php';

use openkm\OKMWebServicesFactory;
use openkm\OpenKM;

class ExampleAuth {

    const HOST = "http://localhost:8080/OpenKM/";
    const USER = "okmAdmin";
    const PASSWORD = "admin";

    private $ws;

    public function __construct() {
        $this->ws = OKMWebServicesFactory::build(self::HOST, self::USER, self::PASSWORD);
    }

    public function testGetMail() {
        try {
            var_dump($this->ws->getMail('okmAdmin'));
        } catch (Exception $e) {
            var_dump($e);
        }
    }

}

$openkm = new OpenKM(); //autoload
$exampleAuth = new ExampleAuth();
$exampleAuth->testGetMail();
?>

getName

Description:

MethodReturn valuesDescription

getName($user)

string

Returns the name of a valid user.

Parameters:

$user string type is the user

Example:

<?php

include '../src/openkm/OpenKM.php';

use openkm\OKMWebServicesFactory;
use openkm\OpenKM;

class ExampleAuth {

    const HOST = "http://localhost:8080/OpenKM/";
    const USER = "okmAdmin";
    const PASSWORD = "admin";

    private $ws;

    public function __construct() {
        $this->ws = OKMWebServicesFactory::build(self::HOST, self::USER, self::PASSWORD);
    }

    public function testGetName() {
        try {
            var_dump($this->ws->getName('okmAdmin'));
        } catch (Exception $e) {
            var_dump($e);
        }
    }
}

$openkm = new OpenKM(); //autoload
$exampleAuth = new ExampleAuth();
$exampleAuth->testGetName();
?>