コード例 #1
0
ファイル: context.go プロジェクト: shawnps/martian
// FromContext retrieves the auth.Context from the session.
func FromContext(ctx *martian.Context) *Context {
	if v, ok := ctx.Session().Get(key); ok {
		return v.(*Context)
	}

	actx := &Context{}
	ctx.Session().Set(key, actx)

	return actx
}
コード例 #2
0
ファイル: ipauth.go プロジェクト: eolexe/martian
// ModifyResponse runs cresmod.ModifyResponse and checks ctx.Auth.Error for
// application specific auth failure.
//
// If an error is returned from resmod.ModifyResponse it is returned.
func (m *Modifier) ModifyResponse(ctx *martian.Context, res *http.Response) error {
	if m.resmod != nil {
		if err := m.resmod.ModifyResponse(ctx, res); err != nil {
			return err
		}
	}

	if err := ctx.Auth.Error; err != nil {
		ctx.Auth.Reset()
		ctx.SkipRoundTrip = false
		return err
	}

	return nil
}
コード例 #3
0
ファイル: proxyauth.go プロジェクト: eolexe/martian
// ModifyRequest sets the auth ID in the context from the request iff it has
// not already been set and runs reqmod.ModifyRequest. If the underlying
// modifier has indicated via ctx.Auth.Error that no valid auth credentials
// have been found we set ctx.SkipRoundTrip.
func (m *Modifier) ModifyRequest(ctx *martian.Context, req *http.Request) error {
	ctx.Auth.ID = id(req.Header)

	if m.reqmod == nil {
		return nil
	}

	if err := m.reqmod.ModifyRequest(ctx, req); err != nil {
		return err
	}

	if ctx.Auth.Error != nil {
		ctx.SkipRoundTrip = true
	}

	return nil
}
コード例 #4
0
ファイル: proxyauth.go プロジェクト: eolexe/martian
// ModifyResponse runs resmod.ModifyResponse and modifies the response to
// include the correct status code and headers if ctx.Auth.Error is present.
//
// If an error is returned from resmod.ModifyResponse it is returned.
func (m *Modifier) ModifyResponse(ctx *martian.Context, res *http.Response) error {
	var err error

	if m.resmod != nil {
		err = m.resmod.ModifyResponse(ctx, res)
	}

	if ctx.Auth.Error != nil {
		// Reset the auth so we don't get stuck in a failed auth loop
		// when dealing with Keep-Alive.
		ctx.Auth.Reset()
		ctx.SkipRoundTrip = false

		res.StatusCode = http.StatusProxyAuthRequired
		res.Header.Set("Proxy-Authenticate", "Basic")
	}

	return err
}
コード例 #5
0
ファイル: ipauth.go プロジェクト: eolexe/martian
// ModifyRequest sets the auth ID in the context from the request iff it has
// not already been set and runs reqmod.ModifyRequest. If the underlying
// modifier has indicated via ctx.Auth.Error that no valid auth credentials
// have been found we set ctx.SkipRoundTrip.
func (m *Modifier) ModifyRequest(ctx *martian.Context, req *http.Request) error {
	ip, _, err := net.SplitHostPort(req.RemoteAddr)
	if err != nil {
		ip = req.RemoteAddr
	}

	ctx.Auth.ID = ip

	if m.reqmod == nil {
		return nil
	}

	if err := m.reqmod.ModifyRequest(ctx, req); err != nil {
		return err
	}

	if ctx.Auth.Error != nil {
		ctx.SkipRoundTrip = true
	}

	return nil
}
コード例 #6
0
ファイル: body_modifier.go プロジェクト: eolexe/martian
// ModifyRequest signals to the proxy to skip the roundtrip.
func (m *Modifier) ModifyRequest(ctx *martian.Context, req *http.Request) error {
	ctx.SkipRoundTrip = true

	return nil
}