mirror of
https://github.com/casdoor/casdoor.git
synced 2025-05-22 18:25:47 +08:00

* fix: add response when web file not found The error flow is as follows: Assuming my directory structure is as follows: ```tree ├── GitHub │ ├── casdoor # code repository ├── casdoor # compiled binary file ``` Execute the program in the `GitHub` directory: ```bash ./casdoor/casdoor ``` The working directory at this time is `GitHub`. According to the code: ```go func StaticFilter(ctx *context.Context) { urlPath := ctx.Request.URL.Path /// omitted path := "web/build" if urlPath == "/" { path += "/index.html" } else { path += urlPath } if !util.FileExist(path) { path = "web/build/index.html" } if !util.FileExist(path) { return } /// omitted } ``` If the user accesses `/`, according to this code, the returned value is actually `web/build/index.html`. But the current directory is GitHub, and there is no `web/build/index.html` file. According to the following code, it will directly return: ```go if !util.FileExist(path) { return } ``` Then in `main.go`: ```go beego.InsertFilter("*", beego.BeforeRouter, routers.StaticFilter) beego.InsertFilter("*", beego.BeforeRouter, routers.AutoSigninFilter) beego.InsertFilter("*", beego.BeforeRouter, routers.CorsFilter) beego.InsertFilter("*", beego.BeforeRouter, routers.ApiFilter) beego.InsertFilter("*", beego.BeforeRouter, routers.PrometheusFilter) beego.InsertFilter("*", beego.BeforeRouter, routers.RecordMessage) ``` The introduction of `beego.InsertFilter` is as follows: ``` func InsertFilter(pattern string, pos int, filter FilterFunc, params ...bool) *App InsertFilter adds a FilterFunc with pattern condition and action constant. The pos means action constant including beego.BeforeStatic, beego.BeforeRouter, beego.BeforeExec, beego.AfterExec and beego.FinishRouter. The bool params is for setting the returnOnOutput value (false allows multiple filters to execute) ``` When the `params` parameter is `false`, it runs multiple filters. The default is `true`. So normally, if ```go beego.InsertFilter("*", beego.BeforeRouter, routers.StaticFilter) ``` response something, the following filters will not be executed. But because the file does not exist, the function directly returns, causing the subsequent filters to continue executing. When it reaches ```go beego.InsertFilter("*", beego.BeforeRouter, routers.ApiFilter) ``` it will start to check permissions: ``` subOwner = anonymous, subName = anonymous, method = GET, urlPath = /login, obj.Owner = , obj.Name = , result = deny ``` Then it will report this error: ```json { "status": "error", "msg": "Unauthorized operation", "data": null, "data2": null } ``` The solution should be: ```go func StaticFilter(ctx *context.Context) { urlPath := ctx.Request.URL.Path /// omitted path := "web/build" if urlPath == "/" { path += "/index.html" } else { path += urlPath } if !util.FileExist(path) { // todo: response error: page not found return } /// omitted } ``` * Update static_filter.go --------- Co-authored-by: hsluoyz <hsluoyz@qq.com>
📦⚡️ Casdoor
A UI-first centralized authentication / Single-Sign-On (SSO) platform based on OAuth 2.0 / OIDC.
Online demo
- Read-only site: https://door.casdoor.com (any modification operation will fail)
- Writable site: https://demo.casdoor.com (original data will be restored for every 5 minutes)
Documentation
Install
- By source code: https://casdoor.org/docs/basic/server-installation
- By Docker: https://casdoor.org/docs/basic/try-with-docker
How to connect to Casdoor?
https://casdoor.org/docs/how-to-connect/overview
Casdoor Public API
Integrations
https://casdoor.org/docs/category/integrations
How to contact?
- Discord: https://discord.gg/5rPsrAzK7S
- Forum: https://forum.casbin.com
- Contact: https://tawk.to/chat/623352fea34c2456412b8c51/1fuc7od6e
Contribute
For casdoor, if you have any questions, you can give Issues, or you can also directly start Pull Requests(but we recommend giving issues first to communicate with the community).
I18n translation
If you are contributing to casdoor, please note that we use Crowdin as translating platform and i18next as translating tool. When you add some words using i18next in the web/
directory, please remember to add what you have added to the web/src/locales/en/data.json
file.
License
Description
An open-source UI-first Identity and Access Management (IAM) / Single-Sign-On (SSO) platform with web UI supporting OAuth 2.0, OIDC, SAML, CAS, LDAP, SCIM, WebAuthn, TOTP, MFA, Face ID, RADIUS, Google Workspace, Active Directory and Kerberos
Readme
Apache-2.0
67 MiB
Languages
Go
98.9%
HTML
0.4%
Makefile
0.3%
Less
0.2%
Dockerfile
0.1%