OKMAuth

Used for managing security and users. For example, add or remove grants on a node, create or modify users, or get the profiles. 

Starting from version 8.1.14, some methods return the DbUser object instead of the old CommonUser, which has been deprecated.

Basics

The class com.openkm.bean.Permission contains permission values (READ, WRITE, etc.). You should use it in combination with methods that change or get 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.
}

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, or record).

Example of nodeId:

  • Using UUID -> "b153c4b7-3d1c-4589-bd42-0ed0f34fd338";

Also, in all methods, you'll see a parameter named "token". Because the Cron tasks are executed in the background without authentication, the methods used in this scenario might use the token parameter. From the default application execution context, you must use the "null" value, which indicates that the application must use the "user session".

In special cases, you might be "promoted to Administrator" using the "administrator token".

String systemToken = DbSessionManager.getInstance().getSystemToken();

Methods

login

Description:

MethodReturn valuesDescription

login()

void

Simulates the user UI login process.

When a user logs in from the UI, some background process creates main user nodes, like /okm:trash. Unfortunately, if the user has never logged in from the UI and logs in from the API, these nodes are still not created and will raise an error, because it is necessary to execute the login method first.

The user must be logged in before executing the method.

Example:

package com.openkm;

import com.openkm.api.OKMAuth;
import com.openkm.util.ContextWrapper;

public class Test {

    public static void main(String[] args) {
        try {
            OKMAuth okmAuth = ContextWrapper.getContext().getBean(OKMAuth.class);
            okmAuth.login();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

login

Description:

MethodReturn valuesDescription

login(String user, String pass)

String

The login process returns an authentication token.

Login tokens by default have an expiration time of 24 hours.

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

Each time the login method is executed, the login token is replaced with a new one.

When a user logs in to the application for the first time, a method is called internally that creates user-specific folders, like /okm:trash/userId, etc.

From the API point of view, this method should only be executed the first time a user accesses the API, to create the user-specific folder structure.

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

Example:

package com.openkm;

import com.openkm.api.OKMAuth;
import com.openkm.util.ContextWrapper;

public class Test {

    public static void main(String[] args) {
        try {
            OKMAuth okmAuth = ContextWrapper.getContext().getBean(OKMAuth.class);
            okmAuth.login("userId","password");
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

grantUser

Description:

MethodReturn valuesDescription

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

void

Add a user grant on 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 its descendants.

Example:

package com.openkm;

import com.openkm.api.OKMAuth;
import com.openkm.bean.Permission;
import com.openkm.util.ContextWrapper;

public class Test {

    public static void main(String[] args) {
        try {
            OKMAuth okmAuth = ContextWrapper.getContext().getBean(OKMAuth.class);
            // Add sochoa write grants at the node but not descendants
            okmAuth.grantUser(null, "b153c4b7-3d1c-4589-bd42-0ed0f34fd338", "sochoa", Permission.ALL_GRANTS, false);

            // Add all okmAdmin grants at the node and descendants
            okmAuth.grantUser(null, "b153c4b7-3d1c-4589-bd42-0ed0f34fd338", "okmAdmin", Permission.ALL_GRANTS, true);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

revokeUser

Description:

MethodReturn valuesDescription

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

void

Remove user grant on a node.

The parameter recursive only makes sense when the nodeId is a folder or a record node.

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

Example:

package com.openkm;

import com.openkm.api.OKMAuth;
import com.openkm.bean.Permission;
import com.openkm.util.ContextWrapper;

public class Test {

    public static void main(String[] args) {
        try {
            OKMAuth okmAuth = ContextWrapper.getContext().getBean(OKMAuth.class);

            // Add sochoa write grants at the node but not descendants
            okmAuth.revokeUser(null, "b153c4b7-3d1c-4589-bd42-0ed0f34fd338", "sochoa", Permission.ALL_GRANTS, false);

            // Remove all okmAdmin grants at the node and descendants
            okmAuth.revokeUser(null, "b153c4b7-3d1c-4589-bd42-0ed0f34fd338", "okmAdmin", Permission.ALL_GRANTS, true);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

getGrantedUsers

Description:

MethodReturn valuesDescription

getGrantedUsers(String token, String nodeId)

Map<String, Integer>

Returns the granted users of a node.

Example:

package com.openkm;

import java.util.Map;

import com.openkm.api.OKMAuth;
import com.openkm.util.ContextWrapper;

public class Test {

    public static void main(String[] args) {
        try {
            OKMAuth okmAuth = ContextWrapper.getContext().getBean(OKMAuth.class);

            Map<String, Integer> grants = okmAuth.getGrantedUsers(null, "b153c4b7-3d1c-4589-bd42-0ed0f34fd338");
            for (String role : grants.keySet()) {
                System.out.println(role + "->" + grants.get(role));
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

grantRole

Description:

MethodReturn valuesDescription

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

void

Add a role grant on a node.

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

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

Example:

package com.openkm;

import com.openkm.api.OKMAuth;
import com.openkm.bean.Permission;
import com.openkm.util.ContextWrapper;

public class Test {

    public static void main(String[] args) {
        try {
            OKMAuth okmAuth = ContextWrapper.getContext().getBean(OKMAuth.class);

            // Add ROLE_USER write grants at the node but not descendants
            okmAuth.grantRole(null, "b153c4b7-3d1c-4589-bd42-0ed0f34fd338", "ROLE_USER", Permission.ALL_GRANTS, false);

            // Add all ROLE_ADMIN grants to the node and descendants
            okmAuth.grantRole(null, "b153c4b7-3d1c-4589-bd42-0ed0f34fd338", "ROLE_ADMIN", Permission.ALL_GRANTS, true);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

revokeRole

Description:

MethodReturn valuesDescription

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

void

Remove role grant on a node.

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

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

Example:

package com.openkm;
import com.openkm.api.OKMAuth;
import com.openkm.bean.Permission;
import com.openkm.util.ContextWrapper;

public class Test {

    public static void main(String[] args) {
        try {
            OKMAuth okmAuth = ContextWrapper.getContext().getBean(OKMAuth.class);
            // Remove ROLE_USER write grants at the node but not descendants
            okmAuth.revokeRole(null, "b153c4b7-3d1c-4589-bd42-0ed0f34fd338", "ROLE_USER", Permission.ALL_GRANTS, false);

            // Remove all ROLE_ADMIN grants to the node and descendants
            okmAuth.revokeRole(null, "b153c4b7-3d1c-4589-bd42-0ed0f34fd338", "ROLE_ADMIN", Permission.ALL_GRANTS, true);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

getGrantedRoles

Description:

MethodReturn valuesDescription

getGrantedRoles(String token, String nodeId) 

Map<String, Integer>

Returns the granted roles of a node.

Example:

package com.openkm;

import java.util.Map;

import com.openkm.api.OKMAuth;
import com.openkm.util.ContextWrapper;

public class Test {

    public static void main(String[] args) {
        try {
            OKMAuth okmAuth = ContextWrapper.getContext().getBean(OKMAuth.class);
            Map<String, Integer> grants = okmAuth.getGrantedRoles(null, "b153c4b7-3d1c-4589-bd42-0ed0f34fd338");
            for (String role : grants.keySet()) {
                System.out.println(role + "->" + grants.get(role));
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

getUsers

Description:

MethodReturn valuesDescription

getUsers(String token) 

List<DbUser>

Returns the list of all users.

Example:

package com.openkm;

import com.openkm.api.OKMAuth;
import com.openkm.bean.DbUser;
import com.openkm.util.ContextWrapper;

public class Test {

    public static void main(String[] args) {
        try {
            OKMAuth okmAuth = ContextWrapper.getContext().getBean(OKMAuth.class);
            for (DbUser user : okmAuth.getUsers(null)) {
                System.out.println(user.getId());
                System.out.println(user.getName());
                System.out.println(user.getEmail());
                System.out.println(user.getActive());
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

getRoles

Description:

MethodReturn valuesDescription

getRoles(String token) 

List<String>

Returns the list of all roles.

Example:

package com.openkm;

import com.openkm.api.OKMAuth;
import com.openkm.util.ContextWrapper;

public class Test {

    public static void main(String[] args) {
        try {
            OKMAuth okmAuth = ContextWrapper.getContext().getBean(OKMAuth.class);
            for (String role : okmAuth.getRoles(null)) {
                System.out.println(role);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

getUsersByRole

Description:

MethodReturn valuesDescription

getUsersByRole(String token, String role)  

List<DbUser>

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

Example:

package com.openkm;

import com.openkm.api.OKMAuth;
import com.openkm.bean.DbUser;
import com.openkm.util.ContextWrapper;

public class Test {

    public static void main(String[] args) {
        try {
            OKMAuth okmAuth = ContextWrapper.getContext().getBean(OKMAuth.class);
            for (DbUser user : okmAuth.getUsersByRole(null, "ROLE_ADMIN")) {
                System.out.println(user.getId());
                System.out.println(user.getName());
                System.out.println(user.getEmail());
                System.out.println(user.getActive());
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

getRolesByUser

Description:

MethodReturn valuesDescription

getRolesByUser(String token, String user)  

List<String>

Returns the list of all roles assigned to a user.

Example:

package com.openkm;

import com.openkm.api.OKMAuth;
import com.openkm.util.ContextWrapper;

public class Test {

    public static void main(String[] args) {
        try {
            OKMAuth okmAuth = ContextWrapper.getContext().getBean(OKMAuth.class);
            for (String role : okmAuth.getRolesByUser(null, "okmAdmin")) {
                System.out.println(role);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

changeSecurity

Description:

MethodReturn valuesDescription

public void changeSecurity(String token, String nodeId, Map<String, Integer> grantUsers, Map<String, Integer> revokeUsers,
            Map<String, Integer> grantRoles, Map<String, Integer> revokeRoles, boolean recursive)

void

Change the security of a node.

Example:

package com.openkm;

import java.util.HashMap;
import java.util.Map;

import com.openkm.api.OKMAuth;
import com.openkm.bean.Permission;
import com.openkm.util.ContextWrapper;

public class Test {

    public static void main(String[] args) {
        try {
            OKMAuth okmAuth = ContextWrapper.getContext().getBean(OKMAuth.class);
            String nodeId = "b153c4b7-3d1c-4589-bd42-0ed0f34fd338";
            Map<String, Integer> grantUsers = new HashMap<>();
            Map<String, Integer> revokeUsers = new HashMap<>();
            Map<String, Integer> grantRoles = new HashMap<>();
            grantRoles.put("ROLE_TEST", Permission.READ | Permission.WRITE);
            Map<String, Integer> revokeRoles = new HashMap<>();
            okmAuth.changeSecurity(null, nodeId, grantUsers, revokeUsers, grantRoles, revokeRoles, false);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

overwriteSecurity

Description:

MethodReturn valuesDescription

public void overwriteSecurity(String token, String nodeId, Map<String, Integer> grantUsers, 
            Map<String, Integer> grantRoles,  boolean recursive)

void

Overwrite the security of a node.

Example:

package com.openkm;

import java.util.HashMap;
import java.util.Map;

import com.openkm.api.OKMAuth;
import com.openkm.bean.Permission;
import com.openkm.util.ContextWrapper;

public class Test {

    public static void main(String[] args) {
        try {
            OKMAuth okmAuth = ContextWrapper.getContext().getBean(OKMAuth.class);
            String nodeId = "b153c4b7-3d1c-4589-bd42-0ed0f34fd338";
            Map<String, Integer> grantUsers = new HashMap<>();
            Map<String, Integer> grantRoles = new HashMap<>();
            grantRoles.put("ROLE_TEST", Permission.READ | Permission.WRITE);
            okmAuth.overwriteSecurity(null, nodeId, grantUsers, grantRoles, false);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

createUser

Description:

MethodReturn valuesDescription

createUser(String token, User user) 

void

Create a new user.

Example:

package com.openkm;

import com.openkm.api.OKMAuth;
import com.openkm.bean.User;
import com.openkm.util.ContextWrapper;

public class Test {

    public static void main(String[] args) {
        try {
            OKMAuth okmAuth = ContextWrapper.getContext().getBean(OKMAuth.class);
            User user = new User();
            user.setId("test");
            user.setPassword("password.2019");
            user.setEmail("some@mail.com");
            user.setName("User Name");
            user.setActive(true);
            okmAuth.createUser(null, user);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

deleteUser

Description:

MethodReturn valuesDescription

deleteUser(String token, String user) 

void

Delete a user.

Example:

package com.openkm;

import com.openkm.api.OKMAuth;
import com.openkm.util.ContextWrapper;

public class Test {

    public static void main(String[] args) {
        try {
            OKMAuth okmAuth = ContextWrapper.getContext().getBean(OKMAuth.class);
            okmAuth.deleteUser(null, "test");
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

updateUser

Description:

MethodReturn valuesDescription

updateUser(String token, User user) 

void

Update a user.

Example:

package com.openkm;

import com.openkm.api.OKMAuth;
import com.openkm.bean.User;
import com.openkm.util.ContextWrapper;

public class Test {

    public static void main(String[] args) {
        try {
            OKMAuth okmAuth = ContextWrapper.getContext().getBean(OKMAuth.class);
            User user = new User();
            user.setId("test");
            user.setPassword("newpassword");
            user.setEmail("some@mail.com");
            user.setName("Test");
            user.setActive(false);
            okmAuth.updateUser(null, user);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

createRole

Description:

MethodReturn valuesDescription

createRole(String token, Role role) 

void

Create a new role.

Example:

package com.openkm;

import com.openkm.api.OKMAuth;
import com.openkm.bean.Role;
import com.openkm.util.ContextWrapper;

public class Test {

    public static void main(String[] args) {
        try {
            OKMAuth okmAuth = ContextWrapper.getContext().getBean(OKMAuth.class);
            Role role = new Role();
            role.setId("ROLE_TEST");
            role.setActive(true);
            okmAuth.createRole(null, role);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

deleteRole

Description:

MethodReturn valuesDescription

deleteRole(String token, String role) 

void

Delete a role.

Example:

package com.openkm;

import com.openkm.api.OKMAuth;
import com.openkm.util.ContextWrapper;

public class Test {

    public static void main(String[] args) {
        try {
            OKMAuth okmAuth = ContextWrapper.getContext().getBean(OKMAuth.class);
            okmAuth.deleteRole(null, "ROLE_TEST");
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

updateRole

Description:

MethodReturn valuesDescription

updateRole(String token, String role, boolean active) 

void

Update a role.

Example:

package com.openkm;

import com.openkm.api.OKMAuth;

public class Test {
    public static void main(String[] args) {
        try {
            OKMAuth.getInstance().updateRole(null, "ROLE_TEST",true);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

assignRole

Description:

MethodReturn valuesDescription

assignRole(String token, String user, String role) 

void

Assign a role to a user.

Example:

package com.openkm;

import com.openkm.api.OKMAuth;
import com.openkm.util.ContextWrapper;

public class Test {

    public static void main(String[] args) {
        try {
            OKMAuth okmAuth = ContextWrapper.getContext().getBean(OKMAuth.class);
            okmAuth.assignRole(null, "test", "ROLE_USER");
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

removeRole

Description:

MethodReturn valuesDescription

removeRole(String token, String user, String role) 

void

Remove a role from a user.

Example:

package com.openkm;

import com.openkm.api.OKMAuth;
import com.openkm.util.ContextWrapper;

public class Test {

    public static void main(String[] args) {
        try {
            OKMAuth okmAuth = ContextWrapper.getContext().getBean(OKMAuth.class);
            okmAuth.removeRole(null, "test", "ROLE_USER");
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

getProfiles

Description:

MethodReturn valuesDescription

getProfiles(String token, boolean filterByActive)  

List<Profile>

Returns the list of all profiles.

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

Each user is assigned one profile that enables more or fewer of the OpenKM UI features.

Example:

package com.openkm;

import com.openkm.api.OKMAuth;
import com.openkm.db.bean.Profile;
import com.openkm.util.ContextWrapper;

public class Test {

    public static void main(String[] args) {
        try {
            OKMAuth okmAuth = ContextWrapper.getContext().getBean(OKMAuth.class);
            for (Profile profile : okmAuth.getProfiles(null, true)) {
                System.out.println(profile);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

getUserProfile

Description:

MethodReturn valuesDescription

getUserProfile(String token, String userId) 

Profile

Returns the profile assigned to a user.

Each user is assigned one profile that enables more or fewer of the OpenKM UI features.

Example:

package com.openkm;

import com.openkm.api.OKMAuth;
import com.openkm.util.ContextWrapper;

public class Test {

    public static void main(String[] args) {
        try {
            OKMAuth okmAuth = ContextWrapper.getContext().getBean(OKMAuth.class);
            System.out.println(okmAuth.getUserProfile(null, "okmAdmin"));
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

setUserProfile

Description:

MethodReturn valuesDescription

setUserProfile(String token, String userId, long profileId) 

void

Change the profile assigned to a user.

Each user is assigned one profile that enables more or fewer of the OpenKM UI features.

Example:

package com.openkm;

import com.openkm.api.OKMAuth;
import com.openkm.db.bean.Profile;
import com.openkm.util.ContextWrapper;

public class Test {

    public static void main(String[] args) {
        try {
            OKMAuth okmAuth = ContextWrapper.getContext().getBean(OKMAuth.class);
            // Set the profile named "default" to the user
            for (Profile profile : okmAuth.getProfiles(null, true)) {
                if (profile.getName().equals("default")) {
                    okmAuth.setUserProfile(null, "okmAdmin", profile.getId());
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

 

logout

Description:

MethodReturn valuesDescription

logout()

void

Executes the logout method on the OpenKM side.

Example:

package com.openkm;

import com.openkm.api.OKMAuth;
import com.openkm.util.ContextWrapper;

public class Test {

    public static void main(String[] args) {
        try {
            OKMAuth okmAuth = ContextWrapper.getContext().getBean(OKMAuth.class);
            okmAuth.logout(null);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

getUser

Description:

MethodReturn valuesDescription

getUser(String token, String userId)

DbUser

Returns user data.

Example:

package com.openkm;

import com.openkm.api.OKMAuth;
import com.openkm.bean.DbUser;
import com.openkm.util.ContextWrapper;

public class Test {

    public static void main(String[] args) {
        try {
            OKMAuth okmAuth = ContextWrapper.getContext().getBean(OKMAuth.class);
            DbUser commonUser = okmAuth.getUser(null, "okmAdmin");
            System.out.print(commonUser);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

setUserPermissions

Description:

MethodReturn valuesDescription

public void setUserPermissions(String token, String nodeId, String user, int permissions, boolean recursive)

void

Update 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 changes will be applied to the node and descendants.

Example:

package com.openkm;

import com.openkm.api.OKMAuth;
import com.openkm.bean.Permission;
import com.openkm.util.ContextWrapper;

public class Test {

    public static void main(String[] args) {
        try {
            OKMAuth okmAuth = ContextWrapper.getContext().getBean(OKMAuth.class);
            // Update permissions of sochoa at the node but not descendants
            okmAuth.setUserPermissions(null, "3c68b3a1-c65c-4b1e-84b5-9ce2712ca573", "sochoa", Permission.READ + Permission.WRITE, false);

            // Update permissions of okmAdmin at the node and descendants
            okmAuth.setUserPermissions(null, "3c68b3a1-c65c-4b1e-84b5-9ce2712ca573", "okmAdmin", Permission.ALL_GRANTS, true);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

setRolePermissions

Description:

MethodReturn valuesDescription

setRolePermissions(String token, String nodeId, String role, int permissions, boolean recursive)

void

Update 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 changes will be applied to the node and descendants.

Example:

package com.openkm;

import com.openkm.api.OKMAuth;
import com.openkm.bean.Permission;
import com.openkm.util.ContextWrapper;

public class Test {

    public static void main(String[] args) {
        try {
            OKMAuth okmAuth = ContextWrapper.getContext().getBean(OKMAuth.class);
            // Update permissions of ROLE_USER at the node but not descendants
            okmAuth.setRolePermissions(null, "3c68b3a1-c65c-4b1e-84b5-9ce2712ca573", "ROLE_USER", Permission.READ + Permission.WRITE, false);

            // Update permissions of ROLE_ADMIN at the node and descendants
            okmAuth.setRolePermissions(null, "3c68b3a1-c65c-4b1e-84b5-9ce2712ca573", "ROLE_ADMIN", Permission.ALL_GRANTS, true);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

getUserTenants

Description:

MethodReturn valuesDescription

getUserTenants(String token)

List<Tenant>

Returns the list of all tenants to which the user has access.

Example:

package com.openkm;

import java.util.List;

import com.openkm.api.OKMAuth;
import com.openkm.db.bean.Tenant;
import com.openkm.util.ContextWrapper;

public class Test {

    public static void main(String[] args) {
        try {
            OKMAuth okmAuth = ContextWrapper.getContext().getBean(OKMAuth.class);

            List<Tenant> tenants = okmAuth.getUserTenants(null);
            for (Tenant tenant : tenants) {
                System.out.println(tenant);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

setUserTenant

Description:

MethodReturn valuesDescription

setUserTenant(String token,  long tenantId)

void

Change the tenant assigned to a user.

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

Example:

package com.openkm;

import com.openkm.api.OKMAuth;
import com.openkm.util.ContextWrapper;

public class Test {

    public static void main(String[] args) {
        try {
            OKMAuth okmAuth = ContextWrapper.getContext().getBean(OKMAuth.class);

            long tenantId = 1;
            okmAuth.setUserTenant(null, tenantId);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

isPasswordExpired

Description:

MethodReturn valuesDescription

isPasswordExpired(String token)

Boolean

Checks if the user's password has expired.

Example:

package com.openkm;

import com.openkm.api.OKMAuth;
import com.openkm.util.ContextWrapper;

public class Test {

    public static void main(String[] args) {
        try {
            OKMAuth okmAuth = ContextWrapper.getContext().getBean(OKMAuth.class);

            Boolean isExpired = okmAuth.isPasswordExpired(null);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

resetPassword

Description:

MethodReturn valuesDescription

resetPassword(String userId)

void

Sends an email with a link that, if the user clicks it, will reset the password.

Example:

package com.openkm;

import com.openkm.api.OKMAuth;
import com.openkm.util.ContextWrapper;

public class Test {

    public static void main(String[] args) {
        try {
            OKMAuth okmAuth = ContextWrapper.getContext().getBean(OKMAuth.class);

            String userId = "okmAdmin";
            okmAuth.resetPassword(userId);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}