Documentation ¶
Overview ¶
Copyright (C) 2022 NHR@FAU, University Erlangen-Nuremberg. All rights reserved. Use of this source code is governed by a MIT-style license that can be found in the LICENSE file.
Copyright (C) 2022 NHR@FAU, University Erlangen-Nuremberg. All rights reserved. Use of this source code is governed by a MIT-style license that can be found in the LICENSE file.
Copyright (C) 2022 NHR@FAU, University Erlangen-Nuremberg. All rights reserved. Use of this source code is governed by a MIT-style license that can be found in the LICENSE file.
Copyright (C) 2022 NHR@FAU, University Erlangen-Nuremberg. All rights reserved. Use of this source code is governed by a MIT-style license that can be found in the LICENSE file.
Copyright (C) 2022 NHR@FAU, University Erlangen-Nuremberg. All rights reserved. Use of this source code is governed by a MIT-style license that can be found in the LICENSE file.
Index ¶
- func FetchUser(ctx context.Context, db *sqlx.DB, username string) (*model.User, error)
- func GetRoleString(roleInt Role) string
- func GetValidRoles(user *User) ([]string, error)
- func GetValidRolesMap(user *User) (map[string]Role, error)
- type AuthSource
- type Authentication
- func (auth *Authentication) AddProject(ctx context.Context, username string, project string) error
- func (auth *Authentication) AddRole(ctx context.Context, username string, queryrole string) error
- func (auth *Authentication) AddUser(user *User) error
- func (auth *Authentication) Auth(onsuccess http.Handler, ...) http.Handler
- func (auth *Authentication) AuthViaSession(rw http.ResponseWriter, r *http.Request) (*User, error)
- func (auth *Authentication) DelUser(username string) error
- func (auth *Authentication) GetUser(username string) (*User, error)
- func (auth *Authentication) ListUsers(specialsOnly bool) ([]*User, error)
- func (auth *Authentication) Login(onsuccess http.Handler, ...) http.Handler
- func (auth *Authentication) Logout(onsuccess http.Handler) http.Handler
- func (auth *Authentication) RemoveProject(ctx context.Context, username string, project string) error
- func (auth *Authentication) RemoveRole(ctx context.Context, username string, queryrole string) error
- type Authenticator
- type ContextKey
- type JWTAuthenticator
- func (ja *JWTAuthenticator) Auth(rw http.ResponseWriter, r *http.Request) (*User, error)
- func (ja *JWTAuthenticator) CanLogin(user *User, rw http.ResponseWriter, r *http.Request) bool
- func (ja *JWTAuthenticator) Init(auth *Authentication, conf interface{}) error
- func (ja *JWTAuthenticator) Login(user *User, rw http.ResponseWriter, r *http.Request) (*User, error)
- func (ja *JWTAuthenticator) ProvideJWT(user *User) (string, error)
- type LdapAuthenticator
- func (la *LdapAuthenticator) Auth(rw http.ResponseWriter, r *http.Request) (*User, error)
- func (la *LdapAuthenticator) CanLogin(user *User, rw http.ResponseWriter, r *http.Request) bool
- func (la *LdapAuthenticator) Init(auth *Authentication, conf interface{}) error
- func (la *LdapAuthenticator) Login(user *User, rw http.ResponseWriter, r *http.Request) (*User, error)
- func (la *LdapAuthenticator) Sync() error
- type LocalAuthenticator
- func (la *LocalAuthenticator) Auth(rw http.ResponseWriter, r *http.Request) (*User, error)
- func (la *LocalAuthenticator) CanLogin(user *User, rw http.ResponseWriter, r *http.Request) bool
- func (la *LocalAuthenticator) Init(auth *Authentication, _ interface{}) error
- func (la *LocalAuthenticator) Login(user *User, rw http.ResponseWriter, r *http.Request) (*User, error)
- type Role
- type User
- func (u *User) GetAuthLevel() Role
- func (u *User) HasAllRoles(queryroles []Role) bool
- func (u *User) HasAnyRole(queryroles []Role) bool
- func (u *User) HasNotRoles(queryroles []Role) bool
- func (u *User) HasProject(project string) bool
- func (u *User) HasRole(role Role) bool
- func (u *User) HasValidRole(role string) (hasRole bool, isValid bool)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func GetRoleString ¶
func GetValidRoles ¶
Called by API endpoint '/roles/' from frontend: Only required for admin config -> Check Admin Role
Types ¶
type AuthSource ¶
type AuthSource int
const ( AuthViaLocalPassword AuthSource = iota AuthViaLDAP AuthViaToken )
type Authentication ¶
type Authentication struct { SessionMaxAge time.Duration LdapAuth *LdapAuthenticator JwtAuth *JWTAuthenticator LocalAuth *LocalAuthenticator // contains filtered or unexported fields }
func (*Authentication) AddProject ¶
func (*Authentication) AddUser ¶
func (auth *Authentication) AddUser(user *User) error
func (*Authentication) Auth ¶
func (auth *Authentication) Auth( onsuccess http.Handler, onfailure func(rw http.ResponseWriter, r *http.Request, authErr error)) http.Handler
Authenticate the user and put a User object in the context of the request. If authentication fails, do not continue but send client to the login screen.
func (*Authentication) AuthViaSession ¶
func (auth *Authentication) AuthViaSession( rw http.ResponseWriter, r *http.Request) (*User, error)
func (*Authentication) DelUser ¶
func (auth *Authentication) DelUser(username string) error
func (*Authentication) GetUser ¶
func (auth *Authentication) GetUser(username string) (*User, error)
func (*Authentication) ListUsers ¶
func (auth *Authentication) ListUsers(specialsOnly bool) ([]*User, error)
func (*Authentication) Login ¶
func (auth *Authentication) Login( onsuccess http.Handler, onfailure func(rw http.ResponseWriter, r *http.Request, loginErr error)) http.Handler
Handle a POST request that should log the user in, starting a new session.
func (*Authentication) Logout ¶
func (auth *Authentication) Logout(onsuccess http.Handler) http.Handler
Clears the session cookie
func (*Authentication) RemoveProject ¶
func (*Authentication) RemoveRole ¶
type Authenticator ¶
type JWTAuthenticator ¶
type JWTAuthenticator struct {
// contains filtered or unexported fields
}
func (*JWTAuthenticator) Auth ¶
func (ja *JWTAuthenticator) Auth( rw http.ResponseWriter, r *http.Request) (*User, error)
func (*JWTAuthenticator) CanLogin ¶
func (ja *JWTAuthenticator) CanLogin( user *User, rw http.ResponseWriter, r *http.Request) bool
func (*JWTAuthenticator) Init ¶
func (ja *JWTAuthenticator) Init(auth *Authentication, conf interface{}) error
func (*JWTAuthenticator) Login ¶
func (ja *JWTAuthenticator) Login( user *User, rw http.ResponseWriter, r *http.Request) (*User, error)
func (*JWTAuthenticator) ProvideJWT ¶
func (ja *JWTAuthenticator) ProvideJWT(user *User) (string, error)
Generate a new JWT that can be used for authentication
type LdapAuthenticator ¶
type LdapAuthenticator struct {
// contains filtered or unexported fields
}
func (*LdapAuthenticator) Auth ¶
func (la *LdapAuthenticator) Auth( rw http.ResponseWriter, r *http.Request) (*User, error)
func (*LdapAuthenticator) CanLogin ¶
func (la *LdapAuthenticator) CanLogin( user *User, rw http.ResponseWriter, r *http.Request) bool
func (*LdapAuthenticator) Init ¶
func (la *LdapAuthenticator) Init( auth *Authentication, conf interface{}) error
func (*LdapAuthenticator) Login ¶
func (la *LdapAuthenticator) Login( user *User, rw http.ResponseWriter, r *http.Request) (*User, error)
func (*LdapAuthenticator) Sync ¶
func (la *LdapAuthenticator) Sync() error
type LocalAuthenticator ¶
type LocalAuthenticator struct {
// contains filtered or unexported fields
}
func (*LocalAuthenticator) Auth ¶
func (la *LocalAuthenticator) Auth( rw http.ResponseWriter, r *http.Request) (*User, error)
func (*LocalAuthenticator) CanLogin ¶
func (la *LocalAuthenticator) CanLogin( user *User, rw http.ResponseWriter, r *http.Request) bool
func (*LocalAuthenticator) Init ¶
func (la *LocalAuthenticator) Init( auth *Authentication, _ interface{}) error
func (*LocalAuthenticator) Login ¶
func (la *LocalAuthenticator) Login( user *User, rw http.ResponseWriter, r *http.Request) (*User, error)
type User ¶
type User struct { Username string `json:"username"` Password string `json:"-"` Name string `json:"name"` Roles []string `json:"roles"` AuthSource AuthSource `json:"via"` Email string `json:"email"` Projects []string `json:"projects"` Expiration time.Time }
func (*User) HasAllRoles ¶
Role-Arrays are short: performance not impacted by nested loop
func (*User) HasAnyRole ¶
Role-Arrays are short: performance not impacted by nested loop
func (*User) HasNotRoles ¶
Role-Arrays are short: performance not impacted by nested loop