cancel
Showing results for 
Search instead for 
Did you mean: 

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

rg1_
Star Contributor
Star Contributor

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?

1 ACCEPTED ANSWER

Florent_Guillau
World-Class Innovator
World-Class Innovator

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).

View answer in original post

7 REPLIES 7

adam_bo_
Star Contributor
Star Contributor

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 = repository.open();
}
if (session == null) {
    log.error("session is null, exit connect");
}

rg1_
Star Contributor
Star Contributor

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.

Florent_Guillau
World-Class Innovator
World-Class Innovator

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).

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.