middleware

package
v0.0.0-...-d841f61 Latest Latest
Warning

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

Go to latest
Published: Jun 11, 2021 License: AGPL-3.0 Imports: 21 Imported by: 0

Documentation

Index

Constants

View Source
const (
	CacheControlHeaderKey          = "Cache-Control"
	DefaultCacheControlHeaderValue = "public, no-cache"
)
View Source
const AuthorizedIds = "authorized_ids"

Variables

View Source
var (
	MissingUserKeyPanicMsg = "Key \"" + auth.UserKey + "\" does not exist"
)

Functions

func Auth

func Auth(providers []security.HttpProvider) gin.HandlerFunc

Auth middleware uses http providers to authenticate user. It checks auth only if request contains credentials.

func Authorize

func Authorize(
	obj string,
	act string,
	enforcer security.Enforcer,
) gin.HandlerFunc

Authorize determines if current subject has been authorized to take an action on an object. Use OnlyAuth middleware to only check if user is authenticated.

func AuthorizeByID

func AuthorizeByID(
	act string,
	enforcer security.Enforcer,
) gin.HandlerFunc

AuthorizeByID determines if current subject has been authorized to take an action on a object by id.

func Cache

func Cache() gin.HandlerFunc

Cache middleware adds default cache headers to response.

func OnlyAuth

func OnlyAuth() gin.HandlerFunc

OnlyAuth determines if user is authenticated. Use Authorize middleware to check user permissions.

func ProvideAuthorizedIds

func ProvideAuthorizedIds(
	act string,
	enforcer security.Enforcer,
) gin.HandlerFunc

ProvideAuthorizedIds determines on which objects current subject has been authorized to take an action.

func ProxyAuthorize

func ProxyAuthorize(
	enforcer security.Enforcer,
	accessConfig proxy.AccessConfig,
) gin.HandlerFunc

ProxyAuthorize determines if current subject has been authorized to take an action on an object for proxy routes.

func Recovery

func Recovery(logger zerolog.Logger) gin.HandlerFunc

Recovery recovers from any panics and if there was one it logs error and writes InternalServerError response.

func ReloadEnforcerPolicyOnChange

func ReloadEnforcerPolicyOnChange(enforcer security.Enforcer) gin.HandlerFunc

ReloadEnforcerPolicyOnChange loads security policy if request changes policy.

func SessionAuth

func SessionAuth(db mongo.DbClient, store sessions.Store) gin.HandlerFunc

SessionAuth returns a Session Authorization middleware. It checks session and retrieves user using provider. It checks auth only if session exists.

func SetAuthor

func SetAuthor() func(c *gin.Context)

SetAuthor middleware sets authorized user id to author field to request body. Use it for create and update model endpoints.

func SetAuthorToBulk

func SetAuthorToBulk() func(c *gin.Context)

SetAuthorToBulk middleware sets authorized user id to author field to bulk request body. Use it for create and update model endpoints.

Types

This section is empty.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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