Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/d-ylee/dbs2go into bulkbl…
Browse files Browse the repository at this point in the history
…ocksFilesTests
  • Loading branch information
d-ylee committed May 16, 2022
2 parents 81ec5df + 4ac6c72 commit a90a946
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 5 deletions.
4 changes: 2 additions & 2 deletions web/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ type Configuration struct {
ServerType string `json:"server_type"` // DBS server type to start: DBSReader, DBSWriter, DBSMigrate, DBSMigration
Etag string `json:"etag"` // etag value to use for ETag generation
CacheControl string `json:"cache_control"` // Cache-Control value, e.g. max-age=300
CMSRole string `json:"cms_role"` // cms role for write access
CMSGroup string `json:"cms_group"` // cms group for write access
CMSRole []string `json:"cms_role"` // cms role for write access
CMSGroup []string `json:"cms_group"` // cms group for write access

// Migration server settings
MigrationDBFile string `json:"migration_dbfile"` // dbfile with secrets
Expand Down
20 changes: 17 additions & 3 deletions web/middlewares.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,24 @@ func authMiddleware(next http.Handler) http.Handler {
}

// check if user has proper roles to DBS (non GET) APIs
if r.Method != "GET" && Config.CMSRole != "" && Config.CMSGroup != "" {
status = CMSAuth.CheckCMSAuthz(r.Header, Config.CMSRole, Config.CMSGroup, "")
if r.Method != "GET" && len(Config.CMSRole) > 0 && len(Config.CMSGroup) > 0 {
if len(Config.CMSRole) != len(Config.CMSGroup) {
log.Println("not equal length of cms_role and cms_group attributes")
w.WriteHeader(http.StatusInternalServerError)
return
}
status = false
for i, role := range Config.CMSRole {
group := Config.CMSGroup[i]
// if user has at least one role/group (s)he ok to use the service
if CMSAuth.CheckCMSAuthz(r.Header, role, group, "") {
status = true
break
}
}
// status = CMSAuth.CheckCMSAuthz(r.Header, Config.CMSRole, Config.CMSGroup, "")
if !status {
log.Printf("ERROR: fail to authorize used with role=%v and group=%v, HTTP headers %+v\n", Config.CMSRole, Config.CMSGroup, r.Header)
log.Printf("ERROR: fail to authorize user with role=%v and group=%v, HTTP headers %+v\n", Config.CMSRole, Config.CMSGroup, r.Header)
w.WriteHeader(http.StatusUnauthorized)
return
}
Expand Down

0 comments on commit a90a946

Please sign in to comment.