Error 403 in kcenter preview but preview works in classical UI

Symptons

Preview work in the classical UI but from kcenter UI it is shown a 403 error in the browser console.

Cause

Database timezone and OS timezone are different. The kcenter UI use a token what expires in the next minute after creation, because a wrong timezone the token is just expired after creation.

Diagnosis

Go to Administration > Tools > Scripting and execute the next script. When the script show "Error token expired" message it means you have a wrong timezone configuration in the OS or in 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 ge 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 timezone parameter.

MySQL JBDBC 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
  •