/** * Opens a {@link CoreSession} for the currently logged-in user. * <p> * The session must be closed using {@link CloseableCoreSession#close}. * * @param repositoryName the repository name, or {@code null} for the default repository * @return the session * @since 5.9.3 */ public static CloseableCoreSession openCoreSession(String repositoryName) { return openCoreSession(repositoryName, getPrincipal(null)); }
/** * Opens a {@link CoreSession} for a system user. * <p> * The session must be closed using {@link CloseableCoreSession#close}. * * @param repositoryName the repository name, or {@code null} for the default repository * @return the session * @since 5.9.3 */ public static CloseableCoreSession openCoreSessionSystem(String repositoryName) { return openCoreSession(repositoryName, new SystemPrincipal(null)); }
/** * MUST ONLY BE USED IN UNIT TESTS to open a {@link CoreSession} for the given user. * <p> * The session must be closed using {@link CloseableCoreSession#close}. * * @param repositoryName the repository name, or {@code null} for the default repository * @param username the user name * @return the session * @since 5.9.3 */ public static CloseableCoreSession openCoreSession(String repositoryName, String username) { return openCoreSession(repositoryName, getPrincipal(username)); }
/** * Opens a {@link CoreSession} for a system user with an optional originating username. * <p> * The session must be closed using {@link CloseableCoreSession#close}. * * @param repositoryName the repository name, or {@code null} for the default repository * @param originatingUsername the originating username to set on the SystemPrincipal * @return the session * @since 8.1 */ public static CloseableCoreSession openCoreSessionSystem(String repositoryName, String originatingUsername) { return openCoreSession(repositoryName, new SystemPrincipal(originatingUsername)); }
private Object readResolve() throws ObjectStreamException { // we need a transaction for this boolean started = false; if (!TransactionHelper.isTransactionActiveOrMarkedRollback()) { started = TransactionHelper.startTransaction(); } try { try (CloseableCoreSession session = CoreInstance.openCoreSession(repositoryName, principal)) { referent = session.getDocument(ref); referent.detach(true); return referent; } } catch (RuntimeException cause) { InvalidObjectException error = new InvalidObjectException( "Cannot refetch " + ref + " from " + repositoryName); error.initCause(cause); throw error; } finally { if (started) { TransactionHelper.commitOrRollbackTransaction(); } } }
try (CloseableCoreSession closeableCoreSession = CoreInstance.openCoreSession(repositoryName)) { session = closeableCoreSession; run();
protected CloseableCoreSession createSession(HttpServletRequest request, String repoName) { if (request.getUserPrincipal() == null) { throw new java.lang.IllegalStateException("Not authenticated user is trying to get a core session"); } return CoreInstance.openCoreSession(repoName); }
public CloseableCoreSession openCoreSession(NuxeoPrincipal principal) { return CoreInstance.openCoreSession(getRepositoryName(), principal); }
public CloseableCoreSession openCoreSession() { return CoreInstance.openCoreSession(getRepositoryName()); }
public CloseableCoreSession openCoreSession(String username) { return CoreInstance.openCoreSession(getRepositoryName(), username); }
public CloseableCoreSession createCoreSession() { UserPrincipal principal = new UserPrincipal("Administrator", new ArrayList<>(), false, true); session = CoreInstance.openCoreSession(getRepositoryName(), principal); return (CloseableCoreSession) session; }
public void push(LoginContext lc) { Entry entry = new Entry(lc); String repositoryName; if (originalSession != null) { repositoryName = originalSession.getRepositoryName(); } else { repositoryName = null; // default repository } entry.session = CoreInstance.openCoreSession(repositoryName); currentSession = entry.session; stack.add(entry); }
protected CoreSession getRepositorySession(String repoName) { if (repoName == null || repoName.isEmpty()) { RepositoryManager rm = Framework.getService(RepositoryManager.class); repoName = rm.getDefaultRepositoryName(); } if (documentManager != null && documentManager.getRepositoryName().equals(repoName)) { return documentManager; } dedicatedSession = CoreInstance.openCoreSession(repoName); return dedicatedSession; }
/** * May be called by implementing classes to open a Use session on the repository. * <p> * It uses the set {@link #originatingUsername} to open the session. * * @since 8.1 */ public void openUserSession() { if (originatingUsername == null) { throw new IllegalStateException("Cannot open an user session without an originatingUsername"); } try { loginContext = Framework.loginAsUser(originatingUsername); } catch (LoginException e) { throw new NuxeoException(e); } session = CoreInstance.openCoreSession(repositoryName); }
public void open(Principal principal, String repositoryName, int txTimeout) throws SystemException { // Tx if (txTimeout == -1) { TransactionHelper.startTransaction(); } else { TransactionHelper.startTransaction(txTimeout); } this.tx = NuxeoContainer.getTransactionManager().getTransaction(); // Session this.session = CoreInstance.openCoreSession(repositoryName, principal); }
protected long syncLogCreationEntries(BaseLogEntryProvider provider, String repoId, String path, Boolean recurs) { provider.removeEntries(DocumentEventTypes.DOCUMENT_CREATED, path); try (CloseableCoreSession session = CoreInstance.openCoreSession(repoId)) { DocumentRef rootRef = new PathRef(path); DocumentModel root = guardedDocument(session, rootRef); long nbAddedEntries = doSyncNode(provider, session, root, recurs); log.debug("synced {} entries on {}", nbAddedEntries, path); return nbAddedEntries; } }
protected PathRef resolveUserWorkspace(CoreSession session, PathRef rootref, String username, String workspacename, int maxsize) { PathRef uwref = new PathRef(rootref, workspacename); CoreSession userSession = null; try { NuxeoPrincipal principalCaller = (NuxeoPrincipal) session.getPrincipal(); // Case when this method is called in unrestricted session (like via UserProfileService) if (principalCaller instanceof SystemPrincipal) { userSession = CoreInstance.openCoreSession(null, username); } CoreSession usedSession = userSession != null ? userSession : session; // If it is username workspace, user has Everything permission on it if (!new UnrestrictedPermissionChecker(usedSession, uwref).hasPermission()) { int digestLength = workspacename.length() / 3; // Generate new path String substring = workspacename.substring(0, workspacename.length() - digestLength); return new PathRef(rootref, substring.concat(digest(username, digestLength))); } } finally { if (userSession != null) { userSession.close(); } } return uwref; }
@Override public DocumentModelList getCreationContainers(NuxeoPrincipal principal, String docType) { DocumentModelList containers = new DocumentModelListImpl(); RepositoryManager repositoryManager = Framework.getService(RepositoryManager.class); for (String repositoryName : repositoryManager.getRepositoryNames()) { try (CloseableCoreSession session = CoreInstance.openCoreSession(repositoryName, principal)) { DocumentModelList docs = getCreationContainers(session, docType); docs.forEach(doc -> doc.detach(true)); containers.addAll(docs); } } return containers; }
protected void processBatchOfDocuments(List<String> batch) { if (batch == null || batch.isEmpty()) { return; } TransactionHelper.runInTransaction(() -> { try { LoginContext loginContext = Framework.loginAsUser(command.getUsername()); String repository = command.getRepository(); try (CloseableCoreSession session = CoreInstance.openCoreSession(repository)) { compute(session, batch, command.getParams()); } finally { loginContext.logout(); } } catch (LoginException e) { throw new NuxeoException(e); } }); }
/** * Internal connect method shared in between above connect() methods. * * @param username the user name. * @param password the user password. * @param repository the repository name. * @return a Nuxeo core session identifier. */ private String _connect(String username, String password, String repositoryName) { // Login before doing anything. login(username, password); CoreSession session = CoreInstance.openCoreSession(repositoryName); String sid = session.getSessionId(); UserManager userMgr = Framework.getService(UserManager.class); WSRemotingSession rs = new WSRemotingSessionImpl(session, userMgr, repositoryName, username, password); getSessionsManager().addSession(sid, rs); return sid; }