--------------------------------------------------------
(avh *AuthVersionHandler, w http.ResponseWriter, req *http.Request, path string)
| 87 | // -------------------------------------------------------- |
| 88 | |
| 89 | func checkAPIAuth(avh *AuthVersionHandler, |
| 90 | w http.ResponseWriter, req *http.Request, path string) ( |
| 91 | allowed bool, username string) { |
| 92 | authType := "" |
| 93 | |
| 94 | var mgr *cbgt.Manager |
| 95 | var adtSvc *audit.AuditSvc |
| 96 | |
| 97 | if avh != nil { |
| 98 | mgr = avh.mgr |
| 99 | adtSvc = avh.adtSvc |
| 100 | } |
| 101 | |
| 102 | if mgr != nil && mgr.Options() != nil { |
| 103 | authType = mgr.Options()["authType"] |
| 104 | } |
| 105 | |
| 106 | if authType == "" { |
| 107 | return true, "" |
| 108 | } |
| 109 | |
| 110 | if authType != "cbauth" { |
| 111 | return false, "" |
| 112 | } |
| 113 | |
| 114 | r := &restRequestParser{req: req} |
| 115 | |
| 116 | perms, err := preparePerms(mgr, r, req.Method, path) |
| 117 | if err != nil { |
| 118 | requestBody, _ := ioutil.ReadAll(req.Body) |
| 119 | rest.PropagateError(w, requestBody, fmt.Sprintf("rest_auth: preparePerms,"+ |
| 120 | " err: %v", err), http.StatusBadRequest) |
| 121 | return false, "" |
| 122 | } |
| 123 | |
| 124 | creds, err := CBAuthWebCreds(req) |
| 125 | if err != nil { |
| 126 | requestBody, _ := ioutil.ReadAll(req.Body) |
| 127 | rest.PropagateError(w, requestBody, fmt.Sprintf("rest_auth: cbauth.AuthWebCreds,"+ |
| 128 | " err: %v", err), http.StatusForbidden) |
| 129 | |
| 130 | if adtSvc != nil { |
| 131 | d := GetAuditEventData(AuditAccessDeniedEvent, req) |
| 132 | go adtSvc.Write(AuditAccessDeniedEvent, d) |
| 133 | } |
| 134 | |
| 135 | return false, "" |
| 136 | } |
| 137 | |
| 138 | for _, perm := range perms { |
| 139 | allowed, err = CBAuthIsAllowed(creds, perm) |
| 140 | if err != nil { |
| 141 | requestBody, _ := ioutil.ReadAll(req.Body) |
| 142 | rest.PropagateError(w, requestBody, fmt.Sprintf("rest_auth: cbauth.IsAllowed,"+ |
| 143 | " err: %v", err), http.StatusForbidden) |
| 144 | return false, "" |
| 145 | } |
| 146 |