public void setOriginatingUser(String originatingUser) { origUserName = originatingUser; computeHash(); }
@Override public String getActingUser() { return getOriginatingUser() == null ? getName() : getOriginatingUser(); }
/** * 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)); }
@Override public String toString() { return getName(); }
@Override public void addContributor(DocumentModel doc, Event event) { NuxeoPrincipal principal = Objects.requireNonNull(event.getContext().getPrincipal()); String principalName = principal.getName(); if (principal instanceof SystemPrincipal) { principalName = ((SystemPrincipal) principal).getActingUser(); if (SYSTEM_USERNAME.equals(principalName) && !ABOUT_TO_CREATE.equals(event.getName())) { return; } } if (doc.getPropertyValue(DUBLINCORE_CREATOR_PROPERTY) == null) { doc.setPropertyValue(DUBLINCORE_CREATOR_PROPERTY, principalName); } List<String> contributorsList = getSanitizedExistingContributors(doc); if (!contributorsList.contains(principalName)) { contributorsList.add(principalName); } doc.setPropertyValue(DUBLINCORE_CONTRIBUTORS_PROPERTY, (Serializable) contributorsList); doc.setPropertyValue(DUBLINCORE_LAST_CONTRIBUTOR_PROPERTY, principalName); }
/** * 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."); } } } }
public SystemPrincipal(String origUserName) { this.origUserName = origUserName == null ? LoginComponent.SYSTEM_USERNAME : origUserName; computeHash(); }
/** * 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