Skip to content
Other versions

Loading…

Auth samples

The class com.openkm.sdk4j.bean.Permission contains permission values ( READ, WRITE, etc. ). You should use it in combination with methods that change or get security grants.

First, you must create the web service object:

OKMWebservices ws = OKMWebservicesFactory.getInstance(host);

Then you should log in using the method “login”. You can access the “login” method from the web service object “ws” as shown below:

ws.login(user, password);

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

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

Description:

Method Return values Description
login(String user, String password) String The login process returns an authentication token.

Example:

package com.openkm;
import com.openkm.sdk4j.OKMWebservicesFactory;
import com.openkm.sdk4j.impl.OKMWebservices;
public class Test {
public static void main(String[] args) {
String host = "http://localhost:8080/openkm";
String user = "okmAdmin";
String password = "admin";
OKMWebservices ws = OKMWebservicesFactory.getInstance(host);
try {
System.out.println("Token: " + ws.login(user, password));
} catch (Exception e) {
e.printStackTrace();
}
}
}

Description:

Method Return values Description
login(String user, String password, int expiration, boolean restrictIP) String The login process returns an authentication token.

Example:

package com.openkm;
import com.openkm.sdk4j.OKMWebservicesFactory;
import com.openkm.sdk4j.impl.OKMWebservices;
public class Test {
public static void main(String[] args) {
String host = "http://localhost:8080/openkm";
String user = "okmAdmin";
String password = "admin";
OKMWebservices ws = OKMWebservicesFactory.getInstance(host);
int days = 7;
boolean restrictIp = true;
try {
System.out.println("Token: " + ws.login(user, password, days, restrictIp));
} catch (Exception e) {
e.printStackTrace();
}
}
}

Description:

Method Return values Description
setAuthorizationToken(String authorizationToken) void Authentication process using an authorization token.

Example:

package com.openkm;
import com.openkm.sdk4j.OKMWebservicesFactory;
import com.openkm.sdk4j.impl.OKMWebservices;
public class Test {
public static void main(String[] args) {
String host = "http://localhost:8080/openkm";
// Usually a long-term authorization token
String authorizationToken = "eyJhbGciOiJIUzUxMiJ9.eyJzdWIiOiJqbGxvcnQiLYRpsCI6IiIsInJvbGUiOlsiUk9MRV9BRE1JTiIsIlJPTEVfTElDRU5TRSIsIlJPTEVfU0VDVVJJVFlfUkVDVVJTSVZFIiwiUk9MRV9UQVNLX01BTkFHRVJfQURNSU4iLCJST0xFX1RFQ05JQ08iLCJST0xFX1RSQUNLX1RJTUUiLCJST0xFX1RSQUNLX1RJTUVfQURNSU4iLCJST0xFX1VTRVIiXSwidHdvRkFBdXRoZW50aWNhdGlvblJlcXVpcmVkIjpmYWxzZSwidHdvRkFBdXRoZW50aWNhdGVkIjpmYWxzZSwiaWF0IjoxNzUzMjkwMTIxLCJleHAiOjE3NTMzNzY1MjF9.mc0pMWv0GNZljxThN1OOR-zSyJJBTc6NTULwi1TYi7tVoSiuq15-lv85MlBrWzTwoFFebwMPZ_PJQhUAJxkXjA"
OKMWebservices ws = OKMWebservicesFactory.getInstance(host);
try {
ws.setAuthorizationToken(authorizationToken);
// at this point, you have grants to request the API
} catch (Exception e) {
e.printStackTrace();
}
}
}

Description:

Method Return values Description
logout() void Execute the logout method on the OpenKM side.

Example:

package com.openkm;
import com.openkm.sdk4j.OKMWebservicesFactory;
import com.openkm.sdk4j.impl.OKMWebservices;
public class Test {
public static void main(String[] args) {
String host = "http://localhost:8080/openkm";
String user = "okmAdmin";
String password = "admin";
OKMWebservices ws = OKMWebservicesFactory.getInstance(host);
try {
ws.login(user, password);
ws.logout();
} catch (Exception e) {
e.printStackTrace();
}
}
}

Description:

Method Return values Description
getRefreshToken() void Refreshes the current authentication token.

Example:

package com.openkm;
import com.openkm.sdk4j.OKMWebservicesFactory;
import com.openkm.sdk4j.impl.OKMWebservices;
public class Test {
public static void main(String[] args) {
String host = "http://localhost:8080/openkm";
String user = "okmAdmin";
String password = "admin";
OKMWebservices ws = OKMWebservicesFactory.getInstance(host);
try {
ws.login(user, password);
// getRefreshToken
String token = ws.getRefreshToken();
System.out.println("New Token: " + token);
} catch (Exception e) {
e.printStackTrace();
}
}
}

Description:

Method Return values Description
getGrantedUsersAndRoles(String uuid) GrantedUsersAndRolesItem Returns the granted users and roles of a node.

Example:

package com.openkm;
import com.openkm.sdk4j.OKMWebservicesFactory;
import com.openkm.sdk4j.bean.GrantedUsersAndRolesItem;
import com.openkm.sdk4j.impl.OKMWebservices;
public class Test {
public static void main(String[] args) {
String host = "http://localhost:8080/openkm";
String username = "okmAdmin";
String password = "admin";
OKMWebservices ws = OKMWebservicesFactory.getInstance(host);
try {
ws.login(username, password);
GrantedUsersAndRolesItem grants = ws.auth.getGrantedUsersAndRoles("3c68b3a1-c65c-4b1e-84b5-9ce2712ca573");
for (String user : grants.getGrantedUsers().keySet()) {
System.out.println(user + "->" + grants.getGrantedUsers().get(user));
}
for (String role : grants.getGrantedRoles().keySet()) {
System.out.println(role + "->" + grants.getGrantedRoles().get(role));
}
} catch (Exception e) {
e.printStackTrace();
}
}
}

Description:

Method Return values Description
getGrantedRoles(String uuid) Map<String, Integer> Returns the granted roles of a node.

Example:

package com.openkm;
import java.util.Map;
import com.openkm.sdk4j.OKMWebservicesFactory;
import com.openkm.sdk4j.impl.OKMWebservices;
public class Test {
public static void main(String[] args) {
String host = "http://localhost:8080/openkm";
String user = "okmAdmin";
String password = "admin";
OKMWebservices ws = OKMWebservicesFactory.getInstance(host);
try {
ws.login(user, password);
Map<String, Integer> grants = ws.auth.getGrantedRoles("373bcdd0-c082-4e7b-addd-e10ef813946e");
for (String role : grants.keySet()) {
System.out.println(role + "->" + grants.get(role));
}
} catch (Exception e) {
e.printStackTrace();
}
}
}

Description:

Method Return values Description
getGrantedUsers(String uuid) Map<String, Integer> Returns the granted users of a node.

Example:

package com.openkm;
import java.util.Map;
import com.openkm.sdk4j.OKMWebservicesFactory;
import com.openkm.sdk4j.impl.OKMWebservices;
public class Test {
public static void main(String[] args) {
String host = "http://localhost:8080/openkm";
String username = "okmAdmin";
String password = "admin";
OKMWebservices ws = OKMWebservicesFactory.getInstance(host);
try {
ws.login(username, password);
Map<String, Integer> grants = ws.auth.getGrantedUsers("373bcdd0-c082-4e7b-addd-e10ef813946e");
for (String user : grants.keySet()) {
System.out.println(user + "->" + grants.get(user));
}
} catch (Exception e) {
e.printStackTrace();
}
}
}

Description:

Method Return values Description
getRoles(boolean showAll) List Returns the list of all roles.

When the showAll variable is set to true, it returns all the roles — enabled and disabled; otherwise it returns only the enabled ones.

Example:

package com.openkm;
import com.openkm.sdk4j.OKMWebservicesFactory;
import com.openkm.sdk4j.impl.OKMWebservices;
public class Test {
public static void main(String[] args) {
String host = "http://localhost:8080/OpenKM";
String username = "okmAdmin";
String password = "admin";
OKMWebservices ws = OKMWebservicesFactory.getInstance(host);
try {
ws.login(username, password);
for (String role : ws.auth.getRolesByUser("okmAdmin")) {
System.out.println(role);
}
} catch (Exception e) {
e.printStackTrace();
}
}
}

Description:

Method Return values Description
getRolesByUser(String user) List Returns the list of all roles assigned to a user.

Example:

package com.openkm;
import com.openkm.sdk4j.OKMWebservicesFactory;
import com.openkm.sdk4j.impl.OKMWebservices;
public class Test {
public static void main(String[] args) {
String host = "http://localhost:8080/OpenKM";
String username = "okmAdmin";
String password = "admin";
OKMWebservices ws = OKMWebservicesFactory.getInstance(host);
try {
ws.login(username, password);
for (String role : ws.auth.getRolesByUser("okmAdmin")) {
System.out.println(role);
}
} catch (Exception e) {
e.printStackTrace();
}
}
}

Description:

Method Return values Description
getUsers(boolean showAll) List Returns the list of all users.

When the showAll variable is set to true, it returns all the users — enabled and disabled; otherwise it returns only the enabled ones.

Example:

package com.openkm;
import com.openkm.sdk4j.OKMWebservicesFactory;
import com.openkm.sdk4j.bean.CommonUser;
import com.openkm.sdk4j.impl.OKMWebservices;
public class Test {
public static void main(String[] args) {
String host = "http://localhost:8080/openkm";
String user = "okmAdmin";
String password = "admin";
OKMWebservices ws = OKMWebservicesFactory.getInstance(host);
try {
ws.login(user, password);
for (CommonUser commonUser : ws.auth.getUsers(true)) {
System.out.println(commonUser);
}
} catch (Exception e) {
e.printStackTrace();
}
}
}

Description:

Method Return values Description
getUser(String userId) CommonUser Returns all user data.

Example:

package com.openkm;
import com.openkm.sdk4j.OKMWebservicesFactory;
import com.openkm.sdk4j.bean.CommonUser;
import com.openkm.sdk4j.impl.OKMWebservices;
public class Test {
public static void main(String[] args) {
String host = "http://localhost:8080/openkm";
String user = "okmAdmin";
String password = "admin";
OKMWebservices ws = OKMWebservicesFactory.getInstance(host);
try {
ws.login(user, password);
CommonUser commonUser = ws.auth.getUser("okmAdmin");
System.out.print(commonUser);
} catch (Exception e) {
e.printStackTrace();
}
}
}

Description:

Method Return values Description
getUsersByRole(String role) List Returns the list of all users who have been assigned a role.

Example:

package com.openkm;
import com.openkm.sdk4j.OKMWebservicesFactory;
import com.openkm.sdk4j.bean.CommonUser;
import com.openkm.sdk4j.impl.OKMWebservices;
public class Test {
public static void main(String[] args) {
String host = "http://localhost:8080/openkm";
String user = "okmAdmin";
String password = "admin";
OKMWebservices ws = OKMWebservicesFactory.getInstance(host);
try {
ws.login(user, password);
for (CommonUser commonUser : ws.auth.getUsersByRole("ROLE_ADMIN")) {
System.out.println(commonUser);
}
} catch (Exception e) {
e.printStackTrace();
}
}
}

Description:

Method Return values Description
revokeRole(String uuid, String roleId, int permissions, boolean recursive) void Removes a role grant on a node.

The ‘recursive’ parameter only applies when the uuid is a folder or a record node.

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

Example:

package com.openkm;
import com.openkm.sdk4j.OKMWebservicesFactory;
import com.openkm.sdk4j.bean.Permission;
import com.openkm.sdk4j.impl.OKMWebservices;
public class Test {
public static void main(String[] args) {
String host = "http://localhost:8080/openkm";
String user = "okmAdmin";
String password = "admin";
OKMWebservices ws = OKMWebservicesFactory.getInstance(host);
try {
ws.login(user, password);
// Remove ROLE_USER write grants at the node but not descendants
ws.auth.revokeRole("4f873d10-654e-4d99-a94f-15466e30a0f6", "ROLE_USER", Permission.ALL_GRANTS, false);
// Remove all ROLE_ADMIN grants to the node and descendants
ws.auth.revokeRole("4f873d10-654e-4d99-a94f-15466e30a0f6", "ROLE_ADMIN", Permission.ALL_GRANTS, true);
} catch (Exception e) {
e.printStackTrace();
}
}
}

Description:

Method Return values Description
revokeUser(String uuid, String user, int permissions, boolean recursive) void Removes a user grant on a node.

The ‘recursive’ parameter only applies when the uuid is a folder or a record node.

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

Example:

package com.openkm;
import com.openkm.sdk4j.OKMWebservicesFactory;
import com.openkm.sdk4j.bean.Permission;
import com.openkm.sdk4j.impl.OKMWebservices;
public class Test {
public static void main(String[] args) {
String host = "http://localhost:8080/openkm";
String user = "okmAdmin";
String password = "admin";
OKMWebservices ws = OKMWebservicesFactory.getInstance(host);
try {
ws.login(user, password);
// Remove sochoa write grants at the node but not descendants
ws.auth.revokeUser("373bcdd0-c082-4e7b-addd-e10ef813946e", "sochoa", Permission.ALL_GRANTS, false);
// Remove all okmAdmin grants at the node and descendants
ws.auth.revokeUser("373bcdd0-c082-4e7b-addd-e10ef813946e", "okmAdmin", Permission.ALL_GRANTS, true);
} catch (Exception e) {
e.printStackTrace();
}
}
}

Description:

Method Return values Description
grantRole(String uuid, String role, int permissions, boolean recursive) void Adds a role grant on a node.

The ‘recursive’ parameter only applies when the uuid is a folder or a record node.

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

Example:

package com.openkm;
import com.openkm.sdk4j.OKMWebservicesFactory;
import com.openkm.sdk4j.bean.Permission;
import com.openkm.sdk4j.impl.OKMWebservices;
public class Test {
public static void main(String[] args) {
String host = "http://localhost:8080/openkm";
String user = "okmAdmin";
String password = "admin";
OKMWebservices ws = OKMWebservicesFactory.getInstance(host);
try {
ws.login(user, password);
// Add ROLE_USER write grants at the node but not descendants
ws.auth.grantRole("4f873d10-654e-4d99-a94f-15466e30a0f6", "ROLE_USER", Permission.ALL_GRANTS, false);
// Add all ROLE_ADMIN grants to the node and descendants
ws.auth.grantRole("4f873d10-654e-4d99-a94f-15466e30a0f6", "ROLE_ADMIN", Permission.ALL_GRANTS, true);
} catch (Exception e) {
e.printStackTrace();
}
}
}

Description:

Method Return values Description
grantUser(String uuid, String user, int permissions, boolean recursive) void Adds a user grant on a node.

The ‘recursive’ parameter only applies when the uuid is a folder or a record node.

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

Example:

package com.openkm;
import com.openkm.sdk4j.OKMWebservicesFactory;
import com.openkm.sdk4j.bean.Permission;
import com.openkm.sdk4j.impl.OKMWebservices;
public class Test {
public static void main(String[] args) {
String host = "http://localhost:8080/openkm";
String user = "okmAdmin";
String password = "admin";
OKMWebservices ws = OKMWebservicesFactory.getInstance(host);
try {
ws.login(user, password);
// Add sochoa write grants at the node but not descendants
ws.auth.grantUser("4f873d10-654e-4d99-a94f-15466e30a0f6", "sochoa", Permission.ALL_GRANTS, false);
// Add all okmAdmin grants at the node and descendants
ws.auth.grantUser("4f873d10-654e-4d99-a94f-15466e30a0f6", "okmAdmin", Permission.ALL_GRANTS, true);
} catch (Exception e) {
e.printStackTrace();
}
}
}

Description:

Method Return values Description
changeSecurity(String uuid, ChangeSecurity changeSecurity) void Changes the security of a node.

Example:

package com.openkm;
import java.util.ArrayList;
import java.util.List;
import com.openkm.sdk4j.OKMWebservicesFactory;
import com.openkm.sdk4j.bean.ChangeSecurity;
import com.openkm.sdk4j.bean.GrantedRole;
import com.openkm.sdk4j.bean.GrantedUser;
import com.openkm.sdk4j.bean.Permission;
import com.openkm.sdk4j.impl.OKMWebservices;
public class Test {
public static void main(String[] args) {
String host = "http://localhost:8080/openkm";
String user = "okmAdmin";
String password = "admin";
OKMWebservices ws = OKMWebservicesFactory.getInstance(host);
try {
ws.login(user, password);
List<GrantedUser> guList = new ArrayList<>();
GrantedUser gu = new GrantedUser();
gu.setUser("sochoa");
gu.setPermissions(Permission.ALL_GRANTS);
guList.add(gu);
List<GrantedRole> grList = new ArrayList<>();
GrantedRole gr = new GrantedRole();
gr.setRole("ROLE_TEST");
gr.setPermissions(Permission.READ | Permission.WRITE);
grList.add(gr);
ChangeSecurity cs = new ChangeSecurity();
cs.setGrantedUsersList(guList);
cs.setGrantedRolesList(grList);
cs.setRecursive(true);
ws.auth.changeSecurity("4f873d10-654e-4d99-a94f-15466e30a0f6", cs);
} catch (Exception e) {
e.printStackTrace();
}
}
}

Description:

Method Return values Description
overwriteSecurity(String uuid, ChangeSecurity changeSecurity) void Overwrites the security of a node.

Example:

package com.openkm;
import com.openkm.sdk4j.OKMWebservicesFactory;
import com.openkm.sdk4j.bean.*;
import com.openkm.sdk4j.impl.OKMWebservices;
import java.util.ArrayList;
import java.util.List;
public class Test {
public static void main(String[] args) {
String host = "http://localhost:8080/openkm";
String user = "okmAdmin";
String password = "admin";
OKMWebservices ws = OKMWebservicesFactory.getInstance(host);
try {
ws.login(user, password);
List<GrantedUser> guList = new ArrayList<>();
GrantedUser gu = new GrantedUser();
gu.setUser("sochoa");
gu.setPermissions(Permission.ALL_GRANTS);
guList.add(gu);
List<GrantedRole> grList = new ArrayList<>();
GrantedRole gr = new GrantedRole();
gr.setRole("ROLE_TEST");
gr.setPermissions(Permission.READ | Permission.WRITE);
grList.add(gr);
ChangeSecurity cs = new ChangeSecurity();
cs.setGrantedUsersList(guList);
cs.setGrantedRolesList(grList);
cs.setRecursive(true);
ws.auth.overwriteSecurity("4f873d10-654e-4d99-a94f-15466e30a0f6", cs);
} catch (Exception e) {
e.printStackTrace();
}
}
}

Description:

Method Return values Description
getSessionId() String Gets the HTTP session ID.

Example:

package com.openkm;
import com.openkm.sdk4j.OKMWebservicesFactory;
import com.openkm.sdk4j.impl.OKMWebservices;
public class Test {
public static void main(String[] args) {
String host = "http://localhost:8080/openkm";
String user = "okmAdmin";
String password = "admin";
OKMWebservices ws = OKMWebservicesFactory.getInstance(host);
try {
ws.login(user, password);
System.out.println(ws.auth.getSessionId());
} catch (Exception e) {
e.printStackTrace();
}
}
}

Description:

Method Return values Description
createUser(String userId, String password, String email, String name, boolean active) void Create a new user.

Example:

package com.openkm;
import com.openkm.sdk4j.OKMWebservicesFactory;
import com.openkm.sdk4j.impl.OKMWebservices;
public class Test {
public static void main(String[] args) {
String host = "http://localhost:8080/openkm";
String user = "okmAdmin";
String password = "admin";
OKMWebservices ws = OKMWebservicesFactory.getInstance(host);
try {
ws.login(user, password);
ws.auth.createUser("test", "password.2016", "test@mail.com", "User test", true);
} catch (Exception e) {
e.printStackTrace();
}
}
}

Description:

Method Return values Description
deleteUser(String userId) void Deletes a user.

Example:

package com.openkm;
import com.openkm.sdk4j.OKMWebservicesFactory;
import com.openkm.sdk4j.impl.OKMWebservices;
public class Test {
public static void main(String[] args) {
String host = "http://localhost:8080/openkm";
String user = "okmAdmin";
String password = "admin";
OKMWebservices ws = OKMWebservicesFactory.getInstance(host);
try {
ws.login(user, password);
ws.auth.deleteUser("test");
} catch (Exception e) {
e.printStackTrace();
}
}
}

Description:

Method Return values Description
updateUser(String userId, String password, String email, String name, boolean active) void Updates a user.

Example:

package com.openkm;
import com.openkm.sdk4j.OKMWebservicesFactory;
import com.openkm.sdk4j.impl.OKMWebservices;
public class Test {
public static void main(String[] args) {
String host = "http://localhost:8080/openkm";
String user = "okmAdmin";
String password = "admin";
OKMWebservices ws = OKMWebservicesFactory.getInstance(host);
try {
ws.login(user, password);
ws.auth.updateUser("test", "newpassword", "test@mail.com", "Test", false);
} catch (Exception e) {
e.printStackTrace();
}
}
}

Description:

Method Return values Description
createRole(String roleId, boolean active) void Create a new role.

Example:

package com.openkm;
import com.openkm.sdk4j.OKMWebservicesFactory;
import com.openkm.sdk4j.impl.OKMWebservices;
public class Test {
public static void main(String[] args) {
String host = "http://localhost:8080/openkm";
String user = "okmAdmin";
String password = "admin";
OKMWebservices ws = OKMWebservicesFactory.getInstance(host);
try {
ws.login(user, password);
ws.auth.createRole("ROLE_TEST", true);
} catch (Exception e) {
e.printStackTrace();
}
}
}

Description:

Method Return values Description
deleteRole(String roleId) void Deletes a role.

Example:

package com.openkm;
import com.openkm.sdk4j.OKMWebservicesFactory;
import com.openkm.sdk4j.impl.OKMWebservices;
public class Test {
public static void main(String[] args) {
String host = "http://localhost:8080/openkm";
String user = "okmAdmin";
String password = "admin";
OKMWebservices ws = OKMWebservicesFactory.getInstance(host);
try {
ws.login(user, password);
ws.auth.deleteRole("ROLE_TEST");
} catch (Exception e) {
e.printStackTrace();
}
}
}

Description:

Method Return values Description
updateRole(String roleId, boolean active) void Updates a role.

Example:

package com.openkm;
import com.openkm.sdk4j.OKMWebservicesFactory;
import com.openkm.sdk4j.impl.OKMWebservices;
public class Test {
public static void main(String[] args) {
String host = "http://localhost:8080/openkm";
String user = "okmAdmin";
String password = "admin";
OKMWebservices ws = OKMWebservicesFactory.getInstance(host);
try {
ws.login(user, password);
ws.auth.updateRole("ROLE_TEST", true);
} catch (Exception e) {
e.printStackTrace();
}
}
}

Description:

Method Return values Description
assignRole(String userId, String roleId) void Assigns a role to a user.

Example:

package com.openkm;
import com.openkm.sdk4j.OKMWebservicesFactory;
import com.openkm.sdk4j.impl.OKMWebservices;
public class Test {
public static void main(String[] args) {
String host = "http://localhost:8080/openkm";
String user = "okmAdmin";
String password = "admin";
OKMWebservices ws = OKMWebservicesFactory.getInstance(host);
try {
ws.login(user, password);
ws.auth.assignRole("test", "ROLE_USER");
} catch (Exception e) {
e.printStackTrace();
}
}
}

Description:

Method Return values Description
removeRole(String userId, String roleId) void Removes a role from a user.

Example:

package com.openkm;
import com.openkm.sdk4j.OKMWebservicesFactory;
import com.openkm.sdk4j.impl.OKMWebservices;
public class Test {
public static void main(String[] args) {
String host = "http://localhost:8080/openkm";
String user = "okmAdmin";
String password = "admin";
OKMWebservices ws = OKMWebservicesFactory.getInstance(host);
try {
ws.login(user, password);
ws.auth.removeRole("test", "ROLE_USER");
} catch (Exception e) {
e.printStackTrace();
}
}
}

Description:

Method Return values Description
getProfiles(boolean filterByActive) List Returns the list of all profiles.

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

Example:

package com.openkm;
import com.openkm.sdk4j.OKMWebservicesFactory;
import com.openkm.sdk4j.bean.Profile;
import com.openkm.sdk4j.impl.OKMWebservices;
public class Test {
public static void main(String[] args) {
String host = "http://localhost:8080/openkm";
String user = "okmAdmin";
String password = "admin";
OKMWebservices ws = OKMWebservicesFactory.getInstance(host);
try {
ws.login(user, password);
for (Profile profile : ws.auth.getProfiles(true)) {
System.out.println(profile.getName());
System.out.println(profile.getActive());
System.out.println(profile.getPrfMisc());
}
} catch (Exception e) {
e.printStackTrace();
}
}
}

Description:

Method Return values Description
getUserProfile(String userId) Profile Returns the profile assigned to a user.

Example:

package com.openkm;
import com.openkm.sdk4j.OKMWebservicesFactory;
import com.openkm.sdk4j.bean.Profile;
import com.openkm.sdk4j.impl.OKMWebservices;
public class Test {
public static void main(String[] args) {
String host = "http://localhost:8080/openkm";
String user = "okmAdmin";
String password = "admin";
OKMWebservices ws = OKMWebservicesFactory.getInstance(host);
try {
ws.login(user, password);
Profile profile = ws.auth.getUserProfile("okmAdmin");
System.out.println(profile.getName());
System.out.println(profile.getActive());
System.out.println(profile.getPrfMisc());
} catch (Exception e) {
e.printStackTrace();
}
}
}

Description:

Method Return values Description
setUserProfile(String userId, long profileId) void Change the assigned profile for a user.

Example:

package com.openkm;
import com.openkm.sdk4j.OKMWebservicesFactory;
import com.openkm.sdk4j.bean.Profile;
import com.openkm.sdk4j.impl.OKMWebservices;
public class Test {
public static void main(String[] args) {
String host = "http://localhost:8080/openkm";
String user = "okmAdmin";
String password = "admin";
OKMWebservices ws = OKMWebservicesFactory.getInstance(host);
try {
ws.login(user, password);
// Set the profile named "default" to the user
for (Profile profile : ws.auth.getProfiles(true)) {
if (profile.getName().equals("default")) {
ws.auth.setUserProfile("test", profile.getId());
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
}

Description:

Method Return values Description
getUserToken(String userId) String Returns the token for a user.

Example:

package com.openkm;
import com.openkm.sdk4j.OKMWebservicesFactory;
import com.openkm.sdk4j.impl.OKMWebservices;
public class Test {
public static void main(String[] args) {
String host = "http://localhost:8080/openkm";
String user = "okmAdmin";
String password = "admin";
OKMWebservices ws = OKMWebservicesFactory.getInstance(host);
try {
ws.login(user, password);
String token = ws.auth.getUserToken("okmAdmin");
System.out.println(token);
} catch (Exception e) {
e.printStackTrace();
}
}
}

Description:

Method Return values Description
setUserPermissions(String uuid, String userId, int permissions, boolean recursive) void Updates user permissions on a node.

The ‘recursive’ parameter only applies when the uuid is a folder or a record node.

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

Example:

package com.openkm;
import com.openkm.sdk4j.OKMWebservicesFactory;
import com.openkm.sdk4j.bean.Permission;
import com.openkm.sdk4j.impl.OKMWebservices;
public class Test {
public static void main(String[] args) {
String host = "http://localhost:8080/openkm";
String user = "okmAdmin";
String password = "admin";
OKMWebservices ws = OKMWebservicesFactory.getInstance(host);
try {
ws.login(user, password);
// Update permissions of sochoa at the node but not descendants
ws.auth.setUserPermissions("3c68b3a1-c65c-4b1e-84b5-9ce2712ca573", "sochoa", Permission.READ + Permission.WRITE, false);
// Update permissions of okmAdmin at the node and descendants
ws.auth.setUserPermissions("3c68b3a1-c65c-4b1e-84b5-9ce2712ca573", "okmAdmin", Permission.ALL_GRANTS, true);
} catch (Exception e) {
e.printStackTrace();
}
}
}

Description:

Method Return values Description
setRolePermissions(String uuid, String roleId, int permissions, boolean recursive) void Updates role permissions on a node.

The ‘recursive’ parameter only applies when the uuid is a folder or a record node.

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

Example:

package com.openkm;
import com.openkm.sdk4j.OKMWebservicesFactory;
import com.openkm.sdk4j.bean.Permission;
import com.openkm.sdk4j.impl.OKMWebservices;
public class Test {
public static void main(String[] args) {
String host = "http://localhost:8080/openkm";
String user = "okmAdmin";
String password = "admin";
OKMWebservices ws = OKMWebservicesFactory.getInstance(host);
try {
ws.login(user, password);
// Update permissions of ROLE_USER at the node but not descendants
ws.auth.setRolePermissions("3c68b3a1-c65c-4b1e-84b5-9ce2712ca573", "ROLE_USER", Permission.READ + Permission.WRITE, false);
// Update permissions of ROLE_ADMIN at the node and descendants
ws.auth.setRolePermissions("3c68b3a1-c65c-4b1e-84b5-9ce2712ca573", "ROLE_ADMIN", Permission.ALL_GRANTS, true);
} catch (Exception e) {
e.printStackTrace();
}
}
}

Description:

Method Return values Description
getUserTenants() List Returns the list of all tenants.

Example:

package com.openkm;
import java.util.List;
import com.openkm.sdk4j.OKMWebservicesFactory;
import com.openkm.sdk4j.bean.Tenant;
import com.openkm.sdk4j.impl.OKMWebservices;
public class Test {
public static void main(String[] args) {
String host = "http://localhost:8080/openkm";
String user = "okmAdmin";
String password = "admin";
OKMWebservices ws = OKMWebservicesFactory.getInstance(host);
try {
ws.login(user, password);
List<Tenant> tenants = ws.auth.getUserTenants();
for (Tenant tenant : tenants) {
System.out.println(tenant);
}
} catch (Exception e) {
e.printStackTrace();
}
}
}

Description:

Method Return values Description
setUserTenant(long tenantId) void Change the assigned tenant for a user.

Example:

package com.openkm;
import com.openkm.sdk4j.OKMWebservicesFactory;
import com.openkm.sdk4j.impl.OKMWebservices;
public class Test {
public static void main(String[] args) {
String host = "http://localhost:8080/openkm";
String user = "okmAdmin";
String password = "admin";
OKMWebservices ws = OKMWebservicesFactory.getInstance(host);
try {
ws.login(user, password);
long tenantId = 1;
ws.auth.setUserTenant(tenantId);
} catch (Exception e) {
e.printStackTrace();
}
}
}

Description:

Method Return values Description
isLoginLowercase() void Returns true when the user’s login must be set in lowercase.

Example:

package com.openkm;
import com.openkm.sdk4j.OKMWebservicesFactory;
import com.openkm.sdk4j.impl.OKMWebservices;
public class Test {
public static void main(String[] args) {
String host = "http://localhost:8080/openkm";
String user = "okmAdmin";
String password = "admin";
OKMWebservices ws = OKMWebservicesFactory.getInstance(host);
try {
ws.login(user, password);
System.out.println(ws.auth.isLoginLowercase());
} catch (Exception e) {
e.printStackTrace();
}
}
}

Description:

Method Return values Description
getToken() void Gets a new authentication token.

Example:

package com.openkm;
import com.openkm.sdk4j.OKMWebservicesFactory;
import com.openkm.sdk4j.impl.OKMWebservices;
public class Test {
public static void main(String[] args) {
String host = "http://localhost:8080/openkm";
String user = "okmAdmin";
String password = "admin";
OKMWebservices ws = OKMWebservicesFactory.getInstance(host);
try {
ws.login(user, password);
ws.getToken();
} catch (Exception e) {
e.printStackTrace();
}
}
}

Description:

Method Return values Description
createPersonalAccessToken(String name, Calendar expiration) void Create a personal access authentication token

Example:

package com.openkm;
import com.openkm.sdk4j.OKMWebservicesFactory;
import com.openkm.sdk4j.impl.OKMWebservices;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.Calendar;
public class Test {
private static final Logger log = LoggerFactory.getLogger(Test.class);
public static void main(String[] args) {
String host = "http://localhost:8080/openkm";
String user = "okmAdmin";
String password = "admin";
OKMWebservices ws = OKMWebservicesFactory.getInstance(host);
try {
ws.login(user, password);
// createPersonalAccessToken
Calendar expiration = Calendar.getInstance();
expiration.set(Calendar.DAY_OF_MONTH, +10);
String personalToken = ws.auth.createPersonalAccessToken("openkm", expiration);
log.info(personalToken);
} catch (Exception e) {
log.error(e.getMessage());
}
}
}