goharbor/harbor · error · errors.UnauthorizedError

UNAUTHORIZED

UNAUTHORIZED

Error message

security context not found

What it means

Error "security context not found" thrown in goharbor/harbor.

Source

Thrown at src/server/v2.0/handler/repository.go:75

}

func (r *repositoryAPI) Prepare(ctx context.Context, _ string, params any) middleware.Responder {
	if err := unescapePathParams(params, "RepositoryName"); err != nil {
		r.SendError(ctx, err)
	}

	return nil
}

func (r *repositoryAPI) ListAllRepositories(ctx context.Context, params operation.ListAllRepositoriesParams) middleware.Responder {
	// set query
	query, err := r.BuildQuery(ctx, params.Q, params.Sort, params.Page, params.PageSize)
	if err != nil {
		return r.SendError(ctx, err)
	}
	secCtx, ok := security.FromContext(ctx)
	if !ok {
		return r.SendError(ctx, errors.UnauthorizedError(errors.New("security context not found")))
	}
	if !secCtx.IsSysAdmin() && !secCtx.IsSolutionUser() {
		projectIDs, err := r.listAuthorizedProjectIDs(ctx)
		if err != nil {
			return r.SendError(ctx, err)
		}
		// no authorized projects, return nil directly
		if len(projectIDs) == 0 {
			return operation.NewListAllRepositoriesOK().
				WithXTotalCount(0).
				WithLink(r.Links(ctx, params.HTTPRequest.URL, 0, query.PageNumber, query.PageSize).String()).
				WithPayload(nil)
		}
		orList := &q.OrList{}
		for _, projectID := range projectIDs {
			orList.Values = append(orList.Values, projectID)
		}
		query.Keywords["ProjectID"] = orList

View on GitHub (pinned to 7b2fd08cc5)

When it happens

Trigger: Thrown at src/server/v2.0/handler/repository.go:75 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of goharbor/harbor@7b2fd08cc5 (2026-08-16). Data as JSON: /api/errors/3414f609296f40d5. Report an issue: GitHub.