Skip to content

Commit

Permalink
save role in event
Browse files Browse the repository at this point in the history
  • Loading branch information
stremovsky committed Dec 7, 2024
1 parent e19c1b3 commit f5bfabd
Show file tree
Hide file tree
Showing 9 changed files with 21 additions and 23 deletions.
8 changes: 2 additions & 6 deletions src/agreements_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ func (e mainEnv) agreementWithdraw(w http.ResponseWriter, r *http.Request, ps ht
if selfService == false {
// user can change consent only for briefs defined in self-service
if len(authResult) == 0 {
if e.enforceAdmin(w, r) == "" {
if e.enforceAdmin(w, r, event) == "" {
return
}
}
Expand Down Expand Up @@ -237,11 +237,7 @@ func (e mainEnv) agreementWithdraw(w http.ResponseWriter, r *http.Request, ps ht

func (e mainEnv) agreementRevokeAll(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
brief := ps.ByName("brief")
authResult := e.enforceAdmin(w, r)
if authResult == "" {
return
}
if e.enforceAdmin(w, r) == "" {
if e.enforceAdmin(w, r, nil) == "" {
return
}
brief = normalizeBrief(brief)
Expand Down
2 changes: 1 addition & 1 deletion src/audit_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func (e mainEnv) getAuditEvents(w http.ResponseWriter, r *http.Request, ps httpr
}

func (e mainEnv) getAdminAuditEvents(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
if e.enforceAdmin(w, r) == "" {
if e.enforceAdmin(w, r, nil) == "" {
return
}
var offset int32
Expand Down
2 changes: 1 addition & 1 deletion src/expiration_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ func (e mainEnv) expStart(w http.ResponseWriter, r *http.Request, ps httprouter.
event := audit("initiate user record expiration by "+mode, identity, mode, identity)
defer func() { event.submit(e.db, e.conf) }()

if e.enforceAdmin(w, r) == "" {
if e.enforceAdmin(w, r, event) == "" {
return
}
userTOKEN := e.loadUserToken(w, r, mode, identity, event)
Expand Down
6 changes: 3 additions & 3 deletions src/lbasis_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (

func (e mainEnv) createLegalBasis(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
brief := ps.ByName("brief")
if e.enforceAdmin(w, r) == "" {
if e.enforceAdmin(w, r, nil) == "" {
return
}
brief = normalizeBrief(brief)
Expand Down Expand Up @@ -82,7 +82,7 @@ func (e mainEnv) createLegalBasis(w http.ResponseWriter, r *http.Request, ps htt

func (e mainEnv) deleteLegalBasis(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
brief := ps.ByName("brief")
if e.enforceAdmin(w, r) == "" {
if e.enforceAdmin(w, r, nil) == "" {
return
}
brief = normalizeBrief(brief)
Expand All @@ -98,7 +98,7 @@ func (e mainEnv) deleteLegalBasis(w http.ResponseWriter, r *http.Request, ps htt
}

func (e mainEnv) listLegalBasisRecords(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
if e.enforceAdmin(w, r) == "" {
if e.enforceAdmin(w, r, nil) == "" {
return
}
resultJSON, numRecords, err := e.db.getLegalBasisRecords()
Expand Down
10 changes: 5 additions & 5 deletions src/pactivities_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (

func (e mainEnv) pactivityCreate(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
activity := ps.ByName("activity")
if e.enforceAdmin(w, r) == "" {
if e.enforceAdmin(w, r, nil) == "" {
return
}
activity = normalizeBrief(activity)
Expand Down Expand Up @@ -70,7 +70,7 @@ func (e mainEnv) pactivityCreate(w http.ResponseWriter, r *http.Request, ps http

func (e mainEnv) pactivityDelete(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
activity := ps.ByName("activity")
if e.enforceAdmin(w, r) == "" {
if e.enforceAdmin(w, r, nil) == "" {
return
}
activity = normalizeBrief(activity)
Expand All @@ -87,7 +87,7 @@ func (e mainEnv) pactivityDelete(w http.ResponseWriter, r *http.Request, ps http
func (e mainEnv) pactivityLink(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
activity := ps.ByName("activity")
brief := ps.ByName("brief")
if e.enforceAdmin(w, r) == "" {
if e.enforceAdmin(w, r, nil) == "" {
return
}
activity = normalizeBrief(activity)
Expand Down Expand Up @@ -122,7 +122,7 @@ func (e mainEnv) pactivityLink(w http.ResponseWriter, r *http.Request, ps httpro
func (e mainEnv) pactivityUnlink(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
activity := ps.ByName("activity")
brief := ps.ByName("brief")
if e.enforceAdmin(w, r) == "" {
if e.enforceAdmin(w, r, nil) == "" {
return
}
activity = normalizeBrief(activity)
Expand All @@ -146,7 +146,7 @@ func (e mainEnv) pactivityUnlink(w http.ResponseWriter, r *http.Request, ps http
}

func (e mainEnv) pactivityList(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
if e.enforceAdmin(w, r) == "" {
if e.enforceAdmin(w, r, nil) == "" {
return
}
resultJSON, numRecords, err := e.db.listProcessingActivities()
Expand Down
4 changes: 2 additions & 2 deletions src/requests_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ func (e mainEnv) getUserRequest(w http.ResponseWriter, r *http.Request, ps httpr
if len(userTOKEN) != 0 {
event.Record = userTOKEN
}
if e.enforceAdmin(w, r) == "" {
if e.enforceAdmin(w, r, event) == "" {
return
}
change := getStringValue(requestInfo["change"])
Expand Down Expand Up @@ -148,7 +148,7 @@ func (e mainEnv) approveUserRequest(w http.ResponseWriter, r *http.Request, ps h
if enforceUUID(w, request, event) == false {
return
}
authResult := e.enforceAdmin(w, r)
authResult := e.enforceAdmin(w, r, event)
if authResult == "" {
return
}
Expand Down
5 changes: 2 additions & 3 deletions src/sessions_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ func (e mainEnv) createSession(w http.ResponseWriter, r *http.Request, ps httpro
//returnError(w, r, "bad session format", nil, event)
return
}
if e.enforceAdmin(w, r) == "" {
if e.enforceAdmin(w, r, event) == "" {
return
}
expiration := e.conf.Policy.MaxSessionRetentionPeriod
Expand Down Expand Up @@ -77,7 +77,7 @@ func (e mainEnv) deleteSession(w http.ResponseWriter, r *http.Request, ps httpro
//returnError(w, r, "bad session format", nil, event)
return
}
if e.enforceAdmin(w, r) == "" {
if e.enforceAdmin(w, r, event) == "" {
return
}
e.db.deleteSession(session)
Expand All @@ -86,7 +86,6 @@ func (e mainEnv) deleteSession(w http.ResponseWriter, r *http.Request, ps httpro
fmt.Fprintf(w, `{"status":"ok"}`)
}


// the following function is currently not used
func (e mainEnv) newUserSession(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
identity := ps.ByName("identity")
Expand Down
2 changes: 1 addition & 1 deletion src/users_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ func (e mainEnv) userGet(w http.ResponseWriter, r *http.Request, ps httprouter.P
}

func (e mainEnv) userList(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
if e.enforceAdmin(w, r) == "" {
if e.enforceAdmin(w, r, nil) == "" {
return
}
if e.conf.Generic.ListUsers == false {
Expand Down
5 changes: 4 additions & 1 deletion src/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -477,11 +477,14 @@ func (e mainEnv) enforceAuth(w http.ResponseWriter, r *http.Request, event *audi
return ""
}

func (e mainEnv) enforceAdmin(w http.ResponseWriter, r *http.Request) string {
func (e mainEnv) enforceAdmin(w http.ResponseWriter, r *http.Request, event *auditEvent) string {
if token, ok := r.Header["X-Bunker-Token"]; ok {
authResult, err := e.db.checkUserAuthXToken(token[0])
//fmt.Printf("error in auth? error %s - %s\n", err, token[0])
if err == nil {
if event != nil {
event.Identity = authResult.name
}
if len(authResult.ttype) > 0 && authResult.ttype != "login" {
return authResult.ttype
}
Expand Down

0 comments on commit f5bfabd

Please sign in to comment.