theonedev/onedev · error · UnauthorizedException

Import target already exists. You need to have project manag

Error message

Import target already exists. You need to have project management privilege over it

What it means

Thrown as an UnauthorizedException by the Jira Cloud import's importProjects() when the target OneDev project path already exists (ProjectService.setup returned an existing project) but the current user lacks manage privilege over that project. Importing would write content into a project the user does not control, so the operation is refused before any data is read from Jira.

Source

Thrown at server-plugin/server-plugin-import-jiracloud/src/main/java/io/onedev/server/plugin/imports/jiracloud/ImportServer.java:367

	TaskResult importProjects(ImportProjects projects, ImportOption option, boolean dryRun, TaskLogger logger) {
		Client client = newClient();
		try {
			Map<String, Optional<Long>> userIds = new HashMap<>();
			Map<String, JsonNode> projectNodes = getProjectNodes(logger);
			ImportResult result = new ImportResult();
			for (var jiraProject: projects.getImportProjects()) {
				OneDev.getInstance(TransactionService.class).run(() -> {
					String oneDevProjectPath = jiraProject;
					if (projects.getParentOneDevProject() != null)
						oneDevProjectPath = projects.getParentOneDevProject() + "/" + oneDevProjectPath;

					logger.log("Importing from '" + jiraProject + "' to '" + oneDevProjectPath + "'...");

					ProjectService projectService = OneDev.getInstance(ProjectService.class);
					Project project = projectService.setup(SecurityUtils.getSubject(), oneDevProjectPath);

					if (!project.isNew() && !SecurityUtils.canManageProject(project)) {
						throw new UnauthorizedException("Import target already exists. " +
								"You need to have project management privilege over it");
					}

					JsonNode projectNode = projectNodes.get(jiraProject);
					if (projectNode == null)
						throw new ExplicitException("Unable to find project: " + jiraProject);

					String apiEndpoint = getApiEndpoint("/project/" + projectNode.get("id").asText());

					// Get more detail project information
					projectNode = JerseyUtils.get(client, apiEndpoint, logger);

					project.setDescription(projectNode.get("description").asText(null));

					if (!dryRun && project.isNew()) {
						projectService.create(SecurityUtils.getUser(), project);
						OneDev.getInstance(AuditService.class).audit(project, "created project", null, VersionedXmlDoc.fromBean(project).toXML());
					}

View on GitHub (pinned to d44925c47c)

Solutions

  1. Grant the importing user Project Manage privilege over the existing target project, then re-run the import.
  2. Choose a different target project path in the import mapping so ProjectService.setup creates a new project the user owns.
  3. Delete or rename the conflicting existing project if it is a stale artifact from a previous import attempt.
  4. Run the import as a project/server administrator who has manage rights over the existing path.

Example fix

// before: importing into existing project without manage rights
oneDevProjectPath = "team/legacy"   // exists, user has only READ access
// after: grant manage permission or use fresh path
oneDevProjectPath = "team/legacy-import"  // new project created and owned by importer
Defensive patterns

Strategy: try-catch

Validate before calling

Project p = OneDev.getInstance(ProjectService.class).find(oneDevProjectPath);
if (p != null && !SecurityUtils.canManageProject(p))
    throw new IllegalStateException("No manage privilege over " + oneDevProjectPath);

Try / catch

try { importServer.doImport(...) } catch (UnauthorizedException e) { logger.error("Grant manage privilege or pick another target path: " + e.getMessage()); }

Prevention

When it happens

Trigger: Calling the Jira Cloud import (doImport -> importProjects) with a oneDevProjectPath that already exists in OneDev while the authenticated subject fails SecurityUtils.canManageProject(project). Happens for every Jira project mapped to an existing path without Project Manage permission.

Common situations: Re-running an import into a project created by another user or an earlier import; overlapping project path that collides with an existing project; running the import with a non-admin account that can create projects but cannot manage the pre-existing target.

Understand the failure class

Background: Permission denied / not authorized / 403 Forbidden: access-control rejections when the caller lacks the required role, grant, or ownership — this error's family across 18 libraries.

Related errors


AI-assisted analysis of theonedev/onedev@d44925c47c (2026-09-06). Data as JSON: /api/errors/1dad367adfa9deec. Report an issue: GitHub.