validator

package
v2.7.3 Latest Latest
Warning

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

Go to latest
Published: Mar 26, 2024 License: Apache-2.0 Imports: 28 Imported by: 0

Documentation

Overview

Package validator provides Validator filter to validates HTTP requests.

Index

Constants

View Source
const (
	// Kind is the kind of Validator.
	Kind = "Validator"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type AuthorizedUsersCache

type AuthorizedUsersCache interface {
	Match(string, string) bool
	WatchChanges()
	Close()
}

AuthorizedUsersCache provides cached lookup for authorized users.

type BasicAuthValidator

type BasicAuthValidator struct {
	// contains filtered or unexported fields
}

BasicAuthValidator defines the Basic Auth validator

func NewBasicAuthValidator

func NewBasicAuthValidator(spec *BasicAuthValidatorSpec, supervisor *supervisor.Supervisor) *BasicAuthValidator

NewBasicAuthValidator creates a new Basic Auth validator

func (*BasicAuthValidator) Close

func (bav *BasicAuthValidator) Close()

Close closes authorizedUsersCache.

func (*BasicAuthValidator) Validate

func (bav *BasicAuthValidator) Validate(req *httpprot.Request) error

Validate validates the Authorization header of a http request

type BasicAuthValidatorSpec

type BasicAuthValidatorSpec struct {
	Mode string `json:"mode,omitempty" jsonschema:"enum=FILE,enum=ETCD,enum=LDAP"`
	// Required for 'FILE' mode.
	// UserFile is path to file containing encrypted user credentials in apache2-utils/htpasswd format.
	// To add user `userY`, use `sudo htpasswd /etc/apache2/.htpasswd userY`
	// Reference: https://manpages.debian.org/testing/apache2-utils/htpasswd.1.en.html#EXAMPLES
	UserFile string `json:"userFile,omitempty"`
	// Required for 'ETCD' mode.
	// When EtcdPrefix is specified, verify user credentials from etcd. Etcd should store them:
	// key: /custom-data/{etcdPrefix}/{$key}
	// value:
	//   key: "$key"
	//   username: "$username" # optional
	//   password: "$password"
	// Username and password are used for Basic Authentication. If "username" is empty, the value of "key"
	// entry is used as username for Basic Auth.
	EtcdPrefix string `json:"etcdPrefix,omitempty"`
	// Required for 'LDAP' mode.
	LDAP *ldapSpec `json:"ldap,omitempty" jsonshema:"omitempty"`
}

BasicAuthValidatorSpec defines the configuration of Basic Auth validator. There are 'file' and 'etcd' modes.

type JWTValidator

type JWTValidator struct {
	// contains filtered or unexported fields
}

JWTValidator defines the JWT validator

func NewJWTValidator

func NewJWTValidator(spec *JWTValidatorSpec) *JWTValidator

NewJWTValidator creates a new JWT validator

func (*JWTValidator) Validate

func (v *JWTValidator) Validate(req *httpprot.Request) error

Validate validates the JWT token of a http request

type JWTValidatorSpec

type JWTValidatorSpec struct {
	Algorithm string `` /* 139-byte string literal not displayed */
	// PublicKey is in hex encoding
	PublicKey string `json:"publicKey" jsonschema:"pattern=^$|^[A-Fa-f0-9]+$"`
	// Secret is in hex encoding
	Secret string `json:"secret" jsonschema:"pattern=^$|^[A-Fa-f0-9]+$"`
	// CookieName specifies the name of a cookie, if not empty, and the cookie with
	// this name both exists and has a non-empty value, its value is used as token
	// string, the Authorization header is used to get the token string otherwise.
	CookieName string `json:"cookieName,omitempty"`
}

JWTValidatorSpec defines the configuration of JWT validator

type OAuth2JWT

type OAuth2JWT struct {
	Algorithm string `json:"algorithm" jsonschema:"enum=HS256,enum=HS384,enum=HS512"`
	// Secret is in hex encoding
	Secret string `json:"secret" jsonschema:"required,pattern=^[A-Fa-f0-9]+$"`
	// contains filtered or unexported fields
}

OAuth2JWT defines the validator configuration for OAuth2 self encoded access token

type OAuth2TokenIntrospect

type OAuth2TokenIntrospect struct {
	EndPoint     string `json:"endPoint" jsonschema:"required"`
	BasicAuth    string `json:"basicAuth,omitempty"`
	ClientID     string `json:"clientId,omitempty"`
	ClientSecret string `json:"clientSecret,omitempty"`
	InsecureTLS  bool   `json:"insecureTls,omitempty"`
}

OAuth2TokenIntrospect defines the validator configuration for OAuth2 token introspection

type OAuth2Validator

type OAuth2Validator struct {
	// contains filtered or unexported fields
}

OAuth2Validator defines the OAuth2 validator

func NewOAuth2Validator

func NewOAuth2Validator(spec *OAuth2ValidatorSpec) *OAuth2Validator

NewOAuth2Validator creates a new OAuth2 validator

func (*OAuth2Validator) Validate

func (v *OAuth2Validator) Validate(req *httpprot.Request) error

Validate validates the access token of a http request

type OAuth2ValidatorSpec

type OAuth2ValidatorSpec struct {
	TokenIntrospect *OAuth2TokenIntrospect `json:"tokenIntrospect,omitempty"`
	JWT             *OAuth2JWT             `json:"jwt,omitempty"`
}

OAuth2ValidatorSpec defines the configuration of OAuth2 validator

type Spec

type Spec struct {
	filters.BaseSpec `json:",inline"`

	Headers   *httpheader.ValidatorSpec `json:"headers,omitempty"`
	JWT       *JWTValidatorSpec         `json:"jwt,omitempty"`
	Signature *signer.Spec              `json:"signature,omitempty"`
	OAuth2    *OAuth2ValidatorSpec      `json:"oauth2,omitempty"`
	BasicAuth *BasicAuthValidatorSpec   `json:"basicAuth,omitempty"`
}

Spec describes the Validator.

func (Spec) Validate

func (spec Spec) Validate() error

Validate verifies that at least one of the validations is defined.

type Validator

type Validator struct {
	// contains filtered or unexported fields
}

Validator is filter Validator.

func (*Validator) Close

func (v *Validator) Close()

Close closes validations.

func (*Validator) Handle

func (v *Validator) Handle(ctx *context.Context) string

Handle validates the request in the context.

func (*Validator) Inherit

func (v *Validator) Inherit(previousGeneration filters.Filter)

Inherit inherits previous generation of Validator.

func (*Validator) Init

func (v *Validator) Init()

Init initializes Validator.

func (*Validator) Kind

func (v *Validator) Kind() *filters.Kind

Kind returns the kind of Validator.

func (*Validator) Name

func (v *Validator) Name() string

Name returns the name of the Validator filter instance.

func (*Validator) Spec

func (v *Validator) Spec() filters.Spec

Spec returns the spec used by the Validator

func (*Validator) Status

func (v *Validator) Status() interface{}

Status returns status.

Jump to

Keyboard shortcuts

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