MCPcopy Create free account
hub / github.com/couchbase/sync_gateway / checkAdminAuthenticationOnly

Method checkAdminAuthenticationOnly

rest/handler.go:1124–1147  ·  view source on GitHub ↗

checkAdminAuthenticationOnly simply checks whether a username / password combination is authenticated pulling the credentials from the handler

()

Source from the content-addressed store, hash-verified

1122// checkAdminAuthenticationOnly simply checks whether a username / password combination is authenticated pulling the
1123// credentials from the handler
1124func (h *handler) checkAdminAuthenticationOnly() (bool, error) {
1125 managementEndpoints, httpClient, err := h.server.ObtainManagementEndpointsAndHTTPClient()
1126 if err != nil {
1127 return false, base.HTTPErrorf(http.StatusInternalServerError, "Error getting management endpoints: %v", err)
1128 }
1129
1130 username, password := h.getBasicAuth()
1131 if username == "" {
1132 h.response.Header().Set("WWW-Authenticate", wwwAuthenticateHeader)
1133 return false, ErrLoginRequired
1134 }
1135
1136 statusCode, _, err := doHTTPAuthRequest(h.ctx(), httpClient, username, password, "POST", "/pools/default/checkPermissions", managementEndpoints, nil)
1137 if err != nil {
1138 return false, base.HTTPErrorf(http.StatusInternalServerError, "Error performing HTTP auth request: %v", err)
1139 }
1140
1141 if statusCode == http.StatusUnauthorized {
1142 base.Audit(h.ctx(), base.AuditIDAdminUserAuthenticationFailed, base.AuditFields{base.AuditFieldUserName: username})
1143 return false, nil
1144 }
1145
1146 return true, nil
1147}
1148
1149func checkAdminAuth(ctx context.Context, bucketName, basicAuthUsername, basicAuthPassword string, attemptedHTTPOperation string, httpClient *http.Client, managementEndpoints []string, shouldCheckPermissions bool, accessPermissions []Permission, responsePermissions []Permission) (responsePermissionResults map[string]bool, statusCode int, err error) {
1150 anyResponsePermFailed := false

Callers 1

Calls 8

getBasicAuthMethod · 0.95
ctxMethod · 0.95
HTTPErrorfFunction · 0.92
AuditFunction · 0.92
doHTTPAuthRequestFunction · 0.85
HeaderMethod · 0.80
SetMethod · 0.45

Tested by

no test coverage detected