Auth samples
Basics
Section titled “Basics”The class com.openkm.sdk4csharp.bean.Permission contains permission values (READ, WRITE, etc.). You should use it in combination with methods that change or retrieve security grants.
In almost all methods, you’ll see a parameter named “nodeId”. The value of this parameter can be a valid node UUID (folder, document, mail, record) or a node path.
Suggested code sample
Section titled “Suggested code sample”First, you must create the webservice object:
OKMWebservices ws = OKMWebservicesFactory.newInstance(host);Then you should log in using the “login” method. You can access the “login” method from the webservice object “ws” as shown below:
ws.login(user, password);At this point you can use all the Auth methods of the “auth” class, as shown below:
Dictionary<String, int> grants = ws.auth.getGrantedRoles("373bcdd0-c082-4e7b-addd-e10ef813946e");Methods
Section titled “Methods”Description:
| Method | Return values | Description |
|---|---|---|
| login(String personalAccessToken) | String | Returns the authorized login token. |
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 { String personalAccessToken = "okmpat-ZRjVfMBcCp2tB1T2Dzbq"; ws.login(personalAccessToken); } catch (Exception e) { System.Console.WriteLine(e.ToString()); } } }}Description:
| Method | Return values | Description |
|---|---|---|
| login(String user, String password) | String | Returns the authorized login token. |
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()); } } }}Description:
| Method | Return values | Description |
|---|---|---|
| String login(String user, String password, int expiration, bool restrictIp) | String | Login process return authentication token. |
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()); } } }}logout
Section titled “logout”Description:
| Method | Return values | Description |
|---|---|---|
| logout() | void | Executes the logout method on the OpenKM side. |
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()); } } }}getRefreshToken
Section titled “getRefreshToken”Description:
| Method | Return values | Description |
|---|---|---|
| getRefreshToken() | String | Refreshes the current authentication token. |
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); String token = ws.getRefreshToken(); System.Console.WriteLine("New token : " + token); } catch (Exception e) { System.Console.WriteLine(e.ToString()); } } }}getGrantedRoles
Section titled “getGrantedRoles”Description:
| Method | Return values | Description |
|---|---|---|
| getGrantedRoles(String nodeId) | Dictionary<String, int> | Returns 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
Section titled “getGrantedUsers”Description:
| Method | Return values | Description |
|---|---|---|
| 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
Section titled “getRoles”Description:
| Method | Return values | Description |
|---|---|---|
| getRoles(boolean showAll) | List |
Returns the list of all the roles. |
When the showAll variable is set to true, it returns all the roles - enabled and disabled - otherwise it only returns the enabled ones.
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
Section titled “getRolesByUser”Description:
| Method | Return values | Description |
|---|---|---|
| getRolesByUser(String user) | List |
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
Section titled “getUser”Description:
| Method | Return values | Description |
|---|---|---|
| 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
Section titled “getUsers”Description:
| Method | Return values | Description |
|---|---|---|
| getUsers(boolean showAll) | List |
Returns the list of all the users. |
When the showAll variable is set to true, it returns all the users - enabled and disabled - otherwise it only returns the enabled ones.
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
Section titled “getUsersByRole”Description:
| Method | Return values | Description |
|---|---|---|
| getUsersByRole(String roleId) | List |
Returns the list of all users who have been 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
Section titled “revokeRole”Description:
| Method | Return values | Description |
|---|---|---|
| revokeRole(String nodeId, String role, int permissions, boolean recursive) | void | Removes a role grant from a node. |
The parameter recursive only makes 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
Section titled “revokeUser”Description:
| Method | Return values | Description |
|---|---|---|
| revokeUser(String nodeId, String user, int permissions, boolean recursive) | void | Removes a user grant from a node. |
The parameter recursive only makes 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
Section titled “grantRole”Description:
| Method | Return values | Description |
|---|---|---|
| grantRole(String nodeId, String role, int permissions, boolean recursive) | void | Adds a role grant to a node. |
The parameter recursive only makes 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
Section titled “grantUser”Description:
| Method | Return values | Description |
|---|---|---|
| grantUser(String nodeId, String userId, int permissions, boolean recursive) | void | Adds a user grant to a node. |
The parameter recursive only makes 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
Section titled “getProfiles”Description:
| Method | Return values | Description |
|---|---|---|
| getProfiles(boolean filterByActive) | List |
Returns the list of all profiles. |
When the parameter filterByActive is enabled, the method returns only the active profiles; otherwise it returns all available profiles.
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
Section titled “getUserProfile”Description:
| Method | Return values | Description |
|---|---|---|
| getUserProfile(String userId) | Profile | Returns the profile assigned to a user. |
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
Section titled “setUserProfile”Description:
| Method | Return values | Description |
|---|---|---|
| setUserProfile(String userId, long profileId) | void | Changes the profile assigned to a user. |
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
Section titled “createUser”Description:
| Method | Return values | Description |
|---|---|---|
| createUser(String user, String password, String email, String name, Boolean active) | void | Creates 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
Section titled “deleteUser”Description:
| Method | Return values | Description |
|---|---|---|
| deleteUser(String userId) | void | Deletes 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
Section titled “updateUser”Description:
| Method | Return values | Description |
|---|---|---|
| updateUser(String userId, String password, String email, String name, Boolean active) | void | Updates 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
Section titled “createRole”Description:
| Method | Return values | Description |
|---|---|---|
| createRole(String roleId, boolean active) | void | Creates 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
Section titled “deleteRole”Description:
| Method | Return values | Description |
|---|---|---|
| deleteRole(String roleId) | void | Deletes 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
Section titled “updateRole”Description:
| Method | Return values | Description |
|---|---|---|
| updateRole(String roleId, boolean active) | void | Updates 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()); } } }}assignRole
Section titled “assignRole”Description:
| Method | Return values | Description |
|---|---|---|
| assignRole(String userId, String roleId) | void | Assigns 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
Section titled “removeRole”Description:
| Method | Return values | Description |
|---|---|---|
| removeRole(String userId, String roleId) | void | Removes 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
Section titled “changeSecurity”Description:
| Method | Return values | Description |
|---|---|---|
| changeSecurity(ChangeSecurity changeSecurity) | void | Changes 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
Section titled “overwriteSecurity”Description:
| Method | Return values | Description |
|---|---|---|
| overwriteSecurity(String uuid, ChangeSecurity changeSecurity) | void | Overwrites 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); 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()); } } }}getGrantedUsersAndRoles
Section titled “getGrantedUsersAndRoles”Description:
| Method | Return values | Description |
|---|---|---|
| getGrantedUsersAndRoles(String uuid) | GrantedUsersAndRolesItem | Returns 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
Section titled “setUserPermissions”Description:
| Method | Return values | Description |
|---|---|---|
| setUserPermissions(String uuid, String userId, int permissions, bool recursive) | void | Updates user permissions on a node. |
The parameter recursive only makes sense when the uuid is a folder or record node.
When the parameter recursive is true, the change will be applied to the node and its 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
Section titled “setRolePermissions”Description:
| Method | Return values | Description |
|---|---|---|
| setRolePermissions(String uuid, String roleId, int permissions, bool recursive) | void | Updates role permissions on a node. |
The parameter recursive only makes sense when the uuid is a folder or record node.
When the parameter recursive is true, the change will be applied to the node and its 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
Section titled “getUserTenants”Description:
| Method | Return values | Description |
|---|---|---|
| getUserTenants() | List |
Returns 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
Section titled “setUserTenant”Description:
| Method | Return values | Description |
|---|---|---|
| setUserTenant(long tenantId) | void | Change the assigned tenant for a user. |
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
Section titled “isAdmin”Description:
| Method | Return values | Description |
|---|---|---|
| isAdmin() | bool | Check if the authenticated user is a member of the 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
Section titled “getSessionId”Description:
| Method | Return values | Description |
|---|---|---|
| getSessionId() | String | Get the 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
Section titled “hasSecurityRecursive”Description:
| Method | Return values | Description |
|---|---|---|
| hasSecurityRecursive() | bool | Check if the user has permission to propagate security recursively. |
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
Section titled “hasTaskManagerAdmin”Description:
| Method | Return values | Description |
|---|---|---|
| hasTaskManagerAdmin() | bool | Check if the user is a member of the “task manager admin” 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
Section titled “isLoginLowercase”Description:
| Method | Return values | Description |
|---|---|---|
| isLoginLowercase() | bool | Return true when the user’s login must be in lowercase. |
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
Section titled “isPasswordExpired”Description:
| Method | Return values | Description |
|---|---|---|
| isPasswordExpired() | Boolean | True when the user’s password has expired. |
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
Section titled “getUserToken”Description:
| Method | Return values | Description |
|---|---|---|
| getUserToken(String userId) | String | Return the auth token for a given user. |
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()); } } }}getUserToken
Section titled “getUserToken”Description:
| Method | Return values | Description |
|---|---|---|
| getUserToken(String userId, int expiration, bool restrictIp) | String | Return the auth token for a given user. |
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", 7, true); Console.WriteLine("UserToken: " + userToken); } catch (Exception e) { System.Console.WriteLine(e.ToString()); } } }}createPersonalAccessToken
Section titled “createPersonalAccessToken”Description:
| Method | Return values | Description |
|---|---|---|
| createPersonalAccessToken(String name, DateTime expiration) | String | Return the personal access token. |
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";
try { DateTime today = DateTime.Now; DateTime futureDate = today.AddDays(365);// create an expired token String personalAccessToken = ws.auth.createPersonalAccessToken("good-pat-test", futureDate); OKMWebservices ws= OKMWebservicesFactory.newInstance(Config.HOST); ws.login(personalAccessToken); } catch (Exception e) { System.Console.WriteLine(e.ToString()); } } }}