package service

import (
	
	
	

	
	
)

// Settings defines service side configuration settings.
type Settings struct {
	Keytab             *keytab.Keytab
	ktprinc            *types.PrincipalName
	sname              string
	requireHostAddr    bool
	disablePACDecoding bool
	cAddr              types.HostAddress
	maxClockSkew       time.Duration
	logger             *log.Logger
	sessionMgr         SessionMgr
}

// NewSettings creates a new service Settings.
func ( *keytab.Keytab,  ...func(*Settings)) *Settings {
	 := new(Settings)
	.Keytab = 
	for ,  := range  {
		()
	}
	return 
}

// RequireHostAddr used to configure service side to required host addresses to be specified in Kerberos tickets.
//
// s := NewSettings(kt, RequireHostAddr(true))
func ( bool) func(*Settings) {
	return func( *Settings) {
		.requireHostAddr = 
	}
}

// RequireHostAddr indicates if the service should require the host address to be included in the ticket.
func ( *Settings) () bool {
	return .requireHostAddr
}

// DecodePAC used to configure service side to enable/disable PAC decoding if the PAC is present.
// Defaults to enabled if not specified.
//
// s := NewSettings(kt, DecodePAC(false))
func ( bool) func(*Settings) {
	return func( *Settings) {
		.disablePACDecoding = !
	}
}

// DecodePAC indicates whether the service should decode any PAC information present in the ticket.
func ( *Settings) () bool {
	return !.disablePACDecoding
}

// ClientAddress used to configure service side with the clients host address to be used during validation.
//
// s := NewSettings(kt, ClientAddress(h))
func ( types.HostAddress) func(*Settings) {
	return func( *Settings) {
		.cAddr = 
	}
}

// ClientAddress returns the client host address which has been provided to the service.
func ( *Settings) () types.HostAddress {
	return .cAddr
}

// Logger used to configure service side with a logger.
//
// s := NewSettings(kt, Logger(l))
func ( *log.Logger) func(*Settings) {
	return func( *Settings) {
		.logger = 
	}
}

// Logger returns the logger instances configured for the service. If none is configured nill will be returned.
func ( *Settings) () *log.Logger {
	return .logger
}

// KeytabPrincipal used to override the principal name used to find the key in the keytab.
//
// s := NewSettings(kt, KeytabPrincipal("someaccount"))
func ( string) func(*Settings) {
	return func( *Settings) {
		,  := types.ParseSPNString()
		.ktprinc = &
	}
}

// KeytabPrincipal returns the principal name used to find the key in the keytab if it has been overridden.
func ( *Settings) () *types.PrincipalName {
	return .ktprinc
}

// MaxClockSkew used to configure service side with the maximum acceptable clock skew
// between the service and the issue time of kerberos tickets
//
// s := NewSettings(kt, MaxClockSkew(d))
func ( time.Duration) func(*Settings) {
	return func( *Settings) {
		.maxClockSkew = 
	}
}

// MaxClockSkew returns the maximum acceptable clock skew between the service and the issue time of kerberos tickets.
// If none is defined a duration of 5 minutes is returned.
func ( *Settings) () time.Duration {
	if .maxClockSkew.Nanoseconds() == 0 {
		return time.Duration(5) * time.Minute
	}
	return .maxClockSkew
}

// SName used provide a specific service name to the service settings.
//
// s := NewSettings(kt, SName("HTTP/some.service.com"))
func ( string) func(*Settings) {
	return func( *Settings) {
		.sname = 
	}
}

// SName returns the specific service name to the service.
func ( *Settings) () string {
	return .sname
}

// SessionManager configures a session manager to establish sessions with clients to avoid excessive authentication challenges.
//
// s := NewSettings(kt, SessionManager(sm))
func ( SessionMgr) func(*Settings) {
	return func( *Settings) {
		.sessionMgr = 
	}
}

// SessionManager returns any configured session manager.
func ( *Settings) () SessionMgr {
	return .sessionMgr
}

// SessionMgr must provide a ways to:
//
// - Create new sessions and in the process add a value to the session under the key provided.
//
// - Get an existing session returning the value in the session under the key provided.
// Return nil bytes and/or error if there is no session.
type SessionMgr interface {
	New(w http.ResponseWriter, r *http.Request, k string, v []byte) error
	Get(r *http.Request, k string) ([]byte, error)
}