api

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Sep 19, 2024 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AuthenticateLDAP

func AuthenticateLDAP(conn LDAPConn, cfg *LDAPConfig, login, password string) (string, error)

AuthenticateLDAP authenticates a user against an LDAP server, checks group membership, and retrieves user details. Returns the user's common name if the user is in the allowed group.

func GenerateJWTToken

func GenerateJWTToken(secretKey []byte, expInterval time.Duration) (string, error)

GenerateJWTToken generates a JWT token with an expiration interval.

func ValidateJWTToken

func ValidateJWTToken(tokenString string, secretKey []byte) error

ValidateJWTToken validates a JWT token string using a secret key. It returns an error if the token is invalid or if the signing method is not HMAC.

Types

type LDAPConfig

type LDAPConfig struct {
	Host          string   `validate:"required,hostname|ip"`     // Hostname or IP address for the LDAP server. This field is required and must contain a valid hostname or IP address.
	Port          int      `validate:"required,gte=1,lte=65535"` // Port number for the LDAP server. This field is required and the value must be between 1 and 65535.
	BaseDN        string   `validate:"required"`                 // Base Distinguished Name (BaseDN) for LDAP queries. This field is required.
	AllowedGroups []string `validate:"required,min=1"`           // List of allowed groups in LDAP. This field is required and must contain at least one element.
}

LDAPConfig contains configuration settings for connecting to an LDAP server.

func (*LDAPConfig) Validate

func (ldapc *LDAPConfig) Validate() error

Validate checks if the LDAPConfig struct is valid according to the rules defined in the struct tags. It ensures that the Host contains a valid hostname or IP, the Port is within the valid range, the BaseDN is specified, and the AllowedGroups contains at least one group.

type LDAPConn

type LDAPConn interface {
	Bind(username, password string) error
	Search(searchRequest *ldap.SearchRequest) (*ldap.SearchResult, error)
	Close()
}

LDAPConn is an interface that defines methods for binding, searching, and closing an LDAP connection.

func NewLDAPWrapper

func NewLDAPWrapper(conn *ldap.Conn) LDAPConn

NewLDAPWrapper creates a new ldapConnWrapper that wraps an existing ldap.Conn and returns it as an LDAPConn interface.

Jump to

Keyboard shortcuts

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