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
During a YouTrack issue import, OneDev sets up the target project at the given path. If the project already exists, the importing user must have management (admin) privilege over that existing project; otherwise an UnauthorizedException is thrown and the import is aborted. This prevents users from hijacking/overwriting projects they don't control.
Source
Thrown at server-plugin/server-plugin-import-youtrack/src/main/java/io/onedev/server/plugin/imports/youtrack/ImportServer.java:1083
youTrackProjectIds.put(projectName, projectNode.get("id").asText());
youTrackProjectDescriptions.put(projectName, projectNode.get("description").asText(null));
}
ImportResult result = new ImportResult();
for (var youTrackProject : projects.getImportProjects()) {
OneDev.getInstance(TransactionService.class).run(() -> {
String oneDevProjectPath = youTrackProject;
if (projects.getParentOneDevProject() != null)
oneDevProjectPath = projects.getParentOneDevProject() + "/" + oneDevProjectPath;
logger.log("Importing from '" + youTrackProject + "' 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");
}
String youTrackProjectId = youTrackProjectIds.get(youTrackProject);
if (youTrackProjectId == null)
throw new ExplicitException("Unable to find YouTrack project: " + youTrackProject);
project.setDescription(youTrackProjectDescriptions.get(youTrackProject));
project.setIssueManagement(true);
if (!dryRun && project.isNew()) {
projectService.create(SecurityUtils.getUser(), project);
OneDev.getInstance(AuditService.class).audit(project, "created project", null, VersionedXmlDoc.fromBean(project).toXML());
}
logger.log("Importing issues...");
ImportResult currentResult = doImportIssues(youTrackProjectId, project,
option, dryRun, logger);View on GitHub (pinned to d44925c47c)
Solutions
- Choose a target project path that does not exist yet so a new project is created.
- Ask a project admin to grant your account Manage privilege on the existing target project (Project -> People -> add with 'Manage Project').
- Have a user with management privilege over the target project run the import instead.
- Delete or rename the conflicting existing project if it is stale.
Example fix
// before: import as user without manage privilege into existing path // target: myteam/existing-project // after: grant manage role, or use a fresh path targetPath = "myteam/existing-project-imported";
Defensive patterns
Strategy: validation
Validate before calling
// before importing, check target project state and privilege
Project p = OneDev.getInstance(ProjectService.class).setup(subject, targetPath);
if (!p.isNew() && !SecurityUtils.canManageProject(p)) {
throw new IllegalStateException("Need manage privilege over existing project " + targetPath);
} Try / catch
try {
importServer.run(spec);
} catch (UnauthorizedException e) {
log.error("Insufficient privilege on import target: {}", e.getMessage());
} Prevention
- Verify your account has Manage Project on the target before starting an import into an existing path.
- Prefer a fresh, non-existent target path for imports.
- Re-run imports with the same user that created the target project.
When it happens
Trigger: Running the YouTrack import targeting an oneDev project path that already exists (project.isNew() == false) while the current subject lacks canManageProject(project) — i.e. projectService.setup() returned an existing project not managed by the user.
Common situations: Re-running an import into a project path created earlier (possibly by another user); importing into an existing project where the user is a regular member or read-only; admin configured the import spec but a non-admin executes it.
Understand the failure class
Background: "You do not have permission" / 403 Forbidden errors: authenticated but not allowed — causes and fixes across open-source libraries — this error's family across 31 libraries.
Related errors
- Import target already exists. You need to have project manag
- Unable to import build spec (import project: {0}, import rev
- Code read permission is required to import build spec (impor
- Malformed build spec (import project: {0}, import revision:
- Build spec not defined (import project: {0}, import revision
AI-assisted analysis of theonedev/onedev@d44925c47c (2026-09-06).
Data as JSON: /api/errors/a0256ecd8a3d9129.
Report an issue: GitHub.