{"record":{"id":"3749f3bedd2dcbab","repo":"theonedev/onedev","slug":"please-login-to-perform-this-query-3749f3","errorCode":null,"errorMessage":"\"Please login to perform this query\"","messagePattern":"\"Please login to perform this query\"","errorType":"http","errorClass":"NotAcceptableException","httpStatus":406,"severity":"error","filePath":"server-core/src/main/java/io/onedev/server/search/entity/workspace/CreatedByMeCriteria.java","lineNumber":29,"sourceCode":"import org.jspecify.annotations.Nullable;\n\nimport io.onedev.server.exception.NotAcceptableException;\nimport io.onedev.server.model.User;\nimport io.onedev.server.model.Workspace;\nimport io.onedev.server.security.SecurityUtils;\nimport io.onedev.server.util.ProjectScope;\n\npublic class CreatedByMeCriteria extends CreatedByCriteria {\n\n\tprivate static final long serialVersionUID = 1L;\n\n\t@Override\n\tpublic Predicate getPredicate(@Nullable ProjectScope projectScope, CriteriaQuery<?> query, From<Workspace, Workspace> from, CriteriaBuilder builder) {\n\t\tif (User.get() != null) {\n\t\t\tPath<User> attribute = from.get(Workspace.PROP_USER);\n\t\t\treturn builder.equal(attribute, User.get());\n\t\t} else {\n\t\t\tthrow new NotAcceptableException(_T(\"Please login to perform this query\"));\n\t\t}\n\t}\n\n\t@Override\n\tpublic User getCreator() {\n\t\treturn SecurityUtils.getUser();\n\t}\n\n\t@Override\n\tpublic boolean matches(Workspace workspace) {\n\t\tif (User.get() != null)\n\t\t\treturn User.get().equals(workspace.getUser());\n\t\telse\n\t\t\tthrow new NotAcceptableException(_T(\"Please login to perform this query\"));\n\t}\n\n\t@Override\n\tpublic String toStringWithoutParens() {","sourceCodeStart":11,"sourceCodeEnd":47,"githubUrl":"https://github.com/theonedev/onedev/blob/d44925c47c37992c828ea673a5f9620539bc3ff2/server-core/src/main/java/io/onedev/server/search/entity/workspace/CreatedByMeCriteria.java#L11-L47","documentation":"CreatedByMeCriteria.getPredicate() for workspace queries compares the workspace's user column against the current user. If User.get() is null (anonymous context), the \"me\" comparison is impossible and it throws NotAcceptableException(\"Please login to perform this query\").","triggerScenarios":"Running a workspace query containing the \"created by me\" rule via getPredicate() while unauthenticated or in a thread with no bound user.","commonSituations":"Anonymous REST queries on workspaces; automation without tokens; session loss/expiry before the query executes.","solutions":["Authenticate (web login or access token) before issuing the workspace query.","Rewrite the query as \"created by <user>\" naming the user explicitly.","Impersonate a user in server-side jobs prior to building the predicate.","Verify authentication/session setup so anonymous sessions don't reach user-relative workspace queries."],"exampleFix":"// before\nGET /~api/workspaces?query=\"created by me\" // anonymous\n\n// after\nGET /~api/workspaces?query=\"created by john\" \\\n  -H \"Authorization: Bearer <pat>\"","handlingStrategy":"try-catch","validationCode":"if (SecurityUtils.getUser() == null) { authenticate(); }","typeGuard":"var user = SecurityUtils.getUser();\nString query = user != null ? \"created by me\" : \"created by \" + explicitUser;","tryCatchPattern":"try { workspaces = queryWorkspaces(\"created by me\"); }\ncatch (NotAcceptableException e) { promptLoginThenRetry(); }","preventionTips":["Require authentication for workspace queries.","Use explicit \"created by <user>\" rules in API integrations.","Refresh expired sessions before saved-query execution.","Verify anonymous access is disabled where user-relative queries are expected."],"tags":["authentication","query","workspace"],"backgroundTag":"authentication-required","analyzedSha":"d44925c47c37992c828ea673a5f9620539bc3ff2","analyzedAt":"2026-09-06T07:18:27.995Z","contentChangedAt":"2026-09-06T07:18:27.995Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}