Documentation
¶
Index ¶
- Constants
- func ApplyColumnSecurity(secCtx SecurityContext, securityList *SecurityList) error
- func ApplyRowSecurity(secCtx SecurityContext, securityList *SecurityList) error
- func GetRemoteID(ctx context.Context) (string, bool)
- func GetSessionID(ctx context.Context) (string, bool)
- func GetSessionRID(ctx context.Context) (int64, bool)
- func GetUserEmail(ctx context.Context) (string, bool)
- func GetUserID(ctx context.Context) (int, bool)
- func GetUserLevel(ctx context.Context) (int, bool)
- func GetUserMeta(ctx context.Context) (map[string]any, bool)
- func GetUserName(ctx context.Context) (string, bool)
- func GetUserRoles(ctx context.Context) ([]string, bool)
- func LoadSecurityRules(secCtx SecurityContext, securityList *SecurityList) error
- func LogDataAccess(secCtx SecurityContext) error
- func NewAuthHandler(securityList *SecurityList, next http.Handler) http.Handler
- func NewAuthMiddleware(securityList *SecurityList) func(http.Handler) http.Handler
- func NewOptionalAuthHandler(securityList *SecurityList, next http.Handler) http.Handler
- func OptionalAuth(ctx context.Context) context.Context
- func SetSecurityMiddleware(securityList *SecurityList) func(http.Handler) http.Handler
- func SkipAuth(ctx context.Context) context.Context
- func WithAuth(handler func(http.ResponseWriter, *http.Request), securityList *SecurityList) func(http.ResponseWriter, *http.Request)
- func WithAuthAndSecurity(handler func(http.ResponseWriter, *http.Request), securityList *SecurityList) func(http.ResponseWriter, *http.Request)
- func WithOptionalAuth(handler func(http.ResponseWriter, *http.Request), securityList *SecurityList) func(http.ResponseWriter, *http.Request)
- func WithOptionalAuthAndSecurity(handler func(http.ResponseWriter, *http.Request), securityList *SecurityList) func(http.ResponseWriter, *http.Request)
- func WithSecurityContext(handler func(http.ResponseWriter, *http.Request), securityList *SecurityList) func(http.ResponseWriter, *http.Request)
- type Authenticator
- type CONTEXT_KEY
- type Cacheable
- type ColumnSecurity
- type ColumnSecurityProvider
- type CompositeSecurityProvider
- func (c *CompositeSecurityProvider) Authenticate(r *http.Request) (*UserContext, error)
- func (c *CompositeSecurityProvider) ClearCache(ctx context.Context, userID int, schema, table string) error
- func (c *CompositeSecurityProvider) GetColumnSecurity(ctx context.Context, userID int, schema, table string) ([]ColumnSecurity, error)
- func (c *CompositeSecurityProvider) GetRowSecurity(ctx context.Context, userID int, schema, table string) (RowSecurity, error)
- func (c *CompositeSecurityProvider) Login(ctx context.Context, req LoginRequest) (*LoginResponse, error)
- func (c *CompositeSecurityProvider) Logout(ctx context.Context, req LogoutRequest) error
- func (c *CompositeSecurityProvider) RefreshToken(ctx context.Context, refreshToken string) (*LoginResponse, error)
- func (c *CompositeSecurityProvider) ValidateToken(ctx context.Context, token string) (bool, error)
- type ConfigColumnSecurityProvider
- type ConfigRowSecurityProvider
- type DatabaseAuthenticator
- func (a *DatabaseAuthenticator) Authenticate(r *http.Request) (*UserContext, error)
- func (a *DatabaseAuthenticator) ClearCache(token string) error
- func (a *DatabaseAuthenticator) ClearUserCache(userID int) error
- func (a *DatabaseAuthenticator) Login(ctx context.Context, req LoginRequest) (*LoginResponse, error)
- func (a *DatabaseAuthenticator) Logout(ctx context.Context, req LogoutRequest) error
- func (a *DatabaseAuthenticator) RefreshToken(ctx context.Context, refreshToken string) (*LoginResponse, error)
- type DatabaseAuthenticatorExample
- func (a *DatabaseAuthenticatorExample) Authenticate(r *http.Request) (*UserContext, error)
- func (a *DatabaseAuthenticatorExample) Login(ctx context.Context, req LoginRequest) (*LoginResponse, error)
- func (a *DatabaseAuthenticatorExample) Logout(ctx context.Context, req LogoutRequest) error
- func (a *DatabaseAuthenticatorExample) RefreshToken(ctx context.Context, refreshToken string) (*LoginResponse, error)
- type DatabaseAuthenticatorOptions
- type DatabaseColumnSecurityProvider
- type DatabaseRowSecurityProvider
- type HeaderAuthenticator
- type HeaderAuthenticatorExample
- type JWTAuthenticator
- type JWTAuthenticatorExample
- type LoginRequest
- type LoginResponse
- type LogoutRequest
- type Refreshable
- type RowSecurity
- type RowSecurityProvider
- type SecurityContext
- type SecurityList
- func (m *SecurityList) ApplyColumnSecurity(records reflect.Value, modelType reflect.Type, pUserID int, ...) (reflect.Value, error)
- func (m *SecurityList) ClearSecurity(pUserID int, pSchema, pTablename string) error
- func (m *SecurityList) ColumSecurityApplyOnRecord(prevRecord reflect.Value, newRecord reflect.Value, modelType reflect.Type, ...) ([]string, error)
- func (m *SecurityList) GetRowSecurityTemplate(pUserID int, pSchema, pTablename string) (RowSecurity, error)
- func (m *SecurityList) LoadColumnSecurity(ctx context.Context, pUserID int, pSchema, pTablename string, pOverwrite bool) error
- func (m *SecurityList) LoadRowSecurity(ctx context.Context, pUserID int, pSchema, pTablename string, pOverwrite bool) (RowSecurity, error)
- func (m *SecurityList) Provider() SecurityProvider
- type SecurityProvider
- type UserContext
- type Validatable
Constants ¶
const ( // Context keys for user information UserIDKey contextKey = "user_id" UserNameKey contextKey = "user_name" UserLevelKey contextKey = "user_level" SessionIDKey contextKey = "session_id" SessionRIDKey contextKey = "session_rid" RemoteIDKey contextKey = "remote_id" UserRolesKey contextKey = "user_roles" UserEmailKey contextKey = "user_email" UserContextKey contextKey = "user_context" UserMetaKey contextKey = "user_meta" SkipAuthKey contextKey = "skip_auth" OptionalAuthKey contextKey = "optional_auth" )
Variables ¶
This section is empty.
Functions ¶
func ApplyColumnSecurity ¶ added in v0.0.63
func ApplyColumnSecurity(secCtx SecurityContext, securityList *SecurityList) error
ApplyColumnSecurity is a public wrapper for applyColumnSecurity that accepts a SecurityContext This allows other packages to apply column-level security using the generic interface
func ApplyRowSecurity ¶ added in v0.0.63
func ApplyRowSecurity(secCtx SecurityContext, securityList *SecurityList) error
ApplyRowSecurity is a public wrapper for applyRowSecurity that accepts a SecurityContext This allows other packages to apply row-level security using the generic interface
func GetRemoteID ¶ added in v0.0.63
GetRemoteID extracts the remote ID from context
func GetSessionID ¶ added in v0.0.63
GetSessionID extracts the session ID from context
func GetSessionRID ¶ added in v0.0.81
GetSessionID extracts the session ID from context
func GetUserEmail ¶ added in v0.0.63
GetUserEmail extracts user email from context
func GetUserLevel ¶ added in v0.0.63
GetUserLevel extracts the user level from context
func GetUserMeta ¶ added in v0.0.64
GetUserMeta extracts user metadata from context
func GetUserName ¶ added in v0.0.63
GetUserName extracts the user name from context
func GetUserRoles ¶
GetUserRoles extracts user roles from context
func LoadSecurityRules ¶ added in v0.0.63
func LoadSecurityRules(secCtx SecurityContext, securityList *SecurityList) error
LoadSecurityRules is a public wrapper for loadSecurityRules that accepts a SecurityContext This allows other packages to load security rules using the generic interface
func LogDataAccess ¶ added in v0.0.63
func LogDataAccess(secCtx SecurityContext) error
LogDataAccess is a public wrapper for logDataAccess that accepts a SecurityContext This allows other packages to use the audit logging functionality
func NewAuthHandler ¶ added in v0.0.64
func NewAuthHandler(securityList *SecurityList, next http.Handler) http.Handler
NewAuthHandler creates an authentication handler that can be used standalone This handler performs authentication and returns 401 if authentication fails Use this when you need authentication logic without middleware wrapping
func NewAuthMiddleware ¶ added in v0.0.63
func NewAuthMiddleware(securityList *SecurityList) func(http.Handler) http.Handler
NewAuthMiddleware creates an authentication middleware with the given security list This middleware extracts user authentication from the request and adds it to context Routes can skip authentication by setting SkipAuthKey context value (use SkipAuth helper) Routes can use optional authentication by setting OptionalAuthKey context value (use OptionalAuth helper) When authentication is skipped or fails with optional auth, a guest user context is set instead
func NewOptionalAuthHandler ¶ added in v0.0.64
func NewOptionalAuthHandler(securityList *SecurityList, next http.Handler) http.Handler
NewOptionalAuthHandler creates an optional authentication handler that can be used standalone This handler tries to authenticate but falls back to guest context if authentication fails Use this for routes that should show personalized content for authenticated users but still work for guests
func OptionalAuth ¶ added in v0.0.64
OptionalAuth returns a context with optional auth flag set to true Use this to mark routes that should try to authenticate, but fall back to guest if authentication fails
func SetSecurityMiddleware ¶
func SetSecurityMiddleware(securityList *SecurityList) func(http.Handler) http.Handler
SetSecurityMiddleware adds security context to requests This middleware should be applied after AuthMiddleware
func SkipAuth ¶ added in v0.0.64
SkipAuth returns a context with skip auth flag set to true Use this to mark routes that should bypass authentication middleware
func WithAuth ¶ added in v0.0.83
func WithAuth(handler func(http.ResponseWriter, *http.Request), securityList *SecurityList) func(http.ResponseWriter, *http.Request)
WithAuth wraps an HTTPFuncType handler with required authentication This function performs authentication and returns 401 if authentication fails Use this for handlers that require authenticated users
Usage:
handler := funcspec.NewHandler(db)
wrappedHandler := security.WithAuth(handler.SqlQueryList("SELECT * FROM orders WHERE user_id = [rid_user]", false, false, false), securityList)
router.HandleFunc("/api/orders", wrappedHandler)
func WithAuthAndSecurity ¶ added in v0.0.83
func WithAuthAndSecurity(handler func(http.ResponseWriter, *http.Request), securityList *SecurityList) func(http.ResponseWriter, *http.Request)
WithAuthAndSecurity wraps an HTTPFuncType handler with both authentication and security context This is a convenience function that combines WithAuth and WithSecurityContext Use this when you need both authentication and security context for a handler
Usage:
handler := funcspec.NewHandler(db)
wrappedHandler := security.WithAuthAndSecurity(handler.SqlQueryList("SELECT * FROM users", false, false, false), securityList)
router.HandleFunc("/api/users", wrappedHandler)
func WithOptionalAuth ¶ added in v0.0.83
func WithOptionalAuth(handler func(http.ResponseWriter, *http.Request), securityList *SecurityList) func(http.ResponseWriter, *http.Request)
WithOptionalAuth wraps an HTTPFuncType handler with optional authentication This function tries to authenticate but falls back to guest context if authentication fails Use this for handlers that should show personalized content for authenticated users but still work for guests
Usage:
handler := funcspec.NewHandler(db)
wrappedHandler := security.WithOptionalAuth(handler.SqlQueryList("SELECT * FROM products", false, false, false), securityList)
router.HandleFunc("/api/products", wrappedHandler)
func WithOptionalAuthAndSecurity ¶ added in v0.0.83
func WithOptionalAuthAndSecurity(handler func(http.ResponseWriter, *http.Request), securityList *SecurityList) func(http.ResponseWriter, *http.Request)
WithOptionalAuthAndSecurity wraps an HTTPFuncType handler with optional authentication and security context This is a convenience function that combines WithOptionalAuth and WithSecurityContext Use this when you want optional authentication and security context for a handler
Usage:
handler := funcspec.NewHandler(db)
wrappedHandler := security.WithOptionalAuthAndSecurity(handler.SqlQueryList("SELECT * FROM products", false, false, false), securityList)
router.HandleFunc("/api/products", wrappedHandler)
func WithSecurityContext ¶ added in v0.0.83
func WithSecurityContext(handler func(http.ResponseWriter, *http.Request), securityList *SecurityList) func(http.ResponseWriter, *http.Request)
WithSecurityContext wraps an HTTPFuncType handler with security context This function allows you to add security context to specific handler functions without needing to apply middleware globally
Usage:
handler := funcspec.NewHandler(db)
wrappedHandler := security.WithSecurityContext(handler.SqlQueryList("SELECT * FROM users", false, false, false), securityList)
router.HandleFunc("/api/users", wrappedHandler)
Types ¶
type Authenticator ¶ added in v0.0.63
type Authenticator interface {
// Login authenticates credentials and returns a token
Login(ctx context.Context, req LoginRequest) (*LoginResponse, error)
// Logout invalidates a user's session/token
Logout(ctx context.Context, req LogoutRequest) error
// Authenticate extracts and validates user from HTTP request
// Returns UserContext or error if authentication fails
Authenticate(r *http.Request) (*UserContext, error)
}
Authenticator handles user authentication operations
type CONTEXT_KEY ¶ added in v0.0.20
type CONTEXT_KEY string
const SECURITY_CONTEXT_KEY CONTEXT_KEY = "SecurityList"
type Cacheable ¶ added in v0.0.63
type Cacheable interface {
// ClearCache clears cached security rules for a user/entity
ClearCache(ctx context.Context, userID int, schema, table string) error
}
Cacheable allows providers to support caching of security rules
type ColumnSecurity ¶
type ColumnSecurity struct {
Schema string `json:"schema"`
Tablename string `json:"tablename"`
Path []string `json:"path"`
ExtraFilters map[string]string `json:"extra_filters"`
UserID int `json:"user_id"`
Accesstype string `json:"accesstype"`
MaskStart int `json:"mask_start"`
MaskEnd int `json:"mask_end"`
MaskInvert bool `json:"mask_invert"`
MaskChar string `json:"mask_char"`
Control string `json:"control"`
ID int `json:"id"`
}
type ColumnSecurityProvider ¶ added in v0.0.63
type ColumnSecurityProvider interface {
// GetColumnSecurity loads column security rules for a user and entity
GetColumnSecurity(ctx context.Context, userID int, schema, table string) ([]ColumnSecurity, error)
}
ColumnSecurityProvider handles column-level security (masking/hiding)
type CompositeSecurityProvider ¶ added in v0.0.63
type CompositeSecurityProvider struct {
// contains filtered or unexported fields
}
CompositeSecurityProvider combines multiple security providers Allows separating authentication, column security, and row security concerns
func NewCompositeSecurityProvider ¶ added in v0.0.63
func NewCompositeSecurityProvider( auth Authenticator, colSec ColumnSecurityProvider, rowSec RowSecurityProvider, ) (*CompositeSecurityProvider, error)
NewCompositeSecurityProvider creates a composite provider All parameters are required
func (*CompositeSecurityProvider) Authenticate ¶ added in v0.0.63
func (c *CompositeSecurityProvider) Authenticate(r *http.Request) (*UserContext, error)
Authenticate delegates to the authenticator
func (*CompositeSecurityProvider) ClearCache ¶ added in v0.0.63
func (c *CompositeSecurityProvider) ClearCache(ctx context.Context, userID int, schema, table string) error
ClearCache implements Cacheable if any provider supports it
func (*CompositeSecurityProvider) GetColumnSecurity ¶ added in v0.0.63
func (c *CompositeSecurityProvider) GetColumnSecurity(ctx context.Context, userID int, schema, table string) ([]ColumnSecurity, error)
GetColumnSecurity delegates to the column security provider
func (*CompositeSecurityProvider) GetRowSecurity ¶ added in v0.0.63
func (c *CompositeSecurityProvider) GetRowSecurity(ctx context.Context, userID int, schema, table string) (RowSecurity, error)
GetRowSecurity delegates to the row security provider
func (*CompositeSecurityProvider) Login ¶ added in v0.0.63
func (c *CompositeSecurityProvider) Login(ctx context.Context, req LoginRequest) (*LoginResponse, error)
Login delegates to the authenticator
func (*CompositeSecurityProvider) Logout ¶ added in v0.0.63
func (c *CompositeSecurityProvider) Logout(ctx context.Context, req LogoutRequest) error
Logout delegates to the authenticator
func (*CompositeSecurityProvider) RefreshToken ¶ added in v0.0.63
func (c *CompositeSecurityProvider) RefreshToken(ctx context.Context, refreshToken string) (*LoginResponse, error)
RefreshToken implements Refreshable if the authenticator supports it
func (*CompositeSecurityProvider) ValidateToken ¶ added in v0.0.63
ValidateToken implements Validatable if the authenticator supports it
type ConfigColumnSecurityProvider ¶ added in v0.0.63
type ConfigColumnSecurityProvider struct {
// contains filtered or unexported fields
}
ConfigColumnSecurityProvider provides static column security configuration
func NewConfigColumnSecurityProvider ¶ added in v0.0.63
func NewConfigColumnSecurityProvider(rules map[string][]ColumnSecurity) *ConfigColumnSecurityProvider
func (*ConfigColumnSecurityProvider) GetColumnSecurity ¶ added in v0.0.63
func (p *ConfigColumnSecurityProvider) GetColumnSecurity(ctx context.Context, userID int, schema, table string) ([]ColumnSecurity, error)
type ConfigRowSecurityProvider ¶ added in v0.0.63
type ConfigRowSecurityProvider struct {
// contains filtered or unexported fields
}
ConfigRowSecurityProvider provides static row security configuration
func NewConfigRowSecurityProvider ¶ added in v0.0.63
func NewConfigRowSecurityProvider(templates map[string]string, blocked map[string]bool) *ConfigRowSecurityProvider
func (*ConfigRowSecurityProvider) GetRowSecurity ¶ added in v0.0.63
func (p *ConfigRowSecurityProvider) GetRowSecurity(ctx context.Context, userID int, schema, table string) (RowSecurity, error)
type DatabaseAuthenticator ¶ added in v0.0.63
type DatabaseAuthenticator struct {
// contains filtered or unexported fields
}
DatabaseAuthenticator provides session-based authentication with database storage All database operations go through stored procedures for security and consistency Requires stored procedures: resolvespec_login, resolvespec_logout, resolvespec_session, resolvespec_session_update, resolvespec_refresh_token See database_schema.sql for procedure definitions
func NewDatabaseAuthenticator ¶ added in v0.0.63
func NewDatabaseAuthenticator(db *sql.DB) *DatabaseAuthenticator
func NewDatabaseAuthenticatorWithOptions ¶ added in v0.0.86
func NewDatabaseAuthenticatorWithOptions(db *sql.DB, opts DatabaseAuthenticatorOptions) *DatabaseAuthenticator
func (*DatabaseAuthenticator) Authenticate ¶ added in v0.0.63
func (a *DatabaseAuthenticator) Authenticate(r *http.Request) (*UserContext, error)
func (*DatabaseAuthenticator) ClearCache ¶ added in v0.0.86
func (a *DatabaseAuthenticator) ClearCache(token string) error
ClearCache removes a specific token from the cache or clears all cache if token is empty
func (*DatabaseAuthenticator) ClearUserCache ¶ added in v0.0.86
func (a *DatabaseAuthenticator) ClearUserCache(userID int) error
ClearUserCache removes all cache entries for a specific user ID
func (*DatabaseAuthenticator) Login ¶ added in v0.0.63
func (a *DatabaseAuthenticator) Login(ctx context.Context, req LoginRequest) (*LoginResponse, error)
func (*DatabaseAuthenticator) Logout ¶ added in v0.0.63
func (a *DatabaseAuthenticator) Logout(ctx context.Context, req LogoutRequest) error
func (*DatabaseAuthenticator) RefreshToken ¶ added in v0.0.63
func (a *DatabaseAuthenticator) RefreshToken(ctx context.Context, refreshToken string) (*LoginResponse, error)
RefreshToken implements Refreshable interface
type DatabaseAuthenticatorExample ¶ added in v0.0.63
type DatabaseAuthenticatorExample struct {
// contains filtered or unexported fields
}
func NewDatabaseAuthenticatorExample ¶ added in v0.0.63
func NewDatabaseAuthenticatorExample(db *gorm.DB) *DatabaseAuthenticatorExample
func (*DatabaseAuthenticatorExample) Authenticate ¶ added in v0.0.63
func (a *DatabaseAuthenticatorExample) Authenticate(r *http.Request) (*UserContext, error)
func (*DatabaseAuthenticatorExample) Login ¶ added in v0.0.63
func (a *DatabaseAuthenticatorExample) Login(ctx context.Context, req LoginRequest) (*LoginResponse, error)
func (*DatabaseAuthenticatorExample) Logout ¶ added in v0.0.63
func (a *DatabaseAuthenticatorExample) Logout(ctx context.Context, req LogoutRequest) error
func (*DatabaseAuthenticatorExample) RefreshToken ¶ added in v0.0.63
func (a *DatabaseAuthenticatorExample) RefreshToken(ctx context.Context, refreshToken string) (*LoginResponse, error)
Optional: Implement Refreshable interface
type DatabaseAuthenticatorOptions ¶ added in v0.0.86
type DatabaseAuthenticatorOptions struct {
// CacheTTL is the duration to cache user contexts
// Default: 5 minutes
CacheTTL time.Duration
// Cache is an optional cache instance. If nil, uses the default cache
Cache *cache.Cache
}
DatabaseAuthenticatorOptions configures the database authenticator
type DatabaseColumnSecurityProvider ¶ added in v0.0.63
type DatabaseColumnSecurityProvider struct {
// contains filtered or unexported fields
}
DatabaseColumnSecurityProvider loads column security from database All database operations go through stored procedures Requires stored procedure: resolvespec_column_security
func NewDatabaseColumnSecurityProvider ¶ added in v0.0.63
func NewDatabaseColumnSecurityProvider(db *sql.DB) *DatabaseColumnSecurityProvider
func (*DatabaseColumnSecurityProvider) GetColumnSecurity ¶ added in v0.0.63
func (p *DatabaseColumnSecurityProvider) GetColumnSecurity(ctx context.Context, userID int, schema, table string) ([]ColumnSecurity, error)
type DatabaseRowSecurityProvider ¶ added in v0.0.63
type DatabaseRowSecurityProvider struct {
// contains filtered or unexported fields
}
DatabaseRowSecurityProvider loads row security from database All database operations go through stored procedures Requires stored procedure: resolvespec_row_security
func NewDatabaseRowSecurityProvider ¶ added in v0.0.63
func NewDatabaseRowSecurityProvider(db *sql.DB) *DatabaseRowSecurityProvider
func (*DatabaseRowSecurityProvider) GetRowSecurity ¶ added in v0.0.63
func (p *DatabaseRowSecurityProvider) GetRowSecurity(ctx context.Context, userID int, schema, table string) (RowSecurity, error)
type HeaderAuthenticator ¶ added in v0.0.63
type HeaderAuthenticator struct{}
HeaderAuthenticator provides simple header-based authentication Expects: X-User-ID, X-User-Name, X-User-Level, X-Session-ID, X-Remote-ID, X-User-Roles, X-User-Email
func NewHeaderAuthenticator ¶ added in v0.0.63
func NewHeaderAuthenticator() *HeaderAuthenticator
func (*HeaderAuthenticator) Authenticate ¶ added in v0.0.63
func (a *HeaderAuthenticator) Authenticate(r *http.Request) (*UserContext, error)
func (*HeaderAuthenticator) Login ¶ added in v0.0.63
func (a *HeaderAuthenticator) Login(ctx context.Context, req LoginRequest) (*LoginResponse, error)
func (*HeaderAuthenticator) Logout ¶ added in v0.0.63
func (a *HeaderAuthenticator) Logout(ctx context.Context, req LogoutRequest) error
type HeaderAuthenticatorExample ¶ added in v0.0.63
type HeaderAuthenticatorExample struct {
}
func NewHeaderAuthenticatorExample ¶ added in v0.0.63
func NewHeaderAuthenticatorExample() *HeaderAuthenticatorExample
func (*HeaderAuthenticatorExample) Authenticate ¶ added in v0.0.63
func (a *HeaderAuthenticatorExample) Authenticate(r *http.Request) (*UserContext, error)
func (*HeaderAuthenticatorExample) Login ¶ added in v0.0.63
func (a *HeaderAuthenticatorExample) Login(ctx context.Context, req LoginRequest) (*LoginResponse, error)
func (*HeaderAuthenticatorExample) Logout ¶ added in v0.0.63
func (a *HeaderAuthenticatorExample) Logout(ctx context.Context, req LogoutRequest) error
type JWTAuthenticator ¶ added in v0.0.63
type JWTAuthenticator struct {
// contains filtered or unexported fields
}
JWTAuthenticator provides JWT token-based authentication All database operations go through stored procedures Requires stored procedures: resolvespec_jwt_login, resolvespec_jwt_logout NOTE: JWT signing/verification requires github.com/golang-jwt/jwt/v5 to be installed and imported
func NewJWTAuthenticator ¶ added in v0.0.63
func NewJWTAuthenticator(secretKey string, db *sql.DB) *JWTAuthenticator
func (*JWTAuthenticator) Authenticate ¶ added in v0.0.63
func (a *JWTAuthenticator) Authenticate(r *http.Request) (*UserContext, error)
func (*JWTAuthenticator) Login ¶ added in v0.0.63
func (a *JWTAuthenticator) Login(ctx context.Context, req LoginRequest) (*LoginResponse, error)
func (*JWTAuthenticator) Logout ¶ added in v0.0.63
func (a *JWTAuthenticator) Logout(ctx context.Context, req LogoutRequest) error
type JWTAuthenticatorExample ¶ added in v0.0.63
type JWTAuthenticatorExample struct {
// contains filtered or unexported fields
}
func NewJWTAuthenticatorExample ¶ added in v0.0.63
func NewJWTAuthenticatorExample(secretKey string, db *gorm.DB) *JWTAuthenticatorExample
func (*JWTAuthenticatorExample) Authenticate ¶ added in v0.0.63
func (a *JWTAuthenticatorExample) Authenticate(r *http.Request) (*UserContext, error)
func (*JWTAuthenticatorExample) Login ¶ added in v0.0.63
func (a *JWTAuthenticatorExample) Login(ctx context.Context, req LoginRequest) (*LoginResponse, error)
func (*JWTAuthenticatorExample) Logout ¶ added in v0.0.63
func (a *JWTAuthenticatorExample) Logout(ctx context.Context, req LogoutRequest) error
type LoginRequest ¶ added in v0.0.63
type LoginRequest struct {
Username string `json:"username"`
Password string `json:"password"`
Claims map[string]any `json:"claims"` // Additional login data
Meta map[string]any `json:"meta"` // Additional metadata to be set on user context
}
LoginRequest contains credentials for login
type LoginResponse ¶ added in v0.0.63
type LoginResponse struct {
Token string `json:"token"`
RefreshToken string `json:"refresh_token"`
User *UserContext `json:"user"`
ExpiresIn int64 `json:"expires_in"` // Token expiration in seconds
Meta map[string]any `json:"meta"` // Additional metadata to be set on user context
}
LoginResponse contains the result of a login attempt
type LogoutRequest ¶ added in v0.0.63
LogoutRequest contains information for logout
type Refreshable ¶ added in v0.0.63
type Refreshable interface {
// RefreshToken exchanges a refresh token for a new access token
RefreshToken(ctx context.Context, refreshToken string) (*LoginResponse, error)
}
Refreshable allows providers to support token refresh
type RowSecurity ¶
type RowSecurity struct {
Schema string `json:"schema"`
Tablename string `json:"tablename"`
Template string `json:"template"`
HasBlock bool `json:"has_block"`
UserID int `json:"user_id"`
}
func (*RowSecurity) GetTemplate ¶
func (m *RowSecurity) GetTemplate(pPrimaryKeyName string, pModelType reflect.Type) string
type RowSecurityProvider ¶ added in v0.0.63
type RowSecurityProvider interface {
// GetRowSecurity loads row security rules for a user and entity
GetRowSecurity(ctx context.Context, userID int, schema, table string) (RowSecurity, error)
}
RowSecurityProvider handles row-level security (filtering)
type SecurityContext ¶ added in v0.0.67
type SecurityContext interface {
GetContext() context.Context
GetUserID() (int, bool)
GetSchema() string
GetEntity() string
GetModel() interface{}
GetQuery() interface{}
SetQuery(interface{})
GetResult() interface{}
SetResult(interface{})
}
SecurityContext is a generic interface that any spec can implement to integrate with security features This interface abstracts the common security context needs across different specs
type SecurityList ¶
type SecurityList struct {
ColumnSecurityMutex sync.RWMutex
ColumnSecurity map[string][]ColumnSecurity
RowSecurityMutex sync.RWMutex
RowSecurity map[string]RowSecurity
// contains filtered or unexported fields
}
SecurityList manages security state and caching It wraps a SecurityProvider and provides caching and utility methods
func GetSecurityList ¶ added in v0.0.83
func GetSecurityList(ctx context.Context) (*SecurityList, bool)
GetSecurityList extracts the SecurityList from request context
func NewSecurityList ¶ added in v0.0.63
func NewSecurityList(provider SecurityProvider) (*SecurityList, error)
NewSecurityList creates a new security list with the given provider
func (*SecurityList) ApplyColumnSecurity ¶
func (*SecurityList) ClearSecurity ¶
func (m *SecurityList) ClearSecurity(pUserID int, pSchema, pTablename string) error
func (*SecurityList) ColumSecurityApplyOnRecord ¶
func (*SecurityList) GetRowSecurityTemplate ¶
func (m *SecurityList) GetRowSecurityTemplate(pUserID int, pSchema, pTablename string) (RowSecurity, error)
func (*SecurityList) LoadColumnSecurity ¶
func (*SecurityList) LoadRowSecurity ¶
func (m *SecurityList) LoadRowSecurity(ctx context.Context, pUserID int, pSchema, pTablename string, pOverwrite bool) (RowSecurity, error)
func (*SecurityList) Provider ¶ added in v0.0.63
func (m *SecurityList) Provider() SecurityProvider
Provider returns the underlying security provider
type SecurityProvider ¶ added in v0.0.63
type SecurityProvider interface {
Authenticator
ColumnSecurityProvider
RowSecurityProvider
}
SecurityProvider is the main interface combining all security concerns
type UserContext ¶ added in v0.0.63
type UserContext struct {
UserID int `json:"user_id"`
UserName string `json:"user_name"`
UserLevel int `json:"user_level"`
SessionID string `json:"session_id"`
SessionRID int64 `json:"session_rid"`
RemoteID string `json:"remote_id"`
Roles []string `json:"roles"`
Email string `json:"email"`
Claims map[string]any `json:"claims"`
Meta map[string]any `json:"meta"` // Additional metadata that can hold any JSON-serializable values
}
UserContext holds authenticated user information
func GetUserContext ¶ added in v0.0.63
func GetUserContext(ctx context.Context) (*UserContext, bool)
GetUserContext extracts the full user context from request context