github.com/RobustRoundRobin/quorum@v20.10.0+incompatible/plugin/security/service.go (about)

     1  package security
     2  
     3  import (
     4  	"context"
     5  	"crypto/tls"
     6  	"errors"
     7  
     8  	"github.com/jpmorganchase/quorum-security-plugin-sdk-go/proto"
     9  )
    10  
    11  type TLSConfigurationSource interface {
    12  	Get(ctx context.Context) (*tls.Config, error)
    13  }
    14  
    15  type AuthenticationManager interface {
    16  	Authenticate(ctx context.Context, token string) (*proto.PreAuthenticatedAuthenticationToken, error)
    17  	IsEnabled(ctx context.Context) (bool, error)
    18  }
    19  
    20  type AuthentiationManagerDeferFunc func() (AuthenticationManager, error)
    21  
    22  type DeferredAuthenticationManager struct {
    23  	deferFunc AuthentiationManagerDeferFunc
    24  }
    25  
    26  func (d *DeferredAuthenticationManager) Authenticate(ctx context.Context, token string) (*proto.PreAuthenticatedAuthenticationToken, error) {
    27  	am, err := d.deferFunc()
    28  	if err != nil {
    29  		return nil, err
    30  	}
    31  	return am.Authenticate(ctx, token)
    32  }
    33  
    34  func (d *DeferredAuthenticationManager) IsEnabled(ctx context.Context) (bool, error) {
    35  	am, err := d.deferFunc()
    36  	if err != nil {
    37  		return false, err
    38  	}
    39  	return am.IsEnabled(ctx)
    40  }
    41  
    42  func NewDeferredAuthenticationManager(deferFunc AuthentiationManagerDeferFunc) *DeferredAuthenticationManager {
    43  	return &DeferredAuthenticationManager{
    44  		deferFunc: deferFunc,
    45  	}
    46  }
    47  
    48  type DisabledAuthenticationManager struct {
    49  }
    50  
    51  func (*DisabledAuthenticationManager) Authenticate(ctx context.Context, token string) (*proto.PreAuthenticatedAuthenticationToken, error) {
    52  	return nil, errors.New("not supported operation")
    53  }
    54  
    55  func (*DisabledAuthenticationManager) IsEnabled(ctx context.Context) (bool, error) {
    56  	return false, nil
    57  }
    58  
    59  func NewDisabledAuthenticationManager() AuthenticationManager {
    60  	return &DisabledAuthenticationManager{}
    61  }