Skip to content
This repository has been archived by the owner on Feb 18, 2021. It is now read-only.

Commit

Permalink
Add resourceUrn to authenticate context (#212)
Browse files Browse the repository at this point in the history
  • Loading branch information
Bo Yang authored May 24, 2017
1 parent 8960e3b commit 483f350
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions services/frontendhost/frontend.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
package frontendhost

import (
"context"
"crypto/sha1"
"encoding/base64"
"fmt"
Expand Down Expand Up @@ -53,6 +54,12 @@ const (
maxSizeCacheDestinationPathForUUID = 1000
)

// ContextKey is the type for context key
type ContextKey string

// ResourceUrnKey is the context key name for resourceUrn
var ResourceUrnKey = ContextKey("resourceUrn")

var nilRequestError = &c.BadRequestError{Message: `request must not be nil`}
var badRequestKafkaConfigError = &c.BadRequestError{Message: `kafka destination must set kafka cluster and topic, and may not be multi-zone`}
var badRequestNonKafkaConfigError = &c.BadRequestError{Message: `non-Kafka destination must not set kafka cluster and topic`}
Expand Down Expand Up @@ -589,13 +596,15 @@ func (h *Frontend) CreateDestination(ctx thrift.Context, createRequest *c.Create

lclLg := h.logger.WithField(common.TagDstPth, common.FmtDstPth(createRequest.GetPath()))

authSubject, err := h.GetAuthManager().Authenticate(ctx)
authResource := common.GetResourceURNCreateDestination(h.SCommon, createRequest.Path)

authContext := context.WithValue(ctx, ResourceUrnKey, authResource)
authSubject, err := h.GetAuthManager().Authenticate(authContext)
if err != nil {
// TODO add metrics
return nil, err
}

authResource := common.GetResourceURNCreateDestination(h.SCommon, createRequest.Path)
err = h.GetAuthManager().Authorize(authSubject, common.OperationCreate, common.Resource(authResource))
if err != nil {
lclLg.WithField(common.TagSubject, authSubject).WithField(common.TagResource, authResource).Info("Not allowed to create destination")
Expand Down

0 comments on commit 483f350

Please sign in to comment.