forked from ProjectWIND/ProjectWIND
添加数据库master权限支持并优化权限验证逻辑
This commit is contained in:
parent
bb599fad28
commit
308560facd
@ -206,7 +206,7 @@ func loadData(db *Database) error {
|
|||||||
|
|
||||||
var DB *Database
|
var DB *Database
|
||||||
|
|
||||||
func dataSet(datamap string, unit string, id string, key string, value interface{}, allowed bool) {
|
func dataSet(datamap string, unit string, id string, key string, value interface{}, allowed bool, master bool) {
|
||||||
// 修改数据
|
// 修改数据
|
||||||
dm, ok := DB.Datamaps[datamap]
|
dm, ok := DB.Datamaps[datamap]
|
||||||
if !ok {
|
if !ok {
|
||||||
@ -214,7 +214,11 @@ func dataSet(datamap string, unit string, id string, key string, value interface
|
|||||||
DB.addDatamap(datamap)
|
DB.addDatamap(datamap)
|
||||||
dm = DB.Datamaps[datamap]
|
dm = DB.Datamaps[datamap]
|
||||||
}
|
}
|
||||||
if !allowed && dm.Permission != "private" {
|
if dm.Permission == "private" && !allowed && !master {
|
||||||
|
LOG.Warn("[Warning]:Permission denied")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if dm.Permission == "master" && !master {
|
||||||
LOG.Warn("[Warning]:Permission denied")
|
LOG.Warn("[Warning]:Permission denied")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -325,13 +329,17 @@ func dataSet(datamap string, unit string, id string, key string, value interface
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func dataGet(datamap string, unit string, id string, key string, allowed bool) (interface{}, bool) {
|
func dataGet(datamap string, unit string, id string, key string, allowed bool, master bool) (interface{}, bool) {
|
||||||
dm, ok := DB.Datamaps[datamap]
|
dm, ok := DB.Datamaps[datamap]
|
||||||
if !ok {
|
if !ok {
|
||||||
LOG.Warn("[Warning]:Datamap %s not found", datamap)
|
LOG.Warn("[Warning]:Datamap %s not found", datamap)
|
||||||
return "", false
|
return "", false
|
||||||
}
|
}
|
||||||
if !allowed && dm.Permission != "private" {
|
if dm.Permission != "public" && !allowed && !master {
|
||||||
|
LOG.Warn("[Warning]:Permission denied")
|
||||||
|
return "", false
|
||||||
|
}
|
||||||
|
if dm.Permission == "master" && !master {
|
||||||
LOG.Warn("[Warning]:Permission denied")
|
LOG.Warn("[Warning]:Permission denied")
|
||||||
return "", false
|
return "", false
|
||||||
}
|
}
|
||||||
@ -480,6 +488,20 @@ func CreatePublicDatamap(id string) {
|
|||||||
DB.Datamaps[id] = db
|
DB.Datamaps[id] = db
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func CreateMasterDatamap(id string) {
|
||||||
|
db := newDatamap(id)
|
||||||
|
db.Permission = "master"
|
||||||
|
DB.Datamaps[id] = db
|
||||||
|
}
|
||||||
|
|
||||||
|
func MasterGet(datamap string, unit string, id string, key string) (interface{}, bool) {
|
||||||
|
return dataGet(datamap, unit, id, key, true, true)
|
||||||
|
}
|
||||||
|
|
||||||
|
func MasterSet(datamap string, unit string, id string, key string, value interface{}) {
|
||||||
|
dataSet(datamap, unit, id, key, value, true, true)
|
||||||
|
}
|
||||||
|
|
||||||
func Get(appName string, datamap string, unit string, id string, key string, isGettingConfig bool) (interface{}, bool) {
|
func Get(appName string, datamap string, unit string, id string, key string, isGettingConfig bool) (interface{}, bool) {
|
||||||
// 查询数据
|
// 查询数据
|
||||||
if unit == "config" && id == "hash" {
|
if unit == "config" && id == "hash" {
|
||||||
@ -497,19 +519,19 @@ func Get(appName string, datamap string, unit string, id string, key string, isG
|
|||||||
hash := getCorePassword()
|
hash := getCorePassword()
|
||||||
if hash == "" {
|
if hash == "" {
|
||||||
// 删除数据表哈希
|
// 删除数据表哈希
|
||||||
dataSet(appName, "config", "hash", "", "", false)
|
dataSet(appName, "config", "hash", "", "", false, false)
|
||||||
}
|
}
|
||||||
datahash, ok := dataGet(appName, "config", "hash", "", false)
|
datahash, ok := dataGet(appName, "config", "hash", "", false, false)
|
||||||
if !ok {
|
if !ok {
|
||||||
LOG.Error("[Error]:Error while get hash of %s", appName)
|
LOG.Error("[Error]:Error while get hash of %s", appName)
|
||||||
}
|
}
|
||||||
if hash != datahash {
|
if hash != datahash {
|
||||||
LOG.Warn("[Warning]:App %s is not allowed to access data of %s", appName, datamap)
|
LOG.Warn("[Warning]:App %s is not allowed to access data of %s", appName, datamap)
|
||||||
return dataGet(appName, unit, id, key, false)
|
return dataGet(appName, unit, id, key, false, false)
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
return dataGet(appName, unit, id, key, true)
|
return dataGet(appName, unit, id, key, true, false)
|
||||||
}
|
}
|
||||||
|
|
||||||
func Set(appName string, datamap string, unit string, id string, key string, value interface{}) {
|
func Set(appName string, datamap string, unit string, id string, key string, value interface{}) {
|
||||||
@ -524,18 +546,18 @@ func Set(appName string, datamap string, unit string, id string, key string, val
|
|||||||
hash := getCorePassword()
|
hash := getCorePassword()
|
||||||
if hash == "" {
|
if hash == "" {
|
||||||
// 删除数据表哈希
|
// 删除数据表哈希
|
||||||
dataSet(appName, "config", "hash", "", "", false)
|
dataSet(appName, "config", "hash", "", "", true, true)
|
||||||
}
|
}
|
||||||
datahash, ok := dataGet(appName, "config", "hash", "", false)
|
datahash, ok := dataGet(appName, "config", "hash", "", false, false)
|
||||||
if !ok {
|
if !ok {
|
||||||
LOG.Error("[Error]:Error while get hash of %s", appName)
|
LOG.Error("[Error]:Error while get hash of %s", appName)
|
||||||
}
|
}
|
||||||
if hash != datahash {
|
if hash != datahash {
|
||||||
LOG.Warn("[Warning]:App %s is not allowed to access data of %s", appName, datamap)
|
LOG.Warn("[Warning]:App %s is not allowed to access data of %s", appName, datamap)
|
||||||
dataSet(appName, unit, id, key, value, false)
|
dataSet(appName, unit, id, key, value, false, false)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
dataSet(appName, unit, id, key, value, true)
|
dataSet(appName, unit, id, key, value, true, false)
|
||||||
}
|
}
|
||||||
|
|
||||||
type DatabaseHandlerImpl struct{}
|
type DatabaseHandlerImpl struct{}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user