allow login without specifying user's domain

This commit is contained in:
Qiu Jian
2019-05-30 09:53:56 +08:00
parent 33d22dfae6
commit 2d9a2cfbf4
3 changed files with 16 additions and 5 deletions
+6 -2
View File
@@ -91,10 +91,14 @@ func authUserByIdentity(ctx context.Context, ident mcclient.SAuthenticationIdent
return nil, errors.Wrap(err, "Query user")
}
idmap, err := models.IdmappingManager.FetchEntity(usr.Id, api.IdMappingEntityUser)
if err != nil {
if err != nil && err != sql.ErrNoRows {
return nil, errors.Wrap(err, "IdmappingManager.FetchEntity")
}
idpId = idmap.IdpId
if idmap == nil { // sql
idpId = api.DEFAULT_IDP_ID
} else {
idpId = idmap.IdpId
}
}
} else {
usrExt, err := models.UserManager.FetchUserExtended(ident.Password.User.Id, ident.Password.User.Name,
+7 -1
View File
@@ -19,6 +19,8 @@ import (
"net/http"
"yunion.io/x/jsonutils"
"yunion.io/x/pkg/errors"
"yunion.io/x/sqlchemy"
api "yunion.io/x/onecloud/pkg/apis/identity"
"yunion.io/x/onecloud/pkg/appsrv"
@@ -86,7 +88,11 @@ func authenticateTokensV3(ctx context.Context, w http.ResponseWriter, r *http.Re
input.Auth.Context = FetchAuthContext(input.Auth.Context, r)
token, err := AuthenticateV3(ctx, input)
if err != nil {
httperrors.UnauthorizedError(w, "unauthorized %s", err)
if errors.Cause(err) == sqlchemy.ErrDuplicateEntry {
httperrors.ConflictError(w, "duplicate username")
} else {
httperrors.UnauthorizedError(w, "unauthorized %s", err)
}
return
}
if token == nil {
+3 -2
View File
@@ -135,9 +135,10 @@ func (this *Client) _authV3(domainName, uname, passwd, projectId, projectName, t
input.Auth.Identity.Password.User.Password = passwd
if len(domainName) > 0 {
input.Auth.Identity.Password.User.Domain.Name = domainName
} else {
input.Auth.Identity.Password.User.Domain.Name = api.DEFAULT_DOMAIN_ID
}
// else {
// input.Auth.Identity.Password.User.Domain.Name = api.DEFAULT_DOMAIN_ID
//}
} else if len(token) > 0 {
input.Auth.Identity.Methods = []string{api.AUTH_METHOD_TOKEN}
input.Auth.Identity.Token.Id = token