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 GitHub repository import, the target OneDev project is set up via ProjectService.setup. If the project already exists and the current user cannot manage it, an UnauthorizedException is thrown so the import never writes into a project the user does not control.
Source
Thrown at server-plugin/server-plugin-import-github/src/main/java/io/onedev/server/plugin/imports/github/ImportServer.java:575
ProjectImportOption option, boolean dryRun, TaskLogger logger) {
Client client = newClient();
try {
Map<String, Optional<Long>> userIds = new HashMap<>();
ImportResult result = new ImportResult();
for (var gitHubRepository: repositories.getImportRepositories()) {
OneDev.getInstance(TransactionService.class).run(() -> {
try {
String oneDevProjectPath = gitHubRepository;
if (repositories.getParentOneDevProject() != null)
oneDevProjectPath = repositories.getParentOneDevProject() + "/" + oneDevProjectPath;
logger.log("Importing from '" + gitHubRepository + "' 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 apiEndpoint = getApiEndpoint("/repos/" + gitHubRepository);
JsonNode repoNode = get(client, apiEndpoint, logger);
project.setDescription(repoNode.get("description").asText(null));
project.setIssueManagement(repoNode.get("has_issues").asBoolean());
if (project.isNew() || project.getDefaultBranch() == null) {
logger.log("Cloning code...");
URIBuilder builder = new URIBuilder(repoNode.get("clone_url").asText());
builder.setUserInfo("git", getAccessToken());
SecretMasker.push(text -> Strings.CS.replace(text, getAccessToken(), "******"));
try {
if (dryRun) {
new LsRemoteCommand(builder.build().toString()).refs("HEAD").quiet(true).run();View on GitHub (pinned to d44925c47c)
Solutions
- Pick a unique target project path that does not already exist
- Get Project Management permission granted on the existing project
- Remove or archive the existing conflicting project if appropriate
- Run the import with an account that has administration rights
Example fix
// before targetProjectPath = "apps/web"; // exists, no manage rights // after targetProjectPath = "apps/web-github-import"; // or grant manage permission
Defensive patterns
Strategy: try-catch
Validate before calling
Project existing = OneDev.getInstance(ProjectManager.class).findProjectByPath(oneDevProjectPath);
if (existing != null && !SecurityUtils.canManageProject(existing))
throw new ValidationException("Cannot manage existing project: " + oneDevProjectPath); Try / catch
try { importServer.importProjects(...); } catch (UnauthorizedException e) { logger.error("{} - choose a different path or request manage privilege", e.getMessage()); } Prevention
- Pre-check target path and permissions before import
- Use unique target paths per import source
- Ensure the importing account has Project Management rights
When it happens
Trigger: Running ImportServer's importProjects for oneDevProjectPath that already exists in OneDev while the authenticated user lacks Project Management privilege on it.
Common situations: Target path already created by another team; import account with insufficient role; rerunning an import after ownership changed; path naming collisions.
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
- Import target already exists. You need to have project manag
- Access denied
- Code read permission is required to import build spec (impor
- Unable to find project to import build spec: {0}
AI-assisted analysis of theonedev/onedev@d44925c47c (2026-09-06).
Data as JSON: /api/errors/673f0085a6d0603c.
Report an issue: GitHub.