user

package
v0.12.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 31, 2018 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrUserExists = errors.New("user already exists")
)

Functions

This section is empty.

Types

type ByFirstName added in v0.7.1

type ByFirstName []User

ByFirstName enables sorting user accounts by First Name A-Z

func (ByFirstName) Len added in v0.7.1

func (u ByFirstName) Len() int

func (ByFirstName) Less added in v0.7.1

func (u ByFirstName) Less(i, j int) bool

func (ByFirstName) Swap added in v0.7.1

func (u ByFirstName) Swap(i, j int)

type ByLastName added in v0.7.1

type ByLastName []User

ByLastName enables sorting user accounts by Last Name A-Z

func (ByLastName) Len added in v0.7.1

func (u ByLastName) Len() int

func (ByLastName) Less added in v0.7.1

func (u ByLastName) Less(i, j int) bool

func (ByLastName) Swap added in v0.7.1

func (u ByLastName) Swap(i, j int)

type ByUsername added in v0.7.1

type ByUsername []User

ByUsername enables sorting user accounts by Username A-Z

func (ByUsername) Len added in v0.7.1

func (u ByUsername) Len() int

func (ByUsername) Less added in v0.7.1

func (u ByUsername) Less(i, j int) bool

func (ByUsername) Swap added in v0.7.1

func (u ByUsername) Swap(i, j int)

type Filter added in v0.8.0

type Filter struct {
	// AllowedTenantAccess filters users based on Tenant Access.
	AllowedTenantAccess string
	// AllowedPeopleAccess filters users based on People Access.
	AllowedPeopleAccess string
	// PersonID filters users based on People ID.
	PersonID string
	// Username filters users based on username.
	Username string
	// Scopes filters users based on scopes users must have.
	// Scopes performs an AND operation. To obtain OR, do multiple requests with a single scope.
	Scopes []string
	// FirstName filters users based on their First Name.
	FirstName string
	// LastName filters users based on their Last Name.
	LastName string
	// Disabled filters users to those with disabled accounts.
	Disabled bool
}

Filter enables querying MongoDB for specific user accounts.

type Manager

type Manager interface {
	Storer

	Authenticate(username string, secret []byte) (*User, error)
}

Manager provides a generic interface to users in order to build a DataStore

type MongoManager

type MongoManager struct {
	// DB is the Mongo connection that holds the base session that can be copied and closed.
	DB     *mgo.Database
	Hasher fosite.Hasher
}

MongoManager manages the Mongo Session instance of a User. Implements user.Manager.

func (*MongoManager) Authenticate

func (m *MongoManager) Authenticate(username string, secret []byte) (*User, error)

Authenticate wraps AuthenticateByUsername to allow users to be found via their username. Returns a user record if authentication is successful.

func (*MongoManager) AuthenticateByID

func (m *MongoManager) AuthenticateByID(id string, secret []byte) (*User, error)

AuthenticateByID gets the stored user by ID and authenticates it using a hasher

func (*MongoManager) AuthenticateByUsername

func (m *MongoManager) AuthenticateByUsername(username string, secret []byte) (*User, error)

AuthenticateByUsername gets the stored user by username and authenticates it using a hasher

func (*MongoManager) CreateUser

func (m *MongoManager) CreateUser(u *User) error

CreateUser stores a new user into mongo

func (*MongoManager) DeleteUser

func (m *MongoManager) DeleteUser(id string) error

DeleteUser removes a user from mongo

func (*MongoManager) GetUser

func (m *MongoManager) GetUser(id string) (*User, error)

GetUser gets a user document that has been previously stored in mongo

func (*MongoManager) GetUserByUsername

func (m *MongoManager) GetUserByUsername(username string) (*User, error)

GetUserByUsername gets a user document by searching for a username that has been previously stored in mongo

func (*MongoManager) GetUsers

func (m *MongoManager) GetUsers(filters Filter) (map[string]User, error)

GetUsers returns a map of IDs mapped to a User object that are stored in mongo

func (*MongoManager) GrantScopeToUser

func (m *MongoManager) GrantScopeToUser(id string, scope string) error

GrantScopeToUser adds a scope to a user if it doesn't already exist in the mongo record

func (*MongoManager) RemoveScopeFromUser

func (m *MongoManager) RemoveScopeFromUser(id string, scope string) error

RemoveScopeFromUser takes a scoped right away from the given user.

func (*MongoManager) UpdateUser

func (m *MongoManager) UpdateUser(user *User) error

UpdateUser updates a user record. This is done using the equivalent of an object replace.

type Storer

type Storer interface {
	GetConcreteUser(id string) (*User, error)
	GetUser(id string) (User, error)
	GetUsers() (map[string]User, error)
	CreateUser(u *User) error
	UpdateUser(u *User) error
	DeleteUser(id string) error
	GrantScope(scope string) error
	RemoveScope(scope string) error
	AuthenticateByID(id string, secret []byte) (*User, error)
	AuthenticateByUsername(username string, secret []byte) (*User, error)
}

Storer provides a definition of specific methods that are required to store a User in a data store.

type User

type User struct {
	// User Meta
	// ID is the uniquely assigned uuid that references the user
	ID string `bson:"_id" json:"id" xml:"id"`

	// AllowedTenantAccess contains the Tenant IDs that the user has been given rights to access.
	// This helps in multi-tenanted situations where a user can be given explicit cross-tenant access.
	AllowedTenantAccess []string `bson:"allowedTenantAccess,omitempty" json:"allowedTenantAccess,omitempty" xml:"allowedTenantAccess,omitempty"`

	// AllowedPeopleAccess contains People IDs that users are allowed access to.
	// This helps in multi-tenanted situations where a user can be given explicit access to other people accounts, for
	// example, parents to children records.
	AllowedPeopleAccess []string `bson:"allowedPeopleAccess" json:"allowedPeopleAccess" xml:"allowedPeopleAccess"`

	// Scopes contains the scopes that have been granted to
	Scopes []string `bson:"scopes" json:"scopes" xml:"scopes"`

	// PersonID is a uniquely assigned uuid that references a person within the system.
	// This enables applications where an external person data store is present. This helps in multi-tenanted
	// situations where the person is unique, but the underlying user accounts can exist per tenant.
	PersonID string `bson:"personID" json:"personID" xml:"personID"`

	// User Content
	// Username is used to authenticate a user
	Username string `bson:"username" json:"username" xml:"username"`

	// Password of the user - will be a hash based on your fosite selected hasher
	// If using this model directly in an API, be sure to clear the password out when marshaling to json/xml
	Password string `bson:"password,omitempty" json:"password,omitempty" xml:"password,omitempty"`

	// FirstName stores the user's Last Name
	FirstName string `bson:"firstName" json:"firstName" xml:"firstName"`

	// LastName stores the user's Last Name
	LastName string `bson:"lastName" json:"lastName" xml:"lastName"`

	// ProfileURI is a pointer to where their profile picture lives
	ProfileURI string `bson:"profileUri" json:"profileUri,omitempty" xml:"profileUri,omitempty"`

	// Disabled specifies whether the user has been disallowed from signing in
	Disabled bool `bson:"disabled" json:"disabled" xml:"disabled"`
}

User provides the specific types for storing, editing, deleting and retrieving a User record in mongo.

func (User) Authenticate

func (u User) Authenticate(cleartext string, hasher fosite.Hasher) error

Authenticate compares a cleartext string against the user's

func (*User) DisablePeopleAccess added in v0.9.0

func (u *User) DisablePeopleAccess(peopleIDs ...string)

DisablePeopleAccess disables user access to the provided people.

func (*User) DisableScopeAccess added in v0.9.0

func (u *User) DisableScopeAccess(removeScopes ...string)

DisableScopeAccess disables user access to one or many scopes.

func (*User) DisableTenantAccess added in v0.9.0

func (u *User) DisableTenantAccess(tenantIDs ...string)

DisableTenantAccess disables user access to one or many tenants.

func (*User) EnablePeopleAccess added in v0.9.0

func (u *User) EnablePeopleAccess(peopleIDs ...string)

EnablePeopleAccess enables user access to the provided people

func (*User) EnableScopeAccess added in v0.9.0

func (u *User) EnableScopeAccess(addScopes ...string)

EnableScopeAccess enables user access to one or many scopes.

func (*User) EnableTenantAccess added in v0.9.0

func (u *User) EnableTenantAccess(tenantIDs ...string)

EnableTenantAccess enables user access to one or many tenants.

func (User) Equal added in v0.4.2

func (u User) Equal(x User) bool

Equal enables checking equality as having a byte array in a struct stop allowing equality checks.

func (User) GetFullName

func (u User) GetFullName() (fn string)

GetFullName concatenates the User's First Name and Last Name for templating purposes

func (*User) GetHashedSecret

func (u *User) GetHashedSecret() []byte

GetHashedSecret returns the Users's Hashed Secret as a byte array

func (User) IsEmpty added in v0.4.2

func (u User) IsEmpty() bool

func (*User) SetPassword

func (u *User) SetPassword(cleartext string, hasher fosite.Hasher) (err error)

SetPassword takes a cleartext secret, hashes it with a hasher and sets it as the user's password

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL