Skip to content

Commit

Permalink
feat: export NewKerberosClientFunc to config for allow custom client
Browse files Browse the repository at this point in the history
Signed-off-by: fooofei <[email protected]>
  • Loading branch information
fooofei authored Jan 25, 2024
1 parent b10ee36 commit 46754c0
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 19 deletions.
4 changes: 2 additions & 2 deletions broker.go
Original file line number Diff line number Diff line change
Expand Up @@ -1295,8 +1295,8 @@ func (b *Broker) authenticateViaSASLv1() error {

func (b *Broker) sendAndReceiveKerberos() error {
b.kerberosAuthenticator.Config = &b.conf.Net.SASL.GSSAPI
if b.kerberosAuthenticator.NewKerberosClientFunc == nil {
b.kerberosAuthenticator.NewKerberosClientFunc = NewKerberosClient
if b.kerberosAuthenticator.Config.NewKerberosClientFunc == nil {
b.kerberosAuthenticator.Config.NewKerberosClientFunc = NewKerberosClient
}
return b.kerberosAuthenticator.Authorize(b)
}
Expand Down
4 changes: 2 additions & 2 deletions broker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -723,14 +723,14 @@ func TestGSSAPIKerberosAuth_Authorize(t *testing.T) {
}
mockBroker.SetGSSAPIHandler(gssapiHandler.MockKafkaGSSAPI)
if test.mockKerberosClient {
broker.kerberosAuthenticator.NewKerberosClientFunc = func(config *GSSAPIConfig) (KerberosClient, error) {
conf.Net.SASL.GSSAPI.NewKerberosClientFunc = func(config *GSSAPIConfig) (KerberosClient, error) {
return &MockKerberosClient{
mockError: test.error,
errorStage: test.errorStage,
}, nil
}
} else {
broker.kerberosAuthenticator.NewKerberosClientFunc = nil
conf.Net.SASL.GSSAPI.NewKerberosClientFunc = nil
}

err := broker.Open(conf)
Expand Down
30 changes: 15 additions & 15 deletions gssapi_kerberos.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,23 +30,23 @@ const (
)

type GSSAPIConfig struct {
AuthType int
KeyTabPath string
CCachePath string
KerberosConfigPath string
ServiceName string
Username string
Password string
Realm string
DisablePAFXFAST bool
AuthType int
KeyTabPath string
CCachePath string
KerberosConfigPath string
ServiceName string
Username string
Password string
Realm string
DisablePAFXFAST bool
NewKerberosClientFunc func(config *GSSAPIConfig) (KerberosClient, error)
}

type GSSAPIKerberosAuth struct {
Config *GSSAPIConfig
ticket messages.Ticket
encKey types.EncryptionKey
NewKerberosClientFunc func(config *GSSAPIConfig) (KerberosClient, error)
step int
Config *GSSAPIConfig
ticket messages.Ticket
encKey types.EncryptionKey
step int
}

type KerberosClient interface {
Expand Down Expand Up @@ -199,7 +199,7 @@ func (krbAuth *GSSAPIKerberosAuth) initSecContext(bytes []byte, kerberosClient K

/* This does the handshake for authorization */
func (krbAuth *GSSAPIKerberosAuth) Authorize(broker *Broker) error {
kerberosClient, err := krbAuth.NewKerberosClientFunc(krbAuth.Config)
kerberosClient, err := krbAuth.Config.NewKerberosClientFunc(krbAuth.Config)
if err != nil {
Logger.Printf("Kerberos client error: %s", err)
return err
Expand Down

0 comments on commit 46754c0

Please sign in to comment.