[opencms-dev] Guidance on storing Klaro cookie-consent decisions in OpenCms database (Master’s thesis)
Michael Emmerich
m.emmerich at alkacon.com
Thu Sep 11 10:57:54 CEST 2025
Hello Zoya,
so if I understand you correctly, you want to store information for
users that have been logged in your OpenCms.
As I do not know how much experience you have with OpenCms, I do not
know if all of the concepts I will mention are known to you.
Then, the easiest way to do this is to simply store this information at
the users directly in the so called "additionalInfo".
AdditionalInfos are key value pairs where the key is a String and the
value is any Java Object, but preferable this is a String as well. You
can see all additional info of a user in the User Management App in
OpenCms vita the context menu of a user ("Additional Infos"). You could
also wire a small jsp that loops over all users and get get all or
certain addotionalInfo from them.
Here is a little code example how to set them:
[...]
CmsUser myuser = cms.getRequestContext().getCurrentUser();
String cookieInfo = "This is the cookieinformation that should be stored
at the user";
myuser.setAdditionalInfo("cookieinfo", cookieInfo);
adminCms.writeUser(myuser);
[...]
"cms" is the current CmsObject of your request which is initalized with
the user where you want to store the information
As normal users cannot write user object for security reasons, you need
an "adminCms" CmsObject with admin roles to write the user back to the
database. Such an CmsObject could be obtained by a own module action
class that would be registered in a custom module.
If you want to write back the data in you own, custom db, i would
suggest that you create a new table in the OpenCms database for this.
You then could use the OpenCms connection pools to store the data. The
general idea would be like this:
[...]
String myQuery ="INSERT INTO Mytable (ValA, ValB, ValC) VALUES
(?,?,?)";
Connection conn = null;
PreparedStatement stmt = null;
try {
conn = OpenCms.getSqlManager().getConnection("default");
stmt = conn.prepareStatement(myQuery);
stmt.setString(1, value1);
stmt.setString(2, value2);
stmt.setString(3, value3);
stmt.executeUpdate();
} catch (SQLException e) {
// add some error logging
} finally {
// close statement and connection
}
[...]
"myQuery" is a simply insert quewry for three values to be inserted in
the table "Mytable"
conn is of the type java.sql.Connection
stmt is of the type java.sql.PreparedStatement
This code uses the connection pool "default", so the ony you normally
use to connect to your OpenCms database
value1-value3 are three strings that contain data that is stored in the db.
I hope this give some ideas how you could proceed with storing the data.
Kind regards,
Michael
Am 10.09.25 um 13:28 schrieb zoya asadi:
> Dear OpenCms team,
>
> Thanks for your reply.
>
> I’m using OpenCms for my Master’s thesis and have customized it into a website called Open Library. I evaluate the site both as an admin and as a user. For my research, I want to model the login-to-logout journey as a graph and run graph algorithms on it.
>
> To do this, I need to know if it’s possible to store which cookies the user approved in a database after they log in (for consistency and analysis). For anonymous visitors, client-side storage is fine.
>
> Kind regards,
> Zoya Asadi
> M.Sc. student, University of Passau
>
>
--
Michael Emmerich
-------------------
Alkacon Software GmbH & Co. KG - The OpenCms Experts
http://www.alkacon.com
http://www.opencms.org
More information about the opencms-dev
mailing list