-
Notifications
You must be signed in to change notification settings - Fork 134
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'v2-master' into v3-master
* v2-master: Add support for view and edit profile for local user (#3883) Add fix to wait until delete indicator has been removed (#3889) FIx setup detection for local users (#3888) Ensure stepper buttons are always visible and content scrolls (#3890) E2E Test should run as user not admin (#3894)
- Loading branch information
Showing
20 changed files
with
542 additions
and
56 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
src/jetstream/datastore/20190918092300_LocalUsersUpdates.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package datastore | ||
|
||
import ( | ||
"database/sql" | ||
|
||
"bitbucket.org/liamstask/goose/lib/goose" | ||
) | ||
|
||
func init() { | ||
|
||
RegisterMigration(20190918092300, "LocalUsersUpdates", func(txn *sql.Tx, conf *goose.DBConf) error { | ||
addGivenNameColumn := "ALTER TABLE local_users ADD given_name VARCHAR(128);" | ||
_, err := txn.Exec(addGivenNameColumn) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
addFamilyNameColumn := "ALTER TABLE local_users ADD family_name VARCHAR(128);" | ||
_, err = txn.Exec(addFamilyNameColumn) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
// All existing data will not have values, so set to defaults | ||
populate := "UPDATE local_users SET given_name='Admin', family_name='User'" | ||
_, err = txn.Exec(populate) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
return nil | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,152 @@ | ||
package userinfo | ||
|
||
import ( | ||
"encoding/json" | ||
"net/http" | ||
|
||
"golang.org/x/crypto/bcrypt" | ||
|
||
"github.com/cloudfoundry-incubator/stratos/src/jetstream/repository/localusers" | ||
"github.com/cloudfoundry-incubator/stratos/src/jetstream/repository/interfaces" | ||
) | ||
|
||
// LocalUserInfo is a plugin to fetch user info | ||
type LocalUserInfo struct { | ||
portalProxy interfaces.PortalProxy | ||
} | ||
|
||
// InitLocalUserInfo creates a new local user info provider | ||
func InitLocalUserInfo(portalProxy interfaces.PortalProxy) Provider { | ||
return &LocalUserInfo{portalProxy: portalProxy} | ||
} | ||
|
||
// GetUserInfo gets info for the specified user | ||
func (userInfo *LocalUserInfo) GetUserInfo(id string) (int, []byte, error) { | ||
|
||
localUsersRepo, err := localusers.NewPgsqlLocalUsersRepository(userInfo.portalProxy.GetDatabaseConnection()) | ||
if err != nil { | ||
return 500, nil, err | ||
} | ||
|
||
user, err := localUsersRepo.FindUser(id) | ||
if err != nil { | ||
return 500, nil, err | ||
} | ||
|
||
uaaUser := &uaaUser{ | ||
ID: id, | ||
Origin: "local", | ||
Username: user.Username, | ||
} | ||
|
||
emails := make([]uaaUserEmail, 1) | ||
emails[0] = uaaUserEmail{Value: user.Email} | ||
uaaUser.Emails = emails | ||
|
||
uaaUser.Name.GivenName = user.GivenName | ||
uaaUser.Name.FamilyName = user.FamilyName | ||
|
||
groups := make([]uaaUserGroup, 2) | ||
groups[0] = uaaUserGroup{Display: user.Scope} | ||
groups[1] = uaaUserGroup{Display: "password.write"} | ||
uaaUser.Groups = groups | ||
|
||
uaaUser.Meta.Version = 0 | ||
|
||
jsonString, err := json.Marshal(uaaUser) | ||
if err != nil { | ||
return 500, nil, err | ||
} | ||
|
||
return 200, jsonString, nil | ||
} | ||
|
||
// UpdateUserInfo updates the user's info | ||
func (userInfo *LocalUserInfo) UpdateUserInfo(profile *uaaUser) (error) { | ||
|
||
// Fetch the user, make updates and save | ||
id := profile.ID | ||
localUsersRepo, err := localusers.NewPgsqlLocalUsersRepository(userInfo.portalProxy.GetDatabaseConnection()) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
user, err := localUsersRepo.FindUser(id) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
hash, err := localUsersRepo.FindPasswordHash(id) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
user.PasswordHash = hash | ||
|
||
if len(profile.Emails) == 1 { | ||
email := profile.Emails[0] | ||
if len(email.Value) >0 { | ||
user.Email = email.Value | ||
} | ||
} | ||
|
||
user.GivenName = profile.Name.GivenName | ||
user.FamilyName = profile.Name.FamilyName | ||
|
||
err = localUsersRepo.UpdateLocalUser(user) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
return nil | ||
} | ||
|
||
// UpdatePassword updates the user's password | ||
func (userInfo *LocalUserInfo) UpdatePassword(id string, passwordInfo *passwordChangeInfo) (error) { | ||
|
||
// Fetch the user, make updates and save | ||
localUsersRepo, err := localusers.NewPgsqlLocalUsersRepository(userInfo.portalProxy.GetDatabaseConnection()) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
user, err := localUsersRepo.FindUser(id) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
hash, err := localUsersRepo.FindPasswordHash(id) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
// Check old password is correct | ||
err = bcrypt.CompareHashAndPassword(hash, []byte(passwordInfo.OldPassword)) | ||
if err != nil { | ||
// Old password is incorrect | ||
return interfaces.NewHTTPShadowError( | ||
http.StatusBadRequest, | ||
"Current password is incorrect", | ||
"Current password is incorrect: %v", err, | ||
) | ||
} | ||
|
||
passwordHash, err := HashPassword(passwordInfo.NewPassword) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
user.PasswordHash = passwordHash | ||
|
||
err = localUsersRepo.UpdateLocalUser(user) | ||
if err != nil { | ||
return err | ||
} | ||
return nil | ||
} | ||
|
||
//HashPassword accepts a plaintext password string and generates a salted hash | ||
func HashPassword(password string) ([]byte, error) { | ||
bytes, err := bcrypt.GenerateFromPassword([]byte(password), 14) | ||
return bytes, err | ||
} |
Oops, something went wrong.