Error 403 in kcenter preview, but the preview works in the classic UI

Symptoms

The preview works in the classic UI, but in the kcenter UI a 403 error is shown in the browser console.

Cause

The database timezone and OS timezone are different. The kcenter UI uses a token that expires one minute after creation; due to an incorrect timezone, the token is already expired immediately after creation.

Diagnosis

Go to Administration > Tools > Scripting and execute the following script. When the script shows the "Error token expired" message, it means you have an incorrect timezone configuration in the OS, the database, or in the JDBC database connection.

import com.openkm.db.service.DownloadPreviewTokenSrv;
import com.openkm.util.ContextWrapper;
import com.openkm.db.bean.DownloadPreviewToken;
import java.text.SimpleDateFormat;
import java.util.Calendar;

// Generate new token
DownloadPreviewTokenSrv downloadPreviewTokenSrv = ContextWrapper.getContext().getBean(DownloadPreviewTokenSrv.class);
String ptk = downloadPreviewTokenSrv.generateDownloadNodePreviewToken("26dbf957-9286-48e1-adf6-151718a931f8"); // replace by your own document UUID ( you will find in properties tab )
print("Preview token:" + ptk);

// Evaluate token
DownloadPreviewToken previewToken = downloadPreviewTokenSrv.findByPk(ptk);
print(previewToken.getId() + "<br/>");
print(previewToken.getUser() + "<br/>");
print(previewToken.getItem() + "<br/>");

SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String validDateString = sdf.format(previewToken.getValidUntil().getTime());
print("Valid until:" + validDateString + "<br/>");

// Current time
Calendar cal = Calendar.getInstance();
String currentDateString = sdf.format(cal.getTime());
print("Current time:" + currentDateString + "<br/>");

// Check if valid
if (previewToken.getValidUntil().after(cal)) {
    print("Valid token");
} else {
    print("Error token expired");   
} 

Resolution

  • Check your OS timezone
    These are different ways to get the timezone in Linux:

    $ date +"%Z %z"

    $ timedatectl

    $ cat /etc/timezone

  • Check your Database timezone
    In MySQL / MariaDB you can try:

    mysql> SELECT @@global.time_zone, @@session.time_zone;

    mysql> select now();

  • Check if your JDBC connection URL has a timezone parameter.

MySQL JDBC URL sample:

spring.datasource.url=jdbc:mysql://localhost:3306/okmdbFileplan?autoReconnect=true&useUnicode=true&characterEncoding=UTF8&serverTimezone=Europe/Madrid

Timezone list: https://www.php.net/manual/es/timezones.php

Properties

Properties

Date

2020-12-29

Applies to

  • Core

 

 

 

Keywords

  • 7.1.x_Pro
  •   
  • Professional
  •