| @@ -53,7 +53,7 @@ | |||
| casibase contains 4 parts: | |||
| | **Name** | **Description** | **Language** | | |||
| | -------------- | ------------------------------------------------- | --------------------------------------- | | |||
| |----------------|---------------------------------------------------|-----------------------------------------| | |||
| | Frontend | User interface for the casibase application | JavaScript + React | | |||
| | Backend | Server-side logic and API for casibase | Golang + Beego + Python + Flask + MySQL | | |||
| | AI Model | Artificial intelligence model | Python + OpenAI | | |||
| @@ -112,9 +112,9 @@ Casnode uses XORM to connect to DB, so all DBs supported by XORM can also be use | |||
| - #### Backend (`casibase\conf\app.conf`) | |||
| ```ini | |||
| casdoorEndpoint = <Your_Casdoor_endpoint> | |||
| clientId = <Your_clientId_in_Casdoor_configuration> | |||
| clientSecret = <Your_clientSecret_in_Casdoor_configuration> | |||
| casdoorDbName = casdoor | |||
| casdoorOrganization = "casibase" | |||
| casdoorApplication = "app-casibase" | |||
| ``` | |||
| @@ -1,86 +0,0 @@ | |||
| // Copyright 2023 The casbin Authors. All Rights Reserved. | |||
| // | |||
| // Licensed under the Apache License, Version 2.0 (the "License"); | |||
| // you may not use this file except in compliance with the License. | |||
| // You may obtain a copy of the License at | |||
| // | |||
| // http://www.apache.org/licenses/LICENSE-2.0 | |||
| // | |||
| // Unless required by applicable law or agreed to in writing, software | |||
| // distributed under the License is distributed on an "AS IS" BASIS, | |||
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |||
| // See the License for the specific language governing permissions and | |||
| // limitations under the License. | |||
| package casdoor | |||
| import ( | |||
| "runtime" | |||
| "github.com/astaxie/beego" | |||
| _ "github.com/go-sql-driver/mysql" | |||
| "xorm.io/xorm" | |||
| ) | |||
| var adapter *Adapter | |||
| type Session struct { | |||
| SessionKey string `xorm:"char(64) notnull pk"` | |||
| SessionData []uint8 `xorm:"blob"` | |||
| SessionExpiry int `xorm:"notnull"` | |||
| } | |||
| func InitCasdoorAdapter() { | |||
| casdoorDbName := beego.AppConfig.String("casdoorDbName") | |||
| if casdoorDbName == "" { | |||
| return | |||
| } | |||
| adapter = NewAdapter(beego.AppConfig.String("driverName"), beego.AppConfig.String("dataSourceName"), beego.AppConfig.String("casdoorDbName")) | |||
| } | |||
| // Adapter represents the MySQL adapter for policy storage. | |||
| type Adapter struct { | |||
| driverName string | |||
| dataSourceName string | |||
| dbName string | |||
| Engine *xorm.Engine | |||
| } | |||
| // finalizer is the destructor for Adapter. | |||
| func finalizer(a *Adapter) { | |||
| err := a.Engine.Close() | |||
| if err != nil { | |||
| panic(err) | |||
| } | |||
| } | |||
| // NewAdapter is the constructor for Adapter. | |||
| func NewAdapter(driverName string, dataSourceName string, dbName string) *Adapter { | |||
| a := &Adapter{} | |||
| a.driverName = driverName | |||
| a.dataSourceName = dataSourceName | |||
| a.dbName = dbName | |||
| // Open the DB, create it if not existed. | |||
| a.open() | |||
| // Call the destructor when the object is released. | |||
| runtime.SetFinalizer(a, finalizer) | |||
| return a | |||
| } | |||
| func (a *Adapter) open() { | |||
| Engine, err := xorm.NewEngine(a.driverName, a.dataSourceName+a.dbName) | |||
| if err != nil { | |||
| panic(err) | |||
| } | |||
| a.Engine = Engine | |||
| } | |||
| func (a *Adapter) close() { | |||
| a.Engine.Close() | |||
| a.Engine = nil | |||
| } | |||
| @@ -1,112 +0,0 @@ | |||
| // Copyright 2023 The casbin Authors. All Rights Reserved. | |||
| // | |||
| // Licensed under the Apache License, Version 2.0 (the "License"); | |||
| // you may not use this file except in compliance with the License. | |||
| // You may obtain a copy of the License at | |||
| // | |||
| // http://www.apache.org/licenses/LICENSE-2.0 | |||
| // | |||
| // Unless required by applicable law or agreed to in writing, software | |||
| // distributed under the License is distributed on an "AS IS" BASIS, | |||
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |||
| // See the License for the specific language governing permissions and | |||
| // limitations under the License. | |||
| package casdoor | |||
| import ( | |||
| "github.com/casbin/casibase/util" | |||
| "xorm.io/core" | |||
| ) | |||
| type Permission struct { | |||
| Owner string `xorm:"varchar(100) notnull pk" json:"owner"` | |||
| Name string `xorm:"varchar(100) notnull pk" json:"name"` | |||
| CreatedTime string `xorm:"varchar(100)" json:"createdTime"` | |||
| DisplayName string `xorm:"varchar(100)" json:"displayName"` | |||
| Users []string `xorm:"mediumtext" json:"users"` | |||
| Roles []string `xorm:"mediumtext" json:"roles"` | |||
| Domains []string `xorm:"mediumtext" json:"domains"` | |||
| Model string `xorm:"varchar(100)" json:"model"` | |||
| ResourceType string `xorm:"varchar(100)" json:"resourceType"` | |||
| Resources []string `xorm:"mediumtext" json:"resources"` | |||
| Actions []string `xorm:"mediumtext" json:"actions"` | |||
| Effect string `xorm:"varchar(100)" json:"effect"` | |||
| IsEnabled bool `json:"isEnabled"` | |||
| Submitter string `xorm:"varchar(100)" json:"submitter"` | |||
| Approver string `xorm:"varchar(100)" json:"approver"` | |||
| ApproveTime string `xorm:"varchar(100)" json:"approveTime"` | |||
| State string `xorm:"varchar(100)" json:"state"` | |||
| } | |||
| func GetPermissions(owner string) ([]*Permission, error) { | |||
| permissions := []*Permission{} | |||
| err := adapter.Engine.Desc("created_time").Find(&permissions, &Permission{Owner: owner}) | |||
| if err != nil { | |||
| return permissions, err | |||
| } | |||
| return permissions, nil | |||
| } | |||
| func getPermission(owner string, name string) (*Permission, error) { | |||
| if owner == "" || name == "" { | |||
| return nil, nil | |||
| } | |||
| permission := Permission{Owner: owner, Name: name} | |||
| existed, err := adapter.Engine.Get(&permission) | |||
| if err != nil { | |||
| return &permission, err | |||
| } | |||
| if existed { | |||
| return &permission, nil | |||
| } else { | |||
| return nil, nil | |||
| } | |||
| } | |||
| func GetPermission(id string) (*Permission, error) { | |||
| owner, name := util.GetOwnerAndNameFromId(id) | |||
| return getPermission(owner, name) | |||
| } | |||
| func UpdatePermission(id string, permission *Permission) (bool, error) { | |||
| owner, name := util.GetOwnerAndNameFromId(id) | |||
| oldPermission, err := getPermission(owner, name) | |||
| if err != nil { | |||
| return false, err | |||
| } | |||
| if oldPermission == nil { | |||
| return false, nil | |||
| } | |||
| affected, err := adapter.Engine.ID(core.PK{owner, name}).AllCols().Update(permission) | |||
| if err != nil { | |||
| return false, err | |||
| } | |||
| return affected != 0, nil | |||
| } | |||
| func AddPermission(permission *Permission) (bool, error) { | |||
| affected, err := adapter.Engine.Insert(permission) | |||
| if err != nil { | |||
| return false, err | |||
| } | |||
| return affected != 0, nil | |||
| } | |||
| func DeletePermission(permission *Permission) (bool, error) { | |||
| affected, err := adapter.Engine.ID(core.PK{permission.Owner, permission.Name}).Delete(&Permission{}) | |||
| if err != nil { | |||
| return false, err | |||
| } | |||
| return affected != 0, nil | |||
| } | |||
| @@ -1,73 +0,0 @@ | |||
| // Copyright 2023 The casbin Authors. All Rights Reserved. | |||
| // | |||
| // Licensed under the Apache License, Version 2.0 (the "License"); | |||
| // you may not use this file except in compliance with the License. | |||
| // You may obtain a copy of the License at | |||
| // | |||
| // http://www.apache.org/licenses/LICENSE-2.0 | |||
| // | |||
| // Unless required by applicable law or agreed to in writing, software | |||
| // distributed under the License is distributed on an "AS IS" BASIS, | |||
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |||
| // See the License for the specific language governing permissions and | |||
| // limitations under the License. | |||
| package casdoor | |||
| type Provider struct { | |||
| Owner string `xorm:"varchar(100) notnull pk" json:"owner"` | |||
| Name string `xorm:"varchar(100) notnull pk unique" json:"name"` | |||
| CreatedTime string `xorm:"varchar(100)" json:"createdTime"` | |||
| DisplayName string `xorm:"varchar(100)" json:"displayName"` | |||
| Category string `xorm:"varchar(100)" json:"category"` | |||
| Type string `xorm:"varchar(100)" json:"type"` | |||
| SubType string `xorm:"varchar(100)" json:"subType"` | |||
| Method string `xorm:"varchar(100)" json:"method"` | |||
| ClientId string `xorm:"varchar(100)" json:"clientId"` | |||
| ClientSecret string `xorm:"varchar(2000)" json:"clientSecret"` | |||
| ClientId2 string `xorm:"varchar(100)" json:"clientId2"` | |||
| ClientSecret2 string `xorm:"varchar(100)" json:"clientSecret2"` | |||
| Cert string `xorm:"varchar(100)" json:"cert"` | |||
| CustomAuthUrl string `xorm:"varchar(200)" json:"customAuthUrl"` | |||
| CustomTokenUrl string `xorm:"varchar(200)" json:"customTokenUrl"` | |||
| CustomUserInfoUrl string `xorm:"varchar(200)" json:"customUserInfoUrl"` | |||
| CustomLogo string `xorm:"varchar(200)" json:"customLogo"` | |||
| Scopes string `xorm:"varchar(100)" json:"scopes"` | |||
| UserMapping map[string]string `xorm:"varchar(500)" json:"userMapping"` | |||
| Host string `xorm:"varchar(100)" json:"host"` | |||
| Port int `json:"port"` | |||
| DisableSsl bool `json:"disableSsl"` // If the provider type is WeChat, DisableSsl means EnableQRCode | |||
| Title string `xorm:"varchar(100)" json:"title"` | |||
| Content string `xorm:"varchar(1000)" json:"content"` // If provider type is WeChat, Content means QRCode string by Base64 encoding | |||
| Receiver string `xorm:"varchar(100)" json:"receiver"` | |||
| RegionId string `xorm:"varchar(100)" json:"regionId"` | |||
| SignName string `xorm:"varchar(100)" json:"signName"` | |||
| TemplateCode string `xorm:"varchar(100)" json:"templateCode"` | |||
| AppId string `xorm:"varchar(100)" json:"appId"` | |||
| Endpoint string `xorm:"varchar(1000)" json:"endpoint"` | |||
| IntranetEndpoint string `xorm:"varchar(100)" json:"intranetEndpoint"` | |||
| Domain string `xorm:"varchar(100)" json:"domain"` | |||
| Bucket string `xorm:"varchar(100)" json:"bucket"` | |||
| PathPrefix string `xorm:"varchar(100)" json:"pathPrefix"` | |||
| Metadata string `xorm:"mediumtext" json:"metadata"` | |||
| IdP string `xorm:"mediumtext" json:"idP"` | |||
| IssuerUrl string `xorm:"varchar(100)" json:"issuerUrl"` | |||
| EnableSignAuthnRequest bool `json:"enableSignAuthnRequest"` | |||
| ProviderUrl string `xorm:"varchar(200)" json:"providerUrl"` | |||
| } | |||
| func GetStorageProviders(owner string) ([]*Provider, error) { | |||
| providers := []*Provider{} | |||
| err := adapter.Engine.Desc("created_time").Find(&providers, &Provider{Owner: owner, Category: "Storage"}) | |||
| if err != nil { | |||
| return providers, err | |||
| } | |||
| return providers, nil | |||
| } | |||
| @@ -11,7 +11,6 @@ landingFolder = casibase-landing | |||
| casdoorEndpoint = http://localhost:8000 | |||
| clientId = af6b5aa958822fb9dc33 | |||
| clientSecret = 8bc3010c1c951c8d876b1f311a901ff8deeb93bc | |||
| casdoorDbName = casdoor | |||
| casdoorOrganization = "casbin" | |||
| casdoorApplication = "app-casibase" | |||
| cacheDir = "C:/casibase_cache" | |||
| @@ -17,13 +17,12 @@ package controllers | |||
| import ( | |||
| "encoding/json" | |||
| "github.com/casbin/casibase/casdoor" | |||
| "github.com/casbin/casibase/util" | |||
| "github.com/casdoor/casdoor-go-sdk/casdoorsdk" | |||
| ) | |||
| func (c *ApiController) GetPermissions() { | |||
| owner := c.Input().Get("owner") | |||
| permissions, err := casdoor.GetPermissions(owner) | |||
| permissions, err := casdoorsdk.GetPermissions() | |||
| if err != nil { | |||
| c.ResponseError(err.Error()) | |||
| return | |||
| @@ -34,8 +33,9 @@ func (c *ApiController) GetPermissions() { | |||
| func (c *ApiController) GetPermission() { | |||
| id := c.Input().Get("id") | |||
| _, name := util.GetOwnerAndNameFromId(id) | |||
| permission, err := casdoor.GetPermission(id) | |||
| permission, err := casdoorsdk.GetPermission(name) | |||
| if err != nil { | |||
| c.ResponseError(err.Error()) | |||
| return | |||
| @@ -45,15 +45,13 @@ func (c *ApiController) GetPermission() { | |||
| } | |||
| func (c *ApiController) UpdatePermission() { | |||
| id := c.Input().Get("id") | |||
| var permission casdoor.Permission | |||
| var permission casdoorsdk.Permission | |||
| err := json.Unmarshal(c.Ctx.Input.RequestBody, &permission) | |||
| if err != nil { | |||
| panic(err) | |||
| } | |||
| success, err := casdoor.UpdatePermission(id, &permission) | |||
| success, err := casdoorsdk.UpdatePermission(&permission) | |||
| if err != nil { | |||
| c.ResponseError(err.Error()) | |||
| return | |||
| @@ -63,14 +61,14 @@ func (c *ApiController) UpdatePermission() { | |||
| } | |||
| func (c *ApiController) AddPermission() { | |||
| var permission casdoor.Permission | |||
| var permission casdoorsdk.Permission | |||
| err := json.Unmarshal(c.Ctx.Input.RequestBody, &permission) | |||
| if err != nil { | |||
| c.ResponseError(err.Error()) | |||
| return | |||
| } | |||
| success, err := casdoor.AddPermission(&permission) | |||
| success, err := casdoorsdk.AddPermission(&permission) | |||
| if err != nil { | |||
| c.ResponseError(err.Error()) | |||
| return | |||
| @@ -80,14 +78,14 @@ func (c *ApiController) AddPermission() { | |||
| } | |||
| func (c *ApiController) DeletePermission() { | |||
| var permission casdoor.Permission | |||
| var permission casdoorsdk.Permission | |||
| err := json.Unmarshal(c.Ctx.Input.RequestBody, &permission) | |||
| if err != nil { | |||
| c.ResponseError(err.Error()) | |||
| return | |||
| } | |||
| success, err := casdoor.DeletePermission(&permission) | |||
| success, err := casdoorsdk.DeletePermission(&permission) | |||
| if err != nil { | |||
| c.ResponseError(err.Error()) | |||
| return | |||
| @@ -14,12 +14,27 @@ | |||
| package controllers | |||
| import "github.com/casbin/casibase/casdoor" | |||
| import "github.com/casdoor/casdoor-go-sdk/casdoorsdk" | |||
| func getStorageProviders() ([]*casdoorsdk.Provider, error) { | |||
| providers, err := casdoorsdk.GetProviders() | |||
| if err != nil { | |||
| return providers, err | |||
| } | |||
| res := []*casdoorsdk.Provider{} | |||
| for _, provider := range providers { | |||
| if provider.Category == "Storage" { | |||
| res = append(res, provider) | |||
| } | |||
| } | |||
| return res, nil | |||
| } | |||
| func (c *ApiController) GetStorageProviders() { | |||
| owner := c.Input().Get("owner") | |||
| // owner := c.Input().Get("owner") | |||
| providers, err := casdoor.GetStorageProviders(owner) | |||
| providers, err := getStorageProviders() | |||
| if err != nil { | |||
| c.ResponseError(err.Error()) | |||
| return | |||
| @@ -7,7 +7,7 @@ require ( | |||
| github.com/aliyun/aliyun-oss-go-sdk v2.2.2+incompatible | |||
| github.com/astaxie/beego v1.12.3 | |||
| github.com/baiyubin/aliyun-sts-go-sdk v0.0.0-20180326062324-cfa1a18b161f // indirect | |||
| github.com/casdoor/casdoor-go-sdk v0.27.0 | |||
| github.com/casdoor/casdoor-go-sdk v0.28.1 | |||
| github.com/cespare/xxhash/v2 v2.2.0 // indirect | |||
| github.com/danaugrs/go-tsne/tsne v0.0.0-20220306155740-2250969e057f | |||
| github.com/fsnotify/fsnotify v1.6.0 // indirect | |||
| @@ -86,8 +86,8 @@ github.com/boombuler/barcode v1.0.1/go.mod h1:paBWMcWSl3LHKBqUq+rly7CNSldXjb2rDl | |||
| github.com/bradfitz/gomemcache v0.0.0-20180710155616-bc664df96737/go.mod h1:PmM6Mmwb0LSuEubjR8N7PtNe1KxZLtOUHtbeikc5h60= | |||
| github.com/casbin/casbin v1.7.0/go.mod h1:c67qKN6Oum3UF5Q1+BByfFxkwKvhwW57ITjqwtzR1KE= | |||
| github.com/casbin/casbin/v2 v2.1.2/go.mod h1:YcPU1XXisHhLzuxH9coDNf2FbKpjGlbCg3n9yuLkIJQ= | |||
| github.com/casdoor/casdoor-go-sdk v0.27.0 h1:40TdcsomUxxhbtBi0huZxPZhfj+pSB8KtWkXg6Dqtk8= | |||
| github.com/casdoor/casdoor-go-sdk v0.27.0/go.mod h1:MBed3ISHQfXTtoOCAk5T8l5lt4wFvsyynrw0awggydY= | |||
| github.com/casdoor/casdoor-go-sdk v0.28.1 h1:z0b36oEsU9PzCxHlYWmRY1ZMLSnUW3MVRDv6I7hWy9E= | |||
| github.com/casdoor/casdoor-go-sdk v0.28.1/go.mod h1:MBed3ISHQfXTtoOCAk5T8l5lt4wFvsyynrw0awggydY= | |||
| github.com/cenkalti/backoff v2.2.1+incompatible/go.mod h1:90ReRw6GdpyfrHakVjL/QHaoyV4aDUVVkXQJJJ3NXXM= | |||
| github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU= | |||
| github.com/cespare/xxhash/v2 v2.1.1/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs= | |||
| @@ -18,7 +18,6 @@ import ( | |||
| "github.com/astaxie/beego" | |||
| "github.com/astaxie/beego/plugins/cors" | |||
| _ "github.com/astaxie/beego/session/redis" | |||
| "github.com/casbin/casibase/casdoor" | |||
| "github.com/casbin/casibase/object" | |||
| "github.com/casbin/casibase/proxy" | |||
| "github.com/casbin/casibase/routers" | |||
| @@ -26,8 +25,6 @@ import ( | |||
| func main() { | |||
| object.InitAdapter() | |||
| casdoor.InitCasdoorAdapter() | |||
| proxy.InitHttpClient() | |||
| beego.InsertFilter("*", beego.BeforeRouter, cors.Allow(&cors.Options{ | |||