Auth samples

Basics

The class com.openkm.sdk4csharp.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:

int 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 -> "c41f9ea0-0d6c-45da-bae4-d72b66f42d0f";

Suggested code sample

First, you must create the webservice object:

OKMWebservices ws = OKMWebservicesFactory.newInstance(host);

Then should login using the method "login". You can access the "login" method from webservice object "ws" as is shown below:

ws.login(user, password);

Once you are logged with the webservices the session is keep in the webservice Object. Then you can use the other API method

At this point you can use all the Auth methods from "auth" class as is shown below:

Dictionary<String, int> grants = ws.auth.getGrantedRoles("373bcdd0-c082-4e7b-addd-e10ef813946e");

Methods

login

Description:

MethodReturn valuesDescription

login(String user, String password)

String

Return the login authorized token.

Login token by default have an expiration time of 24h.

After executing the login method, all the next calls will use automatically the authentication token.

Each time login method is executed the login token is replaced by newer.


When user login into the application the first time, is called internally a method what creates user specific folders, like /okm:trash/userId etc.

From API point of view, this method should be only executed first time user accessing from API, for creating specific user folder structure.

Otherwise you can get errors, for example PathNotExistsException /okm:trash/userId when deleting objects, because the folders has not been created.

Example:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using com.openkm.sdk4csharp;
using com.openkm.sdk4csharp.impl; namespace OKMRest { public class Program { static void Main(string[] args) { String host = "http://localhost:8080/openkm"; String username = "okmAdmin"; String password = "admin"; OKMWebservice ws = OKMWebservicesFactory.newInstance(host);
try { ws.login(user, password); } catch (Exception e) { System.Console.WriteLine(e.ToString()); } } } }

login

Description:

MethodReturn valuesDescription

String login(String user, String password, int expiration, bool restrictIp)

String

Login process return authentication token.

Login token by default have an expiration time of variable expiration value in days.

When restrictIP is true, the token only will work from the source IP address.

After executing the login method, all the next calls will use automatically the authentication token.

Each time login method is executed the login token is replaced by newer.

When user login into the application the first time, is called internally a method what creates user specific folders, like /okm:trash/userId etc.

From API point of view, this method should be only executed first time user accessing from API, for creating specific user folder structure.

Otherwise you can get errors, for example PathNotExistsException /okm:trash/userId when deleting objects, because the folders has not been created.

Example:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using com.openkm.sdk4csharp;
using com.openkm.sdk4csharp.impl; namespace OKMRest { public class Program { static void Main(string[] args) { String host = "http://localhost:8080/openkm"; String username = "okmAdmin"; String password = "admin"; OKMWebservice ws = OKMWebservicesFactory.newInstance(host);
int days = 7;
bool restrictIp = true; try {
System.Console.WriteLine("Token: " + ws.login(user, password, days, restrictIp)); } catch (Exception e) { System.Console.WriteLine(e.ToString()); } } } }

getGrantedRoles

Description:

MethodReturn valuesDescription

getGrantedRoles(String nodeId)

Dictionary<String, int>

Return the granted roles of a node.

Example:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using com.openkm.sdk4csharp;
using com.openkm.sdk4csharp.impl; namespace OKMRest { public class Program { static void Main(string[] args) { String host = "http://localhost:8080/openkm"; String username = "okmAdmin"; String password = "admin"; OKMWebservice ws = OKMWebservicesFactory.newInstance(host);
try
{
ws.login(user, password); Dictionary<String, int> grants = ws.auth.getGrantedRoles("14530e37-ac51-4a26-8049-0146a5916dec"); foreach (String role in grants.Keys) { System.Console.WriteLine("role ->" + role); } } catch (Exception e) { System.Console.WriteLine(e.ToString()); } } } }

getGrantedUsers

Description:

MethodReturn valuesDescription

getGrantedUsers(String nodeId)

Dictionary<String, int>

Returns the granted users of a node.

Example:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using com.openkm.sdk4csharp;
using com.openkm.sdk4csharp.impl; namespace OKMRest { public class Program { static void Main(string[] args) { String host = "http://localhost:8080/openkm"; String username = "okmAdmin"; String password = "admin"; OKMWebservice ws = OKMWebservicesFactory.newInstance(host);
try {
ws.login(user, password); Dictionary<String, int> grants = ws.auth.getGrantedUsers("14530e37-ac51-4a26-8049-0146a5916dec"); foreach (KeyValuePair<string, int> kvp in grants) { Console.WriteLine("{0} -> {1}", kvp.Key, kvp.Value); } } catch (Exception e) { System.Console.WriteLine(e.ToString()); } } } }

getRoles

Description:

MethodReturn valuesDescription

getRoles(boolean showAll)

List<String>

Returns the list of all the roles.

When showAll variable is set to true return all the roles - enabled and disabled - otherwise only returns the enabled.

Example:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using com.openkm.sdk4csharp;

namespace OKMRest
{
    public class Program
    {
        static void Main(string[] args)
        {
            String host = "http://localhost:8080/openkm";
            String username = "okmAdmin";
            String password = "admin";
            OKMWebservice ws = OKMWebservicesFactory.newInstance(host);
try {
ws.login(user, password); foreach (String role in ws.auth.getRoles(false)) { System.Console.WriteLine(role); } } catch (Exception e) { System.Console.WriteLine(e.ToString()); } } } }

getRolesByUser

Description:

MethodReturn valuesDescription

getRolesByUser(String user)

List<String>

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

Example:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using com.openkm.sdk4csharp;

namespace OKMRest
{
    public class Program
    {
        static void Main(string[] args)
        {
            String host = "http://localhost:8080/openkm";
            String username = "okmAdmin";
            String password = "admin";
            OKMWebservice ws = OKMWebservicesFactory.newInstance(host);
try {
ws.login(user, password); foreach(String role in ws.auth.getRolesByUser("okmAdmin")) { System.Console.WriteLine(role); } } catch (Exception e) { System.Console.WriteLine(e.ToString()); } } } }

getUser

Description:

MethodReturn valuesDescription

getUser(String userId)

CommonUser

Returns a user.

Example:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using com.openkm.sdk4csharp;

namespace OKMRest
{
    public class Program
    {
        static void Main(string[] args)
        {
            String host = "http://localhost:8080/openkm";
            String username = "okmAdmin";
            String password = "admin";
            OKMWebservice ws = OKMWebservicesFactory.newInstance(host);
try {
ws.login(user, password); CommonUser user = ws.auth.getUser("okmAdmin");
System.Console.WriteLine(user.toString()); } catch (Exception e) { System.Console.WriteLine(e.ToString()); } } } }

getUsers

Description:

MethodReturn valuesDescription

getUsers(boolean showAll)

List<CommonUser>

Returns the list of all the users.

When showAll variable is set to true return all the users - enabled and disabled - otherwise only returns the enabled.

Example:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using com.openkm.sdk4csharp;

namespace OKMRest
{
    public class Program
    {
        static void Main(string[] args)
        {
            String host = "http://localhost:8080/openkm";
            String username = "okmAdmin";
            String password = "admin";
            OKMWebservice ws = OKMWebservicesFactory.newInstance(host);
try {
ws.login(user, password); foreach (CommonUser user in ws.auth.getUsers(false))
{
System.Console.WriteLine(user.toString());
} } catch (Exception e) { System.Console.WriteLine(e.ToString()); } } } }

getUsersByRole

Description:

MethodReturn valuesDescription

getUsersByRole(String role)

List<CommonUser>

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

Example:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using com.openkm.sdk4csharp;

namespace OKMRest
{
    public class Program
    {
        static void Main(string[] args)
        {
            String host = "http://localhost:8080/openkm";
            String username = "okmAdmin";
            String password = "admin";
            OKMWebservice ws = OKMWebservicesFactory.newInstance(host);
try {
ws.login(user, password); foreach (CommonUser user in ws.auth.getUsersByRole("ROLE_ADMIN"))
{
System.Console.WriteLine(user.toString());
} } catch (Exception e) { System.Console.WriteLine(e.ToString()); } } } }

revokeRole

Description:

MethodReturn valuesDescription

revokeRole(String nodeId, String role, int permissions, boolean recursive)

void

Removes a role grant on a node.

The parameter recursive only has a 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:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using com.openkm.sdk4csharp;
using com.openkm.sdk4csharp.bean;

namespace OKMRest
{
    public class Program
    {
        static void Main(string[] args)
        {
            String host = "http://localhost:8180/openkm";
            String username = "okmAdmin";
            String password = "admin";
            OKMWebservice ws = OKMWebservicesFactory.newInstance(host);
try {
ws.login(user, password); // Remove ROLE_USER write grants at the node but not descendants ws.auth.revokeRole("14530e37-ac51-4a26-8049-0146a5916dec", "ROLE_USER", Permission.ALL_GRANTS, false);
// Remove all ROLE_ADMIN grants to the node and descendants ws.auth.revokeRole("14530e37-ac51-4a26-8049-0146a5916dec", "ROLE_ADMIN", Permission.ALL_GRANTS, true); } catch (Exception e) { System.Console.WriteLine(e.ToString()); } } } }

revokeUser

Description:

MethodReturn valuesDescription

revokeUser(String nodeId, String user, int permissions, boolean recursive)

void

Removes a user grant on a node.

The parameter recursive only makes any 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:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using com.openkm.sdk4csharp;

namespace OKMRest
{
    public class Program
    {
        static void Main(string[] args)
        {
            String host = "http://localhost:8080/openkm";
            String username = "okmAdmin";
            String password = "admin";
            OKMWebservice ws = OKMWebservicesFactory.newInstance(host);
try {
ws.login(user, password); // Remove john write grants at the node but not descendants ws.auth.revokeUser("14530e37-ac51-4a26-8049-0146a5916dec", "john", Permission.ALL_GRANTS, false); // Remove all okmAdmin grants at the node and descendants ws.auth.revokeUser("14530e37-ac51-4a26-8049-0146a5916dec", "okmAdmin", Permission.ALL_GRANTS, true); } catch (Exception e) { System.Console.WriteLine(e.ToString()); } } } }

grantRole

Description:

MethodReturn valuesDescription

grantRole(String nodeId, String role, int permissions, boolean recursive)

void

Add role grant on a node.

The parameter recursive only makes any 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:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using com.openkm.sdk4csharp;

namespace OKMRest
{
    public class Program
    {
        static void Main(string[] args)
        {
            String host = "http://localhost:8080/openkm";
            String username = "okmAdmin";
            String password = "admin";
            OKMWebservice ws = OKMWebservicesFactory.newInstance(host);
try {
ws.login(user, password); // Add ROLE_USER write grants at the node but not descendants ws.auth.grantRole("14530e37-ac51-4a26-8049-0146a5916dec", "ROLE_USER", Permission.ALL_GRANTS, false);
// Add all ROLE_ADMIN grants to the node and descendants ws.auth.grantRole("14530e37-ac51-4a26-8049-0146a5916dec", "ROLE_ADMIN", Permission.ALL_GRANTS, true); } catch (Exception e) { System.Console.WriteLine(e.ToString()); } } } }

grantUser

Description:

MethodReturn valuesDescription

grantUser(String nodeId, String user, int permissions, boolean recursive)

void

Adds a user grant on a node.

The parameter recursive only makes any 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:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using com.openkm.sdk4csharp;

namespace OKMRest
{
    public class Program
    {
        static void Main(string[] args)
        {
            String host = "http://localhost:8080/openkm";
            String username = "okmAdmin";
            String password = "admin";
            OKMWebservice ws = OKMWebservicesFactory.newInstance(host);
try {
ws.login(user, password); // Add john write grants at the node but not descendants ws.auth.grantUser("14530e37-ac51-4a26-8049-0146a5916dec", "john", Permission.ALL_GRANTS, false);
// Add all okmAdmin grants at the node and descendants ws.auth.grantUser("14530e37-ac51-4a26-8049-0146a5916dec", "okmAdmin", Permission.ALL_GRANTS, true); } catch (Exception e) { System.Console.WriteLine(e.ToString()); } } } }

getProfiles

Description:

MethodReturn valuesDescription

getProfiles(boolean filterByActive)

List<Profile>

Return the list of all profiles.

When the parameter filterByActive is enabled, the method will return only the active profiles, otherwise will return all available profiles.

Each user has assigned one profile that enables more or less OpenKM UI features.

Example:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using com.openkm.sdk4csharp;
using com.openkm.sdk4csharp.bean;

namespace OKMRest
{
    public class Program
    {
        static void Main(string[] args)
        {
            String host = "http://localhost:8080/openkm";
            String username = "okmAdmin";
            String password = "admin";
            OKMWebservice ws = OKMWebservicesFactory.newInstance(host);
try {
ws.login(user, password); foreach (Profile profile in ws.auth.getProfiles(true)) { System.Console.WriteLine(profile.toString()); } } catch (Exception e) { System.Console.WriteLine(e.ToString()); } } } }

getUserProfile

Description:

MethodReturn valuesDescription

getUserProfile(String userId)

Profile

Returns the profile assigned to a user.

Each user has assigned one profile that enables more or less OpenKM UI features.

Example:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using com.openkm.sdk4csharp;
using com.openkm.sdk4csharp.bean;

namespace OKMRest
{
    public class Program
    {
        static void Main(string[] args)
        {
            String host = "http://localhost:8080/openkm";
            String username = "okmAdmin";
            String password = "admin";
            OKMWebservice ws = OKMWebservicesFactory.newInstance(host);
try {
ws.login(user, password); System.Console.WriteLine(ws.auth.getUserProfile("okmAdmin").toString()); } catch (Exception e) { System.Console.WriteLine(e.ToString()); } } } }

setUserProfile

Description:

MethodReturn valuesDescription

setUserProfile(String userId, long profileId)

void

Change the assigned profile to a user.

Each user has assigned one profile that enables more or less OpenKM UI features.

Example:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using com.openkm.sdk4csharp;
using com.openkm.sdk4csharp.bean;

namespace OKMRest
{
    public class Program
    {
        static void Main(string[] args)
        {
            String host = "http://localhost:8080/openkm";
            String username = "okmAdmin";
            String password = "admin";
            OKMWebservice ws = OKMWebservicesFactory.newInstance(host);
try {
ws.login(user, password); // Set the profile named "default" to the user foreach (Profile profile in ws.auth.getProfiles(true))
{
if (profile.name.Equals("Default"))
{
ws.setUserProfile("okmAdmin", profile.id);
}
} } catch (Exception e) { System.Console.WriteLine(e.ToString()); } } } }

createUser

Description:

MethodReturn valuesDescription

createUser(String user, String password, String email, String name, Boolean active)

void

Create a new user.

Example:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using com.openkm.sdk4csharp;

namespace OKMRest
{
    public class Program
    {
        static void Main(string[] args)
        {
            String host = "http://localhost:8080/openkm";
            String username = "okmAdmin";
            String password = "admin";
            OKMWebservice ws = OKMWebservicesFactory.newInstance(host);
try {
ws.login(user, password); ws.auth.createUser("test", "password.2016", "some@mail.com", "User Name", true); } catch (Exception e) { System.Console.WriteLine(e.ToString()); } } } }

deleteUser

Description:

MethodReturn valuesDescription

deleteUser(String user)

void

Delete a user.

Example:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using com.openkm.sdk4csharp;

namespace OKMRest
{
    public class Program
    {
        static void Main(string[] args)
        {
            String host = "http://localhost:8080/openkm";
            String username = "okmAdmin";
            String password = "admin";
            OKMWebservice ws = OKMWebservicesFactory.newInstance(host);
try {
ws.login(user, password); ws.auth.deleteUser("test"); } catch (Exception e) { System.Console.WriteLine(e.ToString()); } } } }

updateUser 

Description:

MethodReturn valuesDescription

updateUser(String user, String password, String email, String name, Boolean active)

void

Update a user.

Example:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using com.openkm.sdk4csharp;

namespace OKMRest
{
    public class Program
    {
        static void Main(string[] args)
        {
            String host = "http://localhost:8080/openkm";
            String username = "okmAdmin";
            String password = "admin";
            OKMWebservice ws = OKMWebservicesFactory.newInstance(host);
try {
ws.login(user, password); ws.auth.updateUser("test", "newpassword", "some@mail.com", "Test", false); } catch (Exception e) { System.Console.WriteLine(e.ToString()); } } } }

createRole

Description:

MethodReturn valuesDescription

createRole(String role, boolean active)

void

Create a new role.

Example:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using com.openkm.sdk4csharp;

namespace OKMRest
{
    public class Program
    {
        static void Main(string[] args)
        {
            String host = "http://localhost:8080/openkm";
            String username = "okmAdmin";
            String password = "admin";
            OKMWebservice ws = OKMWebservicesFactory.newInstance(host);
try {
ws.login(user, password); ws.auth.createRole("ROLE_TEST", true); } catch (Exception e) { System.Console.WriteLine(e.ToString()); } } } }

deleteRole

Description:

MethodReturn valuesDescription

deleteRole(String role)

void

Delete a role.

Example:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using com.openkm.sdk4csharp;

namespace OKMRest
{
    public class Program
    {
        static void Main(string[] args)
        {
            String host = "http://localhost:8080/openkm";
            String username = "okmAdmin";
            String password = "admin";
            OKMWebservice ws = OKMWebservicesFactory.newInstance(host);
try {
ws.login(user, password); ws.auth.deleteRole("ROLE_TEST"); } catch (Exception e) { System.Console.WriteLine(e.ToString()); } } } }

updateRole

Description:

MethodReturn valuesDescription

updateRole(String role, boolean active)

void

Update a role.

Example:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using com.openkm.sdk4csharp;

namespace OKMRest
{
    public class Program
    {
        static void Main(string[] args)
        {
            String host = "http://localhost:8080/openkm";
            String username = "okmAdmin";
            String password = "admin";
            OKMWebservice ws = OKMWebservicesFactory.newInstance(host);
try {
ws.login(user, password); ws.auth.updateRole("ROLE_TEST", true); } catch (Exception e) { System.Console.WriteLine(e.ToString()); } } } }

assingRole

Description:

MethodReturn valuesDescription

assingRole(String user, String role)

void

Assign a role to a user.

Example:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using com.openkm.sdk4csharp;

namespace OKMRest
{
    public class Program
    {
        static void Main(string[] args)
        {
            String host = "http://localhost:8080/openkm";
            String username = "okmAdmin";
            String password = "admin";
            OKMWebservice ws = OKMWebservicesFactory.newInstance(host);
try {
ws.login(user, password); ws.auth.assignRole("test", "ROLE_USER"); } catch (Exception e) { System.Console.WriteLine(e.ToString()); } } } }

removeRole

Description:

MethodReturn valuesDescription

removeRole(String user, String role)

void

Remove a role from a user.

Example:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using com.openkm.sdk4csharp;

namespace OKMRest
{
    public class Program
    {
        static void Main(string[] args)
        {
            String host = "http://localhost:8080/openkm";
            String username = "okmAdmin";
            String password = "admin";
            OKMWebservice ws = OKMWebservicesFactory.newInstance(host);
try {
ws.login(user, password); ws.auth.removeRole("test", "ROLE_USER"); } catch (Exception e) { System.Console.WriteLine(e.ToString()); } } } }

changeSecurity

Description:

MethodReturn valuesDescription

changeSecurity(ChangeSecurity changeSecurity)

void

Change the security of a node.

Example:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using com.openkm.sdk4csharp;
using com.openkm.sdk4csharp.bean;

namespace OKMRest
{
    public class Program
    {
        static void Main(string[] args)
        {
            String host = "http://localhost:8080/openkm";
            String username = "okmAdmin";
            String password = "admin";
            OKMWebservice ws = OKMWebservicesFactory.newInstance(host);
try {
ws.login(user, password); Folder fld = ws.folder.createFolder("a978f8e6-aa87-4f0f-b7bc-6f44cb090fdf", "Folder1");
ChangeSecurity cs = new ChangeSecurity();
List<GrantedRole> grList = new List<GrantedRole>();
GrantedRole gr = new GrantedRole();
gr.role = "ROLE_TEST";
gr.permissions = Permission.READ | Permission.WRITE;
grList.Add(gr);
cs.grantedRolesList = grList;
ws.auth.changeSecurity(fld.uuid, cs); } catch (Exception e) { System.Console.WriteLine(e.ToString()); } } } }

overwriteSecurity

Description:

MethodReturn valuesDescription

overwriteSecurity(String uuid, ChangeSecurity changeSecurity)

void

Overwrite the security of a node.


The ChangeSecurity object is used in changeSecurity and overwriteSecurity methods.

Although set values in the variables revokeUsers and revokeRoles of the ChangeSecurity object, these values will not be taken in consideration while overwritten the security.

Example:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using com.openkm.sdk4csharp;
using com.openkm.sdk4csharp.bean;

namespace OKMRest
{
    public class Program
    {
        static void Main(string[] args)
        {
            String host = "http://localhost:8080/openkm";
            String username = "okmAdmin";
            String password = "admin";
            OKMWebservice ws = OKMWebservicesFactory.newInstance(host);
try {
ws.login(user, password); GrantedUser gu = new GrantedUser();
gu.user = pherrera;
gu.permissions = Permission.READ | Permission.WRITE;

List<GrantedUser> guList = new List<GrantedUser>();
guList.Add(gu);

GrantedRole gr = new GrantedRole();
gr.role = "ROLE_TEST";
gr.permissions = Permission.READ | Permission.WRITE;

List<GrantedRole> grList = new List<GrantedRole>();
grList.Add(gr);

ChangeSecurity changeSecurity = new ChangeSecurity();
changeSecurity.recursive = false;
changeSecurity.grantedUsersList = guList;
changeSecurity.grantedRolesList = grList;

ws.auth.overwriteSecurity("4f873d10-654e-4d99-a94f-15466e30a0f6", changeSecurity); } catch (Exception e) { System.Console.WriteLine(e.ToString()); } } } }

logout

Description:

MethodReturn valuesDescription

logout()

void

Execute the logout method in OpenKM side.


The authentication token will be reset.

Example:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using com.openkm.sdk4csharp;
using com.openkm.sdk4csharp.bean;

namespace OKMRest
{
public class Program
{
static void Main(string[] args)
{
String host = "http://localhost:8080/openkm";
String username = "okmAdmin";
String password = "admin";
OKMWebservice ws = OKMWebservicesFactory.newInstance(host);

try
{
ws.login(user, password);
ws.logout();
}
catch (Exception e)
{
System.Console.WriteLine(e.ToString());
}
}
}
}

getGrantedUsersAndRoles

Description:

MethodReturn valuesDescription

getGrantedUsersAndRoles(String uuid)

GrantedUsersAndRolesItem

Return the granted users and roles of a node.

Example:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using com.openkm.sdk4csharp;
using com.openkm.sdk4csharp.bean;

namespace OKMRest
{
public class Program
{
static void Main(string[] args)
{
String host = "http://localhost:8080/openkm";
String username = "okmAdmin";
String password = "admin";
OKMWebservice ws = OKMWebservicesFactory.newInstance(host);

try
{
ws.login(user, password);
GrantedUsersAndRolesItem grants = ws.auth.getGrantedUsersAndRoles("15e35aef-f1bb-451e-ac86-3b0f7c88ca9f");
foreach (KeyValuePair<string, int> user in grants.grantedUsers)
{
System.Console.WriteLine(user.Key + "->" + user.Value);
}
foreach (KeyValuePair<string, int> role in grants.grantedRoles)
{
System.Console.WriteLine(role.Key + "->" + role.Value);
}
}
catch (Exception e)
{
System.Console.WriteLine(e.ToString());
}
}
}
}

setUserPermissions

Description:

MethodReturn valuesDescription

setUserPermissions(String uuid, String userId, int permissions, bool recursive)

void

Update user permissions on a node.

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

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

Example:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using com.openkm.sdk4csharp;
using com.openkm.sdk4csharp.bean;

namespace OKMRest
{
public class Program
{
static void Main(string[] args)
{
String host = "http://localhost:8080/openkm";
String username = "okmAdmin";
String password = "admin";
OKMWebservice ws = OKMWebservicesFactory.newInstance(host);

try
{
ws.login(user, password);
// Set user permissions
ws.auth.setUserPermissions("22c1d190-f798-489d-b420-2008cb38705b", "user1", Permission.READ + Permission.WRITE, false);

// Update permissions of okmAdmin at the node and descendants
ws.auth.setUserPermissions("22c1d190-f798-489d-b420-2008cb38705b", "okmAdmin", Permission.ALL_GRANTS, true);
}
catch (Exception e)
{
System.Console.WriteLine(e.ToString());
}
}
}
}

setRolePermissions

Description:

MethodReturn valuesDescription

setRolePermissions(String uuid, String roleId, int permissions, bool recursive)

void

Update role permissions on a node.

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

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

Example:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using com.openkm.sdk4csharp;
using com.openkm.sdk4csharp.bean;

namespace OKMRest
{
public class Program
{
static void Main(string[] args)
{
String host = "http://localhost:8080/openkm";
String username = "okmAdmin";
String password = "admin";
OKMWebservice ws = OKMWebservicesFactory.newInstance(host);

try
{
ws.login(user, password);
// Set role permissions
ws.auth.setRolePermissions("22c1d190-f798-489d-b420-2008cb38705b", "ROLE_USER", Permission.READ + Permission.WRITE, false);

// Update permissions of ROLE_ADMIN at the node and descendants
ws.auth.setRolePermissions("22c1d190-f798-489d-b420-2008cb38705b", "ROLE_ADMIN", Permission.ALL_GRANTS, true);
}
catch (Exception e)
{
System.Console.WriteLine(e.ToString());
}
}
}
}

getUserTenants

Description:

MethodReturn valuesDescription

getUserTenants()

List<Tenant>

Return the list of all tenants.

Example:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using com.openkm.sdk4csharp;
using com.openkm.sdk4csharp.bean;

namespace OKMRest
{
public class Program
{
static void Main(string[] args)
{
String host = "http://localhost:8080/openkm";
String username = "okmAdmin";
String password = "admin";
OKMWebservice ws = OKMWebservicesFactory.newInstance(host);

try
{
ws.login(user, password);
List<Tenant> tenants = ws.auth.getUserTenants();
foreach (Tenant tenant in tenants)
{
System.Console.WriteLine(tenant.toString());
}
}
catch (Exception e)
{
System.Console.WriteLine(e.ToString());
}
}
}
}

setUserTenant

Description:

MethodReturn valuesDescription

setUserTenant(long tenantId)

void

Change the assigned tenant to a user.

A user might have access to several tenants but only have one assigned.

Example:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using com.openkm.sdk4csharp;
using com.openkm.sdk4csharp.bean;

namespace OKMRest
{
public class Program
{
static void Main(string[] args)
{
String host = "http://localhost:8080/openkm";
String username = "okmAdmin";
String password = "admin";
OKMWebservice ws = OKMWebservicesFactory.newInstance(host);

try
{
ws.login(user, password);
long tenantId = 1; // Valid tenant id
ws.auth.setUserTenant(tenantId);
}
catch (Exception e)
{
System.Console.WriteLine(e.ToString());
}
}
}
}

isAdmin

Description:

MethodReturn valuesDescription

isAdmin()

bool

Check if the authenticated user is a member of administrators.

Example:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using com.openkm.sdk4csharp;
using com.openkm.sdk4csharp.bean;

namespace OKMRest
{
public class Program
{
static void Main(string[] args)
{
String host = "http://localhost:8080/openkm";
String username = "okmAdmin";
String password = "admin";
OKMWebservice ws = OKMWebservicesFactory.newInstance(host);

try
{
ws.login(user, password);
bool isAdmin = ws.auth.isAdmin();
}
catch (Exception e)
{
System.Console.WriteLine(e.ToString());
}
}
}
}

getSessionId

Description:

MethodReturn valuesDescription

getSessionId()

String

Get http session id.

Example:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using com.openkm.sdk4csharp;
using com.openkm.sdk4csharp.bean;
using com.openkm.sdk4csharp.impl;

namespace OKMRest
{
public class Program
{
static void Main(string[] args)
{
String host = "http://localhost:8080/openkm";
String username = "okmAdmin";
String password = "admin";
OKMWebservice ws = OKMWebservicesFactory.newInstance(host);

try
{
ws.login(user, password);
String id = ws.auth.getSessionId();
}
catch (Exception e)
{
System.Console.WriteLine(e.ToString());
}
}
}
}

hasSecurityRecursive

Description:

MethodReturn valuesDescription

hasSecurityRecursive()

bool

Check if the user has grants to propagate the security recursively.

The role is set in the configuration parameter named "default.security.recursive.role"

Example:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using com.openkm.sdk4csharp;
using com.openkm.sdk4csharp.bean;
using com.openkm.sdk4csharp.impl;

namespace OKMRest
{
public class Program
{
static void Main(string[] args)
{
String host = "http://localhost:8080/openkm";
String username = "okmAdmin";
String password = "admin";
OKMWebservice ws = OKMWebservicesFactory.newInstance(host);

try
{
ws.login(user, password);
bool hasSecurityRecursive = ws.auth.hasSecurityRecursive();
}
catch (Exception e)
{
System.Console.WriteLine(e.ToString());
}
}
}
}

hasTaskManagerAdmin

Description:

MethodReturn valuesDescription

hasTaskManagerAdmin()

bool

Check if the user is a member of the role task manager admin.


The configuration parameter named "default.task.manager.admin.role" is used to indicate the role.

Example:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using com.openkm.sdk4csharp;
using com.openkm.sdk4csharp.bean;
using com.openkm.sdk4csharp.impl;

namespace OKMRest
{
public class Program
{
static void Main(string[] args)
{
String host = "http://localhost:8080/openkm";
String username = "okmAdmin";
String password = "admin";
OKMWebservice ws = OKMWebservicesFactory.newInstance(host);

try
{
ws.login(user, password);
bool hasSecurityRecursive = ws.auth.hasTaskManagerAdmin();
}
catch (Exception e)
{
System.Console.WriteLine(e.ToString());
}
}
}
}

isLoginLowercase

Description:

MethodReturn valuesDescription

isLoginLowercase()

bool

Return true when user is must be set in lowercase in login.

Example:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using com.openkm.sdk4csharp;
using com.openkm.sdk4csharp.bean;
using com.openkm.sdk4csharp.impl;

namespace OKMRest
{
public class Program
{
static void Main(string[] args)
{
String host = "http://localhost:8080/openkm";
String username = "okmAdmin";
String password = "admin";
OKMWebservice ws = OKMWebservicesFactory.newInstance(host);

try
{
ws.login(user, password);
System.Console.WriteLine(ws.auth.isLoginLowercase().ToString());
}
catch (Exception e)
{
System.Console.WriteLine(e.ToString());
}
}
}
}

isPasswordExpired

Description:

MethodReturn valuesDescription

isPasswordExpired()

Boolean

True when the password of the user has expired.


By default the password expriation is disabled. Take a look at the configuration parameter named "user.password.expiration" in the Security configuration parameters section to enable.

Example:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using com.openkm.sdk4csharp;
using com.openkm.sdk4csharp.bean;
using com.openkm.sdk4csharp.impl;

namespace OKMRest
{
public class Program
{
static void Main(string[] args)
{
String host = "http://localhost:8080/openkm";
String username = "okmAdmin";
String password = "admin";
OKMWebservice ws = OKMWebservicesFactory.newInstance(host);

try
{
ws.login(user, password);
System.Console.WriteLine("Password expired= " + ws.auth.isPasswordExpired().ToString());
}
catch (Exception e)
{
System.Console.WriteLine(e.ToString());
}
}
}
}

getUserToken

Description:

MethodReturn valuesDescription

getUserToken(String userId)

String

Return the auth token from a given user.

This action can only be done by a super user (user with ROLE_ADMIN).

Example:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using com.openkm.sdk4csharp;
using com.openkm.sdk4csharp.bean;
using com.openkm.sdk4csharp.impl;

namespace OKMRest
{
public class Program
{
static void Main(string[] args)
{
String host = "http://localhost:8080/openkm";
String username = "okmAdmin";
String password = "admin";
OKMWebservice ws = OKMWebservicesFactory.newInstance(host);

try
{
ws.login(user, password);
String userToken = ws.auth.getUserToken("testUser");
Console.WriteLine("UserToken: " + userToken);
}
catch (Exception e)
{
System.Console.WriteLine(e.ToString());
}
}
}
}