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 are changing or getting security grants.

First, you must create the webservice object:

OKMWebservices ws = OKMWebservicesFactory.getInstance(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);

At this point you can use all the Auth methods from “auth” class as is 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 Login process return 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 Login process return 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
logout() void Execute logout method in 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
getGrantedUsersAndRoles(String uuid) GrantedUsersAndRolesItem Return 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> Return 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> Return 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 Return 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:

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 Return the list of all the 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 Return 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:

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 Return 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 Return the list of all the users who have 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 Remove role grant on a node.

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

When parameter recursive 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 Remove user grant on a node.

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

When parameter recursive is true, the change will be applied to the node and 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 Add role grant on a node.

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

When parameter recursive is true, the change will be applied to the node and 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 Add user grant 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:

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 Change 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 Overwrite 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
hasSecurityRecursive() Boolean Check if the user has grants to propagate the security recursively.

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("hasSecurityRecursive = " + ws.auth.hasSecurityRecursive());
} catch (Exception e) {
e.printStackTrace();
}
}
}

Description:

Method Return values Description
hasTaskManagerAdmin() Boolean Check if the user is a member of the role task manager admin

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("hasTaskManagerAdmin = " + ws.auth.hasTaskManagerAdmin());
} catch (Exception e) {
e.printStackTrace();
}
}
}

Description:

Method Return values Description
isAdmin() Boolean Check if the authenticated user is a member of the administrators.

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("Is Administrator " + ws.auth.isAdmin());
} catch (Exception e) {
e.printStackTrace();
}
}
}

Description:

Method Return values Description
getSessionId() String Get 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 Delete 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 Update 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 Delete 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 Update 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 Assign 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 Remove 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 Return the list of all profiles.

The parameter filterByActive when enabled the method will return only the active profiles, otherwise 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 Return 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 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);
// 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 Return the token 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);
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 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:

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 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:

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 Return 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 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);
long tenantId = 1;
ws.auth.setUserTenant(tenantId);
} catch (Exception e) {
e.printStackTrace();
}
}
}

Description:

Method Return values Description
isLoginLowercase() void Return true when user is must be set in lowercase in login.

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
isPasswordExpired() void True when the password of the user has expired.

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("Password expired: " + ws.auth.isPasswordExpired());
} catch (Exception e) {
e.printStackTrace();
}
}
}

Description:

Method Return values Description
getToken() void Get 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();
}
}
}