// NewBearerAuthRoundTripper adds the provided bearer token to a request
// unless the authorization header has already been set.
347820
func newBearerAuthRoundTripper(bearer string, rt http.RoundTripper) http.RoundTripper {
	return &bearerAuthRoundTripper{bearer, rt}
}
999611
func NewDefaultAuthenticationInfoResolverWrapper(
	proxyTransport *http.Transport,
	kubeapiserverClientConfig *rest.Config) AuthenticationInfoResolverWrapper {

	webhookAuthResolverWrapper := func(delegate AuthenticationInfoResolver) AuthenticationInfoResolver {
		return &AuthenticationInfoResolverDelegator{
			ClientConfigForFunc: func(server string) (*rest.Config, error) {
				if server == "kubernetes.default.svc" {
					return kubeapiserverClientConfig, nil
				}
				return delegate.ClientConfigFor(server)
			},
			ClientConfigForServiceFunc: func(serviceName, serviceNamespace string) (*rest.Config, error) {
				if serviceName == "kubernetes" && serviceNamespace == corev1.NamespaceDefault {
					return kubeapiserverClientConfig, nil
				}
				ret, err := delegate.ClientConfigForService(serviceName, serviceNamespace)
				if err != nil {
					return nil, err
				}
				if proxyTransport != nil && proxyTransport.DialContext != nil {
					ret.Dial = proxyTransport.DialContext
				}
				return ret, err
			},
		}
	}
	return webhookAuthResolverWrapper
}
995858
func NewBearerAuthFileRoundTripper(bearerFile string, rt http.RoundTripper) http.RoundTripper {
	return &bearerAuthFileRoundTripper{bearerFile, rt}
}
378699
func NewBearerAuthorizer(a *config.Azure, scope string) (*autorest.BearerAuthorizer, error) {
	oauthConfig, err := adal.NewOAuthConfig(azure.PublicCloud.ActiveDirectoryEndpoint, a.TenantID)
	if err != nil {
		log.Printf("Error trying to create new OAuth Config:%s\n", err)
		return nil, err
	}
	token, err := adal.NewServicePrincipalToken(*oauthConfig, a.ClientID, a.ClientSecret, scope)
	if err != nil {
		log.Printf("Error trying to create New Service Principal Token:%s", err)
		return nil, err
	}
	return autorest.NewBearerAuthorizer(token), nil
}
242678
func NewAuthenticator(router *mux.Router, ctx *Settings, log logging.Logger) AuthenticatorAPI {
	a := &authenticator{
		router: router,
		log:    log,
		formatter: render.New(render.Options{
			IndentJSON: true,
		}),
		groupDb: make(map[string][]*access.PermissionGroup_Permissions),
		expTime: ctx.ExpTime,
	}

	// Authentication store
	if ctx.AuthStore != nil {
		a.userDb = ctx.AuthStore
	} else {
		a.userDb = CreateDefaultAuthDB()
	}

	// Set token signature
	signature = ctx.Signature
	if a.expTime == 0 {
		a.expTime = defaultExpTime
		a.log.Debugf("Token expiration time claim not set, defaulting to 1 hour")
	}

	// Hash of default admin password, hashed with cost 10
	hash := "$2a$10$q5s1LP7xbCJWJlLet1g/h.rGrsHtciILps90bNRdJ.6DRekw9b.zK"
	if err := a.userDb.AddUser(admin, hash, []string{admin}); err != nil {
		a.log.Errorf("failed to add admin user: %v", err)
	}

	for _, user := range ctx.Users {
		if user.Name == admin {
			a.log.Errorf("rejected to create user-defined account named 'admin'")
			continue
		}
		if err := a.userDb.AddUser(user.Name, user.PasswordHash, user.Permissions); err != nil {
			a.log.Errorf("failed to add user %s: %v", user.Name, err)
			continue
		}
		a.log.Debug("Registered user %s, permissions: %v", user.Name, user.Permissions)
	}

	// Admin-group, available by default and always enabled for all URLs
	a.groupDb[admin] = []*access.PermissionGroup_Permissions{}

	a.registerSecurityHandlers()

	return a
}
152764
func WrapRoundTripper(f func(http.RoundTripper) http.RoundTripper) ConfigOpt {
	return func(c *Config) {
		if f != nil {
			if rt := f(c.client.Transport); rt != nil {
				c.client.Transport = rt
			}
		}
	}
}
759360
func NewWrapper(wrapperFunc func(w http.ResponseWriter, r *http.Request, routerNext http.HandlerFunc), wrapped http.HandlerFunc) http.Handler {
	return &wrapper{
		wrapperFunc: wrapperFunc,
		router:      wrapped,
	}
}
469236
func (a *Webhook) SetAuthenticationInfoResolverWrapper(wrapper webhook.AuthenticationInfoResolverWrapper) {
	a.clientManager.SetAuthenticationInfoResolverWrapper(wrapper)
}
687610
func NewBearerClient(token, base string) *Client {
	return &Client{
		ID:            "",
		Token:         token,
		Client:        defaultHttpClient,
		Base:          base,
		UploadType:    JSON,
		ErrorParser:   DefaultErrorParser,
		useBearerAuth: true,
	}
}
434285
func NewAuthenticationProviderService(ctx servicecontext.ServiceContext, config AuthenticationProviderServiceConfig) service.AuthenticationProviderService {
	return &authenticationProviderServiceImpl{
		BaseService: base.NewBaseService(ctx),
		config:      config,
	}
}
407475
func (f *OAuth2TripperFactory) NewTripper(creds *common.Credentials, provider common.Provider) (common.Tripper, error) {
	return NewOAuth2Tripper(creds, provider), nil
}
1028041
func NewReprovider(ctx context.Context, tick time.Duration, rsys routing.ContentRouting, keyProvider KeyChanFunc) *Reprovider {
	return &Reprovider{
		ctx:     ctx,
		trigger: make(chan doneFunc),
		closing: make(chan struct{}),

		rsys:        rsys,
		keyProvider: keyProvider,
		tick:        tick,
	}
}
771753
func NewRPCResponseWriter() *RPCResponseWriter {
	w := &RPCResponseWriter{
		header:     make(http.Header),
		body:       new(bytes.Buffer),
		statusCode: 200,
	}
	//w.header.Set("Content-Type", "application/octet-stream")
	return w
}
413032
func (m *tokenManager) AuthServiceAccountSigner() client.Signer {
	return &goasupport.JWTSigner{Token: m.AuthServiceAccountToken()}
}
1270999
func NewAuthenticator(subscriptionKey, authURL string) _http.Authenticator {
	// make buffered accessToken channel and pre-fill it with an expired token
	tokenChan := make(chan *accessToken, 1)
	tokenChan <- new(accessToken)

	// return new authenticator that uses the above accessToken channel
	return &authenticator{
		accessTokenProvider: newAccessTokenProvider(subscriptionKey, authURL),
		accessTokenChan:     tokenChan,
	}
}
339380
func NewHandlerWrapper(ot opentracing.Tracer) server.HandlerWrapper {
	return func(h server.HandlerFunc) server.HandlerFunc {
		return func(ctx context.Context, req server.Request, rsp interface{}) error {
			if ot == nil {
				ot = opentracing.GlobalTracer()
			}
			name := fmt.Sprintf("%s.%s", req.Service(), req.Endpoint())
			ctx, span, err := StartSpanFromContext(ctx, ot, name)
			if err != nil {
				return err
			}
			defer span.Finish()
			return h(ctx, req, rsp)
		}
	}
}
1163012
func NewMockAuthorizeRequester(ctrl *gomock.Controller) *MockAuthorizeRequester {
	mock := &MockAuthorizeRequester{ctrl: ctrl}
	mock.recorder = &MockAuthorizeRequesterMockRecorder{mock}
	return mock
}