How to get a CoreSession within a SecurityPolicy SQLQuery.Transformer.transform()?

I need to access the CoreSession for the Principal passed as a parameter into SQLQuery.Transformer.transform(Principal, SQLQuery). I was hoping that ((NuxeoPrincipal) principal).getModel().getCoreSession() would provide it but it is almost always null. Is there another way besides creating a new CoreSession?

0 votes

2 answers



No CoreSession is available at this level, because the query transformers are called at a lower-level API level than CoreSession (from the QueryMakers inside VCS).

1 votes

I need to access specific properties from the principal's UserProfile document from within my query transformer. Do you have a recommendation for how this would best be done?

What properties do you need to access?

My own custom properties.

The solution would be to update the Principal object directly with the properties you need at login, when the Principal is created. See how the MultiTenantUserManager does it for instance, to use another class than NuxeoPrincipalImpl.

You can use for instance the following code:

LoginContext loginContext = Framework.login();
RepositoryManager mgr = Framework.getService(RepositoryManager.class);
Repository repository = mgr.getDefaultRepository();
CoreSession session = null;
if (repository != null) {
    session =;
if (session == null) {
    log.error("session is null, exit connect");
-1 votes

I believe your code is creating a new CoreSession which I was hoping to avoid. Instead I would like to access the existing CoreSession already associated with the Principal.