auth

package
v1.0.5 Latest Latest
Warning

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

Go to latest
Published: Nov 11, 2023 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Dial

func Dial(opts *DialOptions) (conn net.Conn, err error)

Dial in

func ListSupportedAuthTypes

func ListSupportedAuthTypes(quote bool) []string

Types

type AuthType

type AuthType int
const (
	UNAUTHENTICATED AuthType = iota + 1
	SIMPLE
	MD5
	NTLM
)

func TypeFromString

func TypeFromString(str string) AuthType

Parse type from string

func (AuthType) IsValid

func (t AuthType) IsValid() bool

Validate type

func (AuthType) String

func (t AuthType) String() string

Type as string

type BindParameters

type BindParameters struct {
	// Type of authentication
	AuthType AuthType `validate:"required,is_valid"` // default: SIMPLE
	// User's domain (required for NTLM authentication)
	Domain string `validate:"required_if=AuthType NTLM"`
	// User's password
	Password string `validate:"required_unless=AuthType UNAUTHENTICATED"`
	// Username
	User string `validate:"required_unless=AuthType UNAUTHENTICATED"`
}

Bind parameters

func NewBindParameters

func NewBindParameters() *BindParameters

Create new bind parameters

func (*BindParameters) SetDefaults

func (p *BindParameters) SetDefaults()

Set default Type

func (*BindParameters) SetDomain

func (p *BindParameters) SetDomain(domain string) *BindParameters

Set domain (required for NTLM-based authentication)

func (*BindParameters) SetPassword

func (p *BindParameters) SetPassword(password string) *BindParameters

Set password

func (*BindParameters) SetType

func (p *BindParameters) SetType(authType AuthType) *BindParameters

Set authentication type

func (*BindParameters) SetUser

func (p *BindParameters) SetUser(user string) *BindParameters

Set username

func (*BindParameters) Validate

func (p *BindParameters) Validate() error

Validate fields

type Connection

type Connection struct {
	*ldap.Conn
	*DialOptions
	// contains filtered or unexported fields
}

Connection object

func Bind

func Bind(parameters *BindParameters, options *DialOptions) (*Connection, error)

Establish connection with the server

func (Connection) Close

func (c Connection) Close() error

func (Connection) RemoteHost

func (c Connection) RemoteHost() string

type DialOptions

type DialOptions struct {
	// Number of max retries if failing
	MaxRetries uint `validate:"required" default:"3"`
	// Limits number of objects returned by an LDAP query
	SizeLimit int64
	// Timeout for connection handshake and LDAP queries
	TimeLimit time.Duration `validate:"required" default:"10s"`
	// Custom TLS config
	TLSConfig *tls.Config
	// Server URL
	URL *URL `validate:"required,is_valid"` // default: ldap://localhost:389
}

Options for dialer

func NewDialOptions

func NewDialOptions() *DialOptions

Create new dial-in options

func (*DialOptions) SetDefaults

func (o *DialOptions) SetDefaults()

Sets default URL

func (*DialOptions) SetMaxRetries

func (o *DialOptions) SetMaxRetries(retries uint) *DialOptions

Set max retries

func (*DialOptions) SetSizeLimit

func (o *DialOptions) SetSizeLimit(limit int64) *DialOptions

Set size limit

func (*DialOptions) SetTLSConfig

func (o *DialOptions) SetTLSConfig(conf *tls.Config) *DialOptions

Set custom TLS config

func (*DialOptions) SetTimeLimit

func (o *DialOptions) SetTimeLimit(limit time.Duration) *DialOptions

Set time limit

func (*DialOptions) SetURL

func (o *DialOptions) SetURL(addr string) *DialOptions

Set URL

func (*DialOptions) Validate

func (o *DialOptions) Validate() error

Validate fields

type Port

type Port int
const (
	// Local catalogue port
	LDAP_RW Port = 389
	// Global catalogue port
	LDAP_RO Port = 3268
	// Local catalogue port over TLS
	LDAPS_RW Port = 636
	// Global catalogue port over TLS
	LDAPS_RO Port = 3269
)

type Scheme

type Scheme string
const (
	LDAP  Scheme = "ldap"
	LDAPS Scheme = "ldaps"
)

func (Scheme) IsValid

func (s Scheme) IsValid() bool

Validate scheme

type URL

type URL struct {
	// Scheme
	Scheme Scheme `validate:"required,is_valid"`
	// Server's domain name
	Host string `validate:"required"`
	// Server's port
	Port Port `validate:"required,gt=0"`
}

Server's URL

func NewURL

func NewURL() *URL

Make empty URL

func URLFromString

func URLFromString(in string) (*URL, error)

Parse URL from string matching <scheme>://<hostname>:<port>

func (URL) HostPort

func (u URL) HostPort() string

Get server's hostname and port in form <hostname>:<port>

func (URL) IsValid

func (u URL) IsValid() bool

Implement util.ValidatorInterface

func (*URL) SetHost

func (u *URL) SetHost(h string) *URL

Set hostname

func (*URL) SetPort

func (u *URL) SetPort(p Port) *URL

Set port

func (*URL) SetScheme

func (u *URL) SetScheme(s Scheme) *URL

Set scheme

func (URL) String

func (u URL) String() string

Render URL as <scheme>://<hostname>:<port>

func (URL) ToBaseDirectoryPath

func (u URL) ToBaseDirectoryPath() string

Build base DN from host

func (*URL) Validate

func (u *URL) Validate() error

Validate fields

Jump to

Keyboard shortcuts

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