/** * 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)); }
/** * 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)); }
protected static NuxeoPrincipal getPrincipal(String username) { if (username != null) { return new UserPrincipal(username, new ArrayList<>(), false, false); } else { LoginStack.Entry entry = ClientLoginModule.getCurrentLogin(); if (entry != null) { Principal p = entry.getPrincipal(); if (p instanceof NuxeoPrincipal) { return (NuxeoPrincipal) p; } else if (LoginComponent.isSystemLogin(p)) { return new SystemPrincipal(p.getName()); } else { throw new RuntimeException("Unsupported principal: " + p.getClass()); } } else { if (Framework.isTestModeSet()) { return new SystemPrincipal(null); } else { throw new NuxeoException( "Cannot create a CoreSession outside a security context, " + " login() missing."); } } } }
/** * Returns the current logged {@link NuxeoPrincipal} from the login stack * * @since 5.6 */ public static NuxeoPrincipal getCurrentPrincipal() { LoginStack.Entry entry = getCurrentLogin(); if (entry != null) { Principal p = entry.getPrincipal(); if (p instanceof NuxeoPrincipal) { return (NuxeoPrincipal) p; } else if (LoginComponent.isSystemLogin(p)) { return new SystemPrincipal(p.getName()); } } return null; }
return new SystemPrincipal(principal.getName()); // NOSONAR