nsecurity

package module
v0.7.0 Latest Latest
Warning

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

Go to latest
Published: Apr 22, 2024 License: Apache-2.0 Imports: 19 Imported by: 0

README

nsecurity

license Language Build Status GoDoc Go Report Card

Documentation

Index

Constants

View Source
const (
	// RedisKeyRequestID - nfgo:reqid:{requestID}
	RedisKeyRequestID ntypes.Key = "nfgo:reqid:%s"
)
View Source
const (
	// RedisKeySignKey - nfgo:signkey:{appType}:{subject}
	RedisKeySignKey ntypes.Key = "nfgo:signkey:%s:%s"
)

Variables

This section is empty.

Functions

func InitPolicy

func InitPolicy(enforcer casbin.IEnforcer, securityConfig *SecurityConfig, rules [][]string) error

InitPolicy -

func MustNewEnforcer

func MustNewEnforcer(securityConfig *SecurityConfig, db *gorm.DB) casbin.IEnforcer

MustNewEnforcer -

func NewEnforcer

func NewEnforcer(securityConfig *SecurityConfig, db *gorm.DB) (casbin.IEnforcer, error)

NewEnforcer -

Types

type AuthTicket

type AuthTicket struct {
	ClientType string
	RequestID  string
	Token      string
	Subject    string
	Timestamp  string
	Signature  string
}

AuthTicket -

func (*AuthTicket) VerifySignature

func (a *AuthTicket) VerifySignature(signKey string) bool

VerifySignature -

func (*AuthTicket) VerifyTimeWindow

func (a *AuthTicket) VerifyTimeWindow(timeWindow time.Duration) error

VerifyTimeWindow - check IsoverTimeWindow clientTs milliseconds since January 1, 1970 UTC.

func (*AuthTicket) VerifyToken

func (a *AuthTicket) VerifyToken(validateFn func(token string) (*JWTPayload, error)) error

VerifyToken -

type JWTConfig

type JWTConfig struct {
	JWTPublicKey  string `yaml:"jwtPublicKey"`
	JWTPrivateKey string `yaml:"jwtPrivateKey"`
}

type JWTOper

type JWTOper interface {
	IssueToken(subject string, expiration time.Time, set map[string]interface{}) (string, error)

	ParseToken(token string) (*JWTPayload, error)

	ValidateToken(token string) (*JWTPayload, error)
}

func MustNewJWTOper

func MustNewJWTOper(config *SecurityConfig) JWTOper

func NewJWTOper

func NewJWTOper(config *SecurityConfig) (JWTOper, error)

type JWTPayload

type JWTPayload struct {
	Subject string
	Expires time.Time
	Set     map[string]interface{}
}

type ReplayChecker

type ReplayChecker interface {
	VerifyReplay(requestID string) error
}

ReplayChecker -

func NewRedisReplayChecker

func NewRedisReplayChecker(redisOper ndb.RedisOper, securityConfig *SecurityConfig) ReplayChecker

NewRedisReplayChecker -

type SecurityConfig

type SecurityConfig struct {
	JWT                *JWTConfig    `yaml:"jwt"`
	SignKeyLifeTime    time.Duration `yaml:"signKeyLifeTime"`
	RefreshSignKeyLife bool          `yaml:"refreshSignKeyLife"`
	TimeWindow         time.Duration `yaml:"timeWindow"`
	Anons              []string      `yaml:"anons"`
	Model              string        `yaml:"model"`
	Policies           []string      `yaml:"policies"`
}

SecurityConfig -

func (*SecurityConfig) SetDefaultValues

func (conf *SecurityConfig) SetDefaultValues()

SetDefaultValues -

type SignKeyStore

type SignKeyStore interface {
	Store(clientType, subject, signKey string) error
	Get(clientType, subject string) (string, error)
}

SignKeyStore -

func NewRedisSignKeyStore

func NewRedisSignKeyStore(redisOper ndb.RedisOper, securityConfig *SecurityConfig) SignKeyStore

NewRedisSignKeyStore -

Jump to

Keyboard shortcuts

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