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
When importing GitLab projects, the target OneDev project is created/fetched with ProjectService.setup; if it already exists and the current user lacks manage privilege over it, an UnauthorizedException is thrown to protect the existing project from unauthorized modification.
Source
Thrown at server-plugin/server-plugin-import-gitlab/src/main/java/io/onedev/server/plugin/imports/gitlab/ImportServer.java:305
ProjectImportOption option, boolean dryRun, TaskLogger logger) {
Client client = newClient();
try {
Map<String, Optional<Long>> userIds = new HashMap<>();
ImportResult result = new ImportResult();
for (var gitLabProject: projects.getImportProjects()) {
OneDev.getInstance(TransactionService.class).run(() -> {
try {
String oneDevProjectPath = gitLabProject;
if (projects.getParentOneDevProject() != null)
oneDevProjectPath = projects.getParentOneDevProject() + "/" + oneDevProjectPath;
logger.log("Importing from '" + gitLabProject + "' 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("/projects/" + gitLabProject.replace("/", "%2F"));
JsonNode projectNode = JerseyUtils.get(client, apiEndpoint, logger);
project.setDescription(projectNode.get("description").asText(null));
project.setIssueManagement(projectNode.get("issues_enabled").asBoolean());
if (project.isNew() || project.getDefaultBranch() == null) {
logger.log("Cloning code...");
URIBuilder builder = new URIBuilder(projectNode.get("http_url_to_repo").asText());
builder.setUserInfo("git", getAccessToken());
SecretMasker.push(new SecretMasker() {
@Override
public String mask(String text) {View on GitHub (pinned to d44925c47c)
Solutions
- Use a different oneDev project path for the import
- Have an administrator grant your user Project Management privilege on the existing project
- Delete/rename the pre-existing project if it is no longer needed
- Re-run the import with appropriate credentials
Example fix
// before String oneDevProjectPath = "group/service"; // already exists // after String oneDevProjectPath = "group/service-gitlab-import";
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("No manage privilege over " + oneDevProjectPath); Try / catch
try { importServer.importProjects(...); } catch (UnauthorizedException e) { log.error("Import blocked: {}", e.getMessage()); /* pick new path or obtain permission */ } Prevention
- Validate project path uniqueness before running the import
- Grant the import account manage privileges on target namespaces
- Avoid reusing paths of projects owned by others
When it happens
Trigger: importProjects invoked with a oneDevProjectPath that already exists in OneDev while SecurityUtils.canManageProject(project) is false for the current subject.
Common situations: Importing into a project path owned by someone else; using a non-admin service account; rerunning an import whose target was recreated by another user; namespace path 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/fedaaaa7b729aceb.
Report an issue: GitHub.