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";
- Using path -> "/okm:root/sample.pdf"
Methods
getGrantedRoles
Description:
Method | Return values | Description |
---|---|---|
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;
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, username, password);
try
{
Dictionary<String, int> grants = ws.getGrantedRoles("/okm:root");
foreach (String role in grants.Keys)
{
System.Console.WriteLine("role ->" + role);
}
}
catch (Exception e)
{
System.Console.WriteLine(e.ToString());
}
}
}
}
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;
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, username, password);
try
{
Dictionary<String, int> grants = ws.getGrantedUsers("/okm:root");
foreach (KeyValuePair<string, int> kvp in grants)
{
Console.WriteLine("{0} -> {1}", kvp.Key, kvp.Value);
}
}
catch (Exception e)
{
System.Console.WriteLine(e.ToString());
}
}
}
}
getMail
Description:
Method | Return values | Description |
---|---|---|
getMail(String user) |
String |
Returns the mail of a valid 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, username, password);
try
{
System.Console.WriteLine(ws.getMail("okmAdmin"));
} catch (Exception e) {
System.Console.WriteLine(e.ToString());
}
}
}
}
getName
Description:
Method | Return values | Description |
---|---|---|
getName(String user) |
String |
Returns the name of a valid 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, username, password);
try
{
System.Console.WriteLine(ws.getName("okmAdmin"));
} catch (Exception e) {
System.Console.WriteLine(e.ToString());
}
System.Console.ReadKey();
}
}
}
getRoles
Description:
Method | Return values | Description |
---|---|---|
getRoles() |
List<String> |
Returns the list of all the roles. |
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, username, password);
try
{
foreach (String role in ws.getRoles())
{
System.Console.WriteLine(role);
}
} catch (Exception e) {
System.Console.WriteLine(e.ToString());
}
}
}
}
getRolesByUser
Description:
Method | Return values | Description |
---|---|---|
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, username, password);
try
{
foreach(String role in ws.getRolesByUser("okmAdmin"))
{
System.Console.WriteLine(role);
}
} catch (Exception e) {
System.Console.WriteLine(e.ToString());
}
}
}
}
getUsers
Description:
Method | Return values | Description |
---|---|---|
getUsers() |
List<String> |
Returns the list of all the users. |
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, username, password);
try
{
foreach (String user in ws.getUsers())
{
System.Console.WriteLine(user);
}
}
catch (Exception e)
{
System.Console.WriteLine(e.ToString());
}
}
}
}
getUsersByRole
Description:
Method | Return values | Description |
---|---|---|
getUsersByRole(String role) |
List<String> |
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, username, password);
try
{
foreach (String user in ws.getUsersByRole("ROLE_ADMIN"))
{
System.Console.WriteLine(user);
}
}
catch (Exception e)
{
System.Console.WriteLine(e.ToString());
}
}
}
}
revokeRole
Description:
Method | Return values | Description |
---|---|---|
revokeRole(String nodeId, String role, int permissions, boolean recursive) |
void |
Removes a role grant on a node. |
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:
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, username, password);
try
{
// Remove ROLE_USER write grants at the node but not descendants
ws.revokeRole("/okm:root", "ROLE_USER", Permission.ALL_GRANTS, false);
// Remove all ROLE_ADMIN grants to the node and descendants
ws.revokeRole("/okm:root", "ROLE_ADMIN", Permission.ALL_GRANTS, true);
}
catch (Exception e)
{
System.Console.WriteLine(e.ToString());
}
}
}
}
revokeUser
Description:
Method | Return values | Description |
---|---|---|
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, username, password);
try
{
// Remove john write grants at the node but not descendants
ws.revokeUser("/okm:root", "john", Permission.ALL_GRANTS, false);
// Remove all okmAdmin grants at the node and descendants
ws.revokeUser("/okm:root", "okmAdmin", Permission.ALL_GRANTS, true);
} catch (Exception e) {
System.Console.WriteLine(e.ToString());
}
}
}
}
grantRole
Description:
Method | Return values | Description |
---|---|---|
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, username, password);
try
{
// Add ROLE_USER write grants at the node but not descendants
ws.grantRole("/okm:root", "ROLE_USER", Permission.ALL_GRANTS, false);
// Add all ROLE_ADMIN grants to the node and descendants
ws.grantRole("/okm:root", "ROLE_ADMIN", Permission.ALL_GRANTS, true);
} catch (Exception e) {
System.Console.WriteLine(e.ToString());
}
}
}
}
grantUser
Description:
Method | Return values | Description |
---|---|---|
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, username, password);
try
{
// Add john write grants at the node but not descendants
ws.grantUser("/okm:root", "john", Permission.ALL_GRANTS, false);
// Add all okmAdmin grants at the node and descendants
ws.grantUser("/okm:root", "okmAdmin", Permission.ALL_GRANTS, true);
} catch (Exception e) {
System.Console.WriteLine(e.ToString());
}
}
}
}
getProfiles
Description:
Method | Return values | Description |
---|---|---|
getProfiles(boolean filterByActive) |
List<Profile> |
Return the list of all profiles. |
Whenthe 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, username, password);
try
{
foreach (Profile profile in ws.getProfiles(true))
{
System.Console.WriteLine(profile);
}
} catch (Exception e) {
System.Console.WriteLine(e.ToString());
}
}
}
}
getUserProfile
Description:
Method | Return values | Description |
---|---|---|
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, username, password);
try
{
System.Console.WriteLine(ws.getUserProfile("okmAdmin"));
} catch (Exception e) {
System.Console.WriteLine(e.ToString());
}
}
}
}
setUserProfile
Description:
Method | Return values | Description |
---|---|---|
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, username, password);
try
{
// Set the profile named "default" to the user
foreach (Profile profile in ws.getProfiles(true).profiles)
{
if (profile.name.Equals("default"))
{
ws.setUserProfile("okmAdmin", profile.id);
}
}
} catch (Exception e) {
System.Console.WriteLine(e.ToString());
}
}
}
}
createUser
Description:
Method | Return values | Description |
---|---|---|
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, username, password);
try
{
ws.createUser("test", "password.2016", "some@mail.com", "User Name", true);
}
catch (Exception e)
{
System.Console.WriteLine(e.ToString());
}
}
}
}
deleteUser
Description:
Method | Return values | Description |
---|---|---|
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, username, password);
try
{
ws.deleteUser("test");
}
catch (Exception e)
{
System.Console.WriteLine(e.ToString());
}
}
}
}
updateUser
Description:
Method | Return values | Description |
---|---|---|
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, username, password);
try
{
ws.updateUser("test", "newpassword", "some@mail.com", "Test", false);
}
catch (Exception e)
{
System.Console.WriteLine(e.ToString());
}
}
}
}
createRole
Description:
Method | Return values | Description |
---|---|---|
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, username, password);
try
{
ws.createRole("ROLE_TEST", true);
}
catch (Exception e)
{
System.Console.WriteLine(e.ToString());
}
}
}
}
deleteRole
Description:
Method | Return values | Description |
---|---|---|
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, username, password);
try
{
ws.deleteRole("ROLE_TEST");
}
catch (Exception e)
{
System.Console.WriteLine(e.ToString());
}
}
}
}
updateRole
Description:
Method | Return values | Description |
---|---|---|
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, username, password);
try
{
ws.updateRole("ROLE_TEST", true);
}
catch (Exception e)
{
System.Console.WriteLine(e.ToString());
}
}
}
}
assingRole
Description:
Method | Return values | Description |
---|---|---|
assingRole(String user, String role) |
void |
Assign 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, username, password);
try
{
ws.assignRole("test", "ROLE_USER");
}
catch (Exception e)
{
System.Console.WriteLine(e.ToString());
}
}
}
}
removeRole
Description:
Method | Return values | Description |
---|---|---|
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, username, password);
try
{
ws.removeRole("test", "ROLE_USER");
}
catch (Exception e)
{
System.Console.WriteLine(e.ToString());
}
}
}
}
changeSecurity
Description:
Method | Return values | Description |
---|---|---|
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, username, password);
try
{
ChangeSecurity cs = new ChangeSecurity();
cs.nodeId = "7f3e8715-945d-4d0f-a66c-444c2b0c6dcd";
GrantedRoleList grList = new GrantedRoleList();
GrantedRole gr = new GrantedRole();
gr.role = "ROLE_TEST";
gr.permissions = Permission.READ | Permission.WRITE;
grList.grantedRoles.Add(gr);
cs.grantedRolesList = grList;
ws.changeSecurity(cs);
}
catch (Exception e)
{
System.Console.WriteLine(e.ToString());
}
}
}
}
login
Description:
Method | Return values | Description |
---|---|---|
login() |
void |
Simulate first login process. |
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;
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, username, password);
try
{
ws.login();
}
catch (Exception e)
{
System.Console.WriteLine(e.ToString());
}
}
}
}