Documentation
¶
Index ¶
- type Authentication
- type AuthenticationException
- type AuthenticationManager
- type AuthenticationProvider
- type Authority
- type CredentialsContainer
- type DefaultSecurityFilterAction
- type DefaultSecurityFilterActionEnum
- type DefaultSecurityFilterChainException
- func (this *DefaultSecurityFilterChainException) Action() string
- func (this *DefaultSecurityFilterChainException) Data() map[string]any
- func (this *DefaultSecurityFilterChainException) Handle(handler SecurityHandler) error
- func (this DefaultSecurityFilterChainException) Next() *DefaultSecurityFilterChainException
- func (this DefaultSecurityFilterChainException) RedirectTo(url string) *DefaultSecurityFilterChainException
- func (this DefaultSecurityFilterChainException) RedirectToWithCode(url string, code int) *DefaultSecurityFilterChainException
- func (this DefaultSecurityFilterChainException) RenderView(view string, data map[string]any) *DefaultSecurityFilterChainException
- func (this DefaultSecurityFilterChainException) ReportError(err Error, code int) *DefaultSecurityFilterChainException
- func (this *DefaultSecurityFilterChainException) ReportedError() Error
- func (this *DefaultSecurityFilterChainException) Status() int
- func (this *DefaultSecurityFilterChainException) To() string
- func (this *DefaultSecurityFilterChainException) View() string
- type GrantedAuthority
- type Manager
- type PasswordEncoder
- type PostAuthorisationFilter
- type PreAuthenticationFilter
- type Principal
- type RememberMeService
- type SecurityAppHandler
- type SecurityContext
- type SecurityContextHolder
- type SecurityEndpointRegistration
- type SecurityEventFilter
- type SecurityFilter
- type SecurityFilterChain
- type SecurityFilterChainException
- type SecurityHandler
- type SecurityRouter
- type SessionAwareFilter
- type UserDetails
- type UserDetailsService
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Authentication ¶
type Authentication interface {
Principal
// GetAuthorities() returns the authorities this principal has been granted.
GetAuthorities() []GrantedAuthority
// GetCredentials() returns the credentials that prove the principal is correct.
GetCredentials() any
// GetPrincipal() The identity of the principal being authenticated.
GetPrincipal() any
// IsAuthenticated() returns whether that principal has been authenticated.
IsAuthenticated() bool
}
Authentication represent an authentication request or and authenticated principal, once processed by an AuthenticationManager.Authenticate.
type AuthenticationException ¶
type AuthenticationException interface {
Exception
// AuthenticationRequest() returns the [Authentication] causing this Exception
AuthenticationRequest() Authentication
}
type AuthenticationManager ¶
type AuthenticationManager interface {
Manager
// Authenticate() will return an authenticated [Authenication] or an AuthenticationException.
// It will delegate this to a configured [AuthenticationProvider] supporting this [Authentication]
Authenticate(Authentication) (Authentication, AuthenticationException)
}
AuthenticationManager is an interface that will delegate [Authenticate] to one of AuthenticationProvider supporting it.
type AuthenticationProvider ¶
type AuthenticationProvider interface {
// Authenticate() will return an authenticated [Authenication] or an AuthenticationException
Authenticate(Authentication) (Authentication, AuthenticationException)
// Supports() should return whether this [AuthenticationProvider] supports this [Authentication]
Supports(Authentication) bool
}
AuthenticationProvider will handle authentication for a specific Authentication.
type Authority ¶
type Authority string
Authority is a utility type to ease the creation of GrantedAuthority
Example :
var authorities []GrantedAuthority = []GrantedAuthority{Authority("ROLE_USER")}
func (Authority) Authority ¶
Authority() implements GrantedAuthority.Authority.
type CredentialsContainer ¶
type CredentialsContainer interface {
// EraseCredentials() will proceed on erasing the credentials.
EraseCredentials()
}
CredentialsContainer represent an interface facilating credential suppression after an Authentication succeeded.
NOTE: Not used for now
type DefaultSecurityFilterAction ¶
type DefaultSecurityFilterAction = Enum[DefaultSecurityFilterActionEnum]
DefaultSecurityFilterAction is an Enum alias for DefaultSecurityFilterActionEnum
type DefaultSecurityFilterActionEnum ¶
type DefaultSecurityFilterActionEnum struct {
NEXT,
ERROR,
REDIRECT,
RENDER DefaultSecurityFilterAction
}
DefaultSecurityFilterActionEnum is an Enum type for all possible actions
type DefaultSecurityFilterChainException ¶
type DefaultSecurityFilterChainException struct {
*DefaultError
// contains filtered or unexported fields
}
DefaultSecurityFilterChainException is the default implementation of SecurityFilterChainException.
It offers constructor-like functions to directly creates all the possible SecurityFilterChainException.
TODO: Decompose it into different struct, like AuthenticationException
func (*DefaultSecurityFilterChainException) Action ¶
func (this *DefaultSecurityFilterChainException) Action() string
Action() implements SecurityFilterChainException.Action.
func (*DefaultSecurityFilterChainException) Data ¶
func (this *DefaultSecurityFilterChainException) Data() map[string]any
Data() returns the data map configured for rendering a view.
NOTE: Provided for debugging and testing purpose.
func (*DefaultSecurityFilterChainException) Handle ¶
func (this *DefaultSecurityFilterChainException) Handle(handler SecurityHandler) error
Handle() implements SecurityFilterChainException.Handle.
func (DefaultSecurityFilterChainException) Next ¶
func (this DefaultSecurityFilterChainException) Next() *DefaultSecurityFilterChainException
Next() creates a new DefaultSecurityFilterChainException used to tell you framework to process with the next middleware.
func (DefaultSecurityFilterChainException) RedirectTo ¶
func (this DefaultSecurityFilterChainException) RedirectTo(url string) *DefaultSecurityFilterChainException
RedirectTo() creates a new DefaultSecurityFilterChainException for redirecting a request to the provided url.
It uses a 302 HTTP code (temporary redirect) by default.
func (DefaultSecurityFilterChainException) RedirectToWithCode ¶
func (this DefaultSecurityFilterChainException) RedirectToWithCode(url string, code int) *DefaultSecurityFilterChainException
RedirectToWithCode() creates a new DefaultSecurityFilterChainException for redirecting a request to the provided url using the provided code.
func (DefaultSecurityFilterChainException) RenderView ¶
func (this DefaultSecurityFilterChainException) RenderView(view string, data map[string]any) *DefaultSecurityFilterChainException
RenderView() creates a new DefaultSecurityFilterChainException for rendering a view, with the provided data map.
func (DefaultSecurityFilterChainException) ReportError ¶
func (this DefaultSecurityFilterChainException) ReportError(err Error, code int) *DefaultSecurityFilterChainException
ReportError() creates a new DefaultSecurityFilterChainException that will report an [Error] err, with the configured HTTP code.
To create a redirect, please use DefaultSecurityFilterChainException.RedirectTo or DefaultSecurityFilterChainException.RedirectToWithCode
func (*DefaultSecurityFilterChainException) ReportedError ¶
func (this *DefaultSecurityFilterChainException) ReportedError() Error
ReportedError() returns the configured [Error].
NOTE: Provided for debugging and testing purpose.
func (*DefaultSecurityFilterChainException) Status ¶
func (this *DefaultSecurityFilterChainException) Status() int
Status() returns the status code used for redirect or error reporting.
NOTE: Provided for debugging and testing purpose.
func (*DefaultSecurityFilterChainException) To ¶
func (this *DefaultSecurityFilterChainException) To() string
To() returns the configured url used for redirect.
NOTE: Provided for debugging and testing purpose.
func (*DefaultSecurityFilterChainException) View ¶
func (this *DefaultSecurityFilterChainException) View() string
View() returns the view name configured for rendering a view.
NOTE: Provided for debugging and testing purpose.
type GrantedAuthority ¶
type GrantedAuthority interface {
// Authority() returns the authority as a string.
Authority() string
}
GrantedAuthority represent an authority a user is given.
type Manager ¶
type Manager interface {
// contains filtered or unexported methods
}
Manager is a marker interface to differentiate AuthenticationProvider and AuthenticationManager Authenticate method
type PasswordEncoder ¶
type PasswordEncoder interface {
// Encode() will encode a password or generate and error.
Encode(password []byte) ([]byte, error)
// Matches() will check if a submittes password match.
Matches(password, encoded []byte) bool
}
PasswordEncoder is the interface representing a way to encode and match a password.
type PostAuthorisationFilter ¶
type PostAuthorisationFilter interface {
SecurityEventFilter
// contains filtered or unexported methods
}
PostAuthorisationFilter is a type that a middleware should implements to indicates to the web framework implementation that it should be configured *after* the security process.
type PreAuthenticationFilter ¶
type PreAuthenticationFilter interface {
SecurityEventFilter
// contains filtered or unexported methods
}
PreAuthenticationFilter is a type that a middleware should implements to indicates to the web framework implementation that it should be configured *before* the security process.
type Principal ¶
type Principal interface {
GetName() string
}
Principal represent a the notion of a principal, which can be used to represent any entity
type RememberMeService ¶
type RememberMeService interface {
AutoLogin(handler SecurityHandler) (Authentication, Error)
LoginSuccess(handler SecurityHandler, successfulAuthentication Authentication)
LoginFail(handler SecurityHandler)
Logout(handler SecurityHandler)
}
RememberMeService represent a remember-me service
type SecurityAppHandler ¶
type SecurityAppHandler interface {
// Implements [SecurityRouter]
SecurityRouter
// EnableCsrf() should implement what it is needed to enable CSRF for that
// web framework connector. Before doing so it should check the result of the skip
// function to know if it should not be done.
EnableCsrf(skip func(handler SecurityHandler) bool)
// EnableSession() should implement what is needed to enable Session handling for that
// web framework connector. Before doing so it should check the result of the skip
// function to know if it should not be done.
EnableSession(skip func(handler SecurityHandler) bool)
// HasSession() should returns if for that request, session has been enabled.
HasSession(handler SecurityHandler) bool
// PostAuthorizationFilter() is a callback
PostAuthorizationFilter(handler SecurityHandler)
}
SecurityAppHandler is an interface a web framework connector should implements to interface with github.com/BeamFoundry/rays-web-security.
It is used to initialize the security on a request with the SecurityFilterChain.
type SecurityContext ¶
type SecurityContext interface {
// GetAuthentication() returns the current [Authentication] associated with the current thread.
//
// It can be an Anonymous user, in which case [Authentication.IsAuthenticated] will return false.
GetAuthentication() Authentication
// SetAuthentication() will change the current authentication object.
//
// It's the responsibility of a [SecurityFilter] to either save the current [Authentication] in
// either or both the session or in the [SecurityContext].
SetAuthentication(authentication Authentication)
// SetHTTPPolicyDebugValue() sets a string containing debug informations about the current
// policy applied to the current thread.
SetHTTPPolicyDebugValue(debug string)
// GetHTTPPolicyDebugValue() let's retrieve the value set in SetHTTPPolicyDebugValue.
GetHTTPPolicyDebugValue() string
}
SecurityContext is an object popuplated inside the SecurityContextHolder during the Authentication phase.
It let you retrieve the current user Authentication, or set it.
type SecurityContextHolder ¶
type SecurityContextHolder interface {
// ClearContext() is called when initializing the current authntication process.
ClearContext()
// SetContext() lets erase the current [SecurityContext]
SetContext(context SecurityContext)
// GetContext() lets you retrieve the current [SecurityContext]
GetContext() SecurityContext
}
SecurityContextHolder is the interface that is used to set or retrieve the current SecurityContext.
type SecurityEndpointRegistration ¶
type SecurityEndpointRegistration interface {
// RegisterSecurityEndpoint() let you add endpoints.
RegisterSecurityEndpoint(router SecurityRouter)
}
SecurityEndpointRegistration is an optional interface a SecurityFilter may also implements to have some path related handler registered.
They are mainly used to provide technical endpoints like "login" form display and "logout".
type SecurityEventFilter ¶
type SecurityEventFilter interface {
EventFilter
// contains filtered or unexported methods
}
SecurityEventFilter is a base marker type for an EventFilter around a security event. Used by PreAuthenticationFilter and PostAuthorisationFilter.
type SecurityFilter ¶
type SecurityFilter interface {
// Authenticate() should authenticate an user, using Session or the AuthenticationManager.
//
// It should return a [SecurityFilterChainException] indicating what should be done next.
Authenticate(handler SecurityHandler) SecurityFilterChainException
// AuthenticationRequired() should return a [SecurityFilterChainException] to indicate what
// the [SecurityFilterChain] should do if no authentication has been successful and
// the user try to access a restricted path.
AuthenticationRequired(handler SecurityHandler) SecurityFilterChainException
}
SecurityFilter is an interface describing a filter used to Authenticate a user.
It is used by the SecurityFilterChain implementation.
You can add your own SecurityFilter in an [HttpSecurity] object.
type SecurityFilterChain ¶
type SecurityFilterChain interface {
Initialize(serverName string, app SecurityAppHandler)
}
type SecurityFilterChainException ¶
type SecurityFilterChainException interface {
// Exception is an alias for Error
Exception
// Action() returns thez action to execute, useful if you exception can handler multiple cases.
Action() string
// Handle() will process this [SecurityFilterChainException] though a [SecurityHandler] and return any error
// that handler will return.
//
// it's the web framework responsibility to return error it can manage through its implementation of
// [SecurityHandler].
Handle(handler SecurityHandler) error
}
SecurityFilterChainException is an interface implementing github.com/BeamFoundry/rays/pkg/lang.Exception.
It is used to designed a way to create error reported by a SecurityFilter and be handled by a SecurityHandler.
type SecurityHandler ¶
type SecurityHandler interface {
// Cookie() returns the named Cookie or an error if not found.
Cookie(name string) (*http.Cookie, error)
// SetCookie() sets a cookie
SetCookie(cookie *http.Cookie)
// FormValue() returns a named form submitted value
FormValue(name string) string
// Header() returns the named HTTP Header or blank
Header(name string) string
// SetHeader() set then named Header to value
SetHeader(name, value string)
// Method() returns the Request HTTP Method
Method() string
// Path() returns the Request Path
Path() string
// SessionReset() empty the current session
SessionReset()
// SessionRefresh() regenerate the session ID, keeping the data.
// Used after a login, to protect against session fixing.
SessionRefresh()
// SessionValue() return a session value
SessionValue(key string) any
// SetSessionValue() sets a session value
SetSessionValue(key string, obj any)
// URL() returns the request URL
URL() *url.URL
// BindBody() bind the current Form submitted to an object
BindBody(obj any) error
// Redirect() set the Location header and redirect code
Redirect(to string, code int) error
// RenderView() render the view with data
RenderView(view string, data map[string]any) error
// Error() handles creating an HTTP error message
//
// Implementations may have a specific method for creating them.
Error(code int, message string) error
// Write() write the body
Write(p []byte) (n int, err error)
// Enable the next handler
Next() error
}
SecurityHandler represents a web framework agnostic web context.
type SecurityRouter ¶
type SecurityRouter interface {
// Group() returns a new SecurityRouter for the given path
Group(path string) SecurityRouter
// Use() register a new handler
Use(handler func(SecurityHandler) error)
// Get() add a GET HTTP handler for the given path
Get(path string, handler func(SecurityHandler) error)
// Post() add a POST HTTP handler for the given path
Post(path string, handler func(SecurityHandler) error)
}
SecurityRouter is a base interface used by SecurityAppHandler.
type SessionAwareFilter ¶
type SessionAwareFilter interface {
// contains filtered or unexported methods
}
SessionAwareFilter is a marker interface a SecurityFilter should use to indicate it needs session handling.
Depending on the configuration Session may be enabled only if some filters need it. See: [github.com/BeamFoundry/rays-web-security/pkg/config.]
type UserDetails ¶
type UserDetails interface {
// GetUsername() returns the username used to authenticate the user.
GetUsername() string
// GetPassword() returns the password used to authenticate the user.
GetPassword() string
// GetAuthorities() returns the authorities granted to the user.
GetAuthorities() []GrantedAuthority
// IsExpired() indicates whether the user's account has expired.
IsExpired() bool
// IsCredentialExpired() indicates whether the user's credentials (password) has expired.
IsCredentialExpired() bool
// IsDisabled() indicates whether the user's credentials (password) has expired.
IsDisabled() bool
// IsLocked() indicates whether the user is enabled or disabled.
IsLocked() bool
}
UserDetails provide core user informations.
type UserDetailsService ¶
type UserDetailsService interface {
// LoadUserByUsername() should return a [UserDetails] given it's username or nil.
LoadUserByUsername(username string) UserDetails
}
UserDetailsService is an interface used by in internal AuthenticationProvider for retrieving a username, password and other attributes for user authenticating, using a username and password