humingcheng commented on a change in pull request #1014:
URL:
https://github.com/apache/servicecomb-service-center/pull/1014#discussion_r639798475
##########
File path: server/plugin/auth/buildin/buildin.go
##########
@@ -48,86 +49,113 @@ type TokenAuthenticator struct {
}
func (ba *TokenAuthenticator) Identify(req *http.Request) error {
- if !rbacsvc.Enabled() {
+ if !rbac.Enabled() {
return nil
}
pattern, ok := req.Context().Value(rest.CtxMatchPattern).(string)
- if ok && !mustAuth(pattern) {
- return nil
- }
- v := req.Header.Get(restful.HeaderAuth)
- if v == "" {
- return rbac.ErrNoHeader
+ if !ok {
+ pattern = req.URL.Path
+ log.Warn("can not find api pattern")
}
- s := strings.Split(v, " ")
- if len(s) != 2 {
- return rbac.ErrInvalidHeader
+
+ if !mustAuth(pattern) {
+ return nil
}
- to := s[1]
- claims, err := authr.Authenticate(req.Context(), to)
+ claims, err := ba.VerifyToken(req)
if err != nil {
- log.Errorf(err, "authenticate request failed, %s %s",
req.Method, req.RequestURI)
+ log.Errorf(err, "verify request token failed, %s %s",
req.Method, req.RequestURI)
return err
}
+
m, ok := claims.(map[string]interface{})
if !ok {
- log.Error("claims convert failed", rbac.ErrConvertErr)
- return rbac.ErrConvertErr
+ log.Error("claims convert failed", rbacModel.ErrConvertErr)
+ return rbacModel.ErrConvertErr
}
-
- roleList, err := rbac.GetRolesList(m)
+ account, err := rbacModel.GetAccount(m)
if err != nil {
- log.Error("get role list failed", err)
+ log.Error("get account failed", err)
return err
}
+ util.SetRequestContext(req, authHandler.CtxRequestClaims, m)
+ // user can change self password
+ if pattern == rbac.APIAccountPassword && account.Name ==
req.URL.Query().Get(":name") {
Review comment:
done
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]