PrincipalUtils

Utility methods for retrieving information from the security context. For example, get the actual userId from the security context session or get the actual tenant of the logged-in user.

Methods

getUser

Description:

MethodReturn valuesDescription

getUser()

String

Get the userId of the logged-in user.

The user must be logged in before executing the methods.

Example:

package com.openkm;

import com.openkm.principal.PrincipalUtils;

public class Test {

    public static void main(String[] args) {
        try {
            System.out.println(PrincipalUtils.getUser());
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

getTenantId

Description:

MethodReturn valuesDescription

getTenantId()

long

Get the tenantId of the logged-in user.

The user must be logged in before executing the methods.

Example:

package com.openkm;

import com.openkm.principal.PrincipalUtils;

public class Test {

    public static void main(String[] args) {
        try {
            long tenantId = PrincipalUtils.getTenantId();
            System.out.println(tenantId);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
Table of contents [ Hide Show ]