Skip to content

Commit

Permalink
Merge pull request #42 from islax/addPolicyToToken
Browse files Browse the repository at this point in the history
Add policy and partner to token
  • Loading branch information
kn-cyberinc authored Dec 8, 2021
2 parents 462ee31 + 7a324a8 commit 644e059
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 16 deletions.
8 changes: 8 additions & 0 deletions context/ExecutionContext.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,14 @@ func NewExecutionContext(token *security.JwtToken, correlationID string, action
executionCtxLogger = executionCtxLogger.With().Str("externalIdType", token.ExternalIDType).Logger()
}

if token.PolicyID != uuid.Nil {
executionCtxLogger = executionCtxLogger.With().Str("policyId", token.PolicyID.String()).Logger()
}

if token.PartnerID != uuid.Nil {
executionCtxLogger = executionCtxLogger.With().Str("partnerId", token.PartnerID.String()).Logger()
}

} else {
executionCtxLogger = logger.With().
Str("action", action).
Expand Down
24 changes: 14 additions & 10 deletions security/Token.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,24 @@ package security
import (
"strings"

jwt "github.com/golang-jwt/jwt"
"github.com/golang-jwt/jwt"
uuid "github.com/satori/go.uuid"
)

// Appliance ExternalID Type
const Appliance = "Appliance"

// Session ExternalID Type
const Session = "Session"

// User ExternalID Type
const User = "User"
const (
// ApplianceExternalIdType indicates Appliance ExternalID Type
ApplianceExternalIdType = "Appliance"
// SessionExternalIdType indicates Session ExternalID Type
SessionExternalIdType = "Session"
// UserExternalIdType indicates User ExternalID Type
UserExternalIdType = "User"
// PartnerExternalIdType indicates Partner ExternalID Type
PartnerExternalIdType = "Partner"
)

// JwtToken represents the parsed Token from Authentication Header
type JwtToken struct {
// UserID is id of user matchimg the token
// UserID is id of user matching the token
UserID uuid.UUID `json:"user,omitempty"`
UserName string `json:"name,omitempty"`
DisplayName string `json:"displayName,omitempty"`
Expand All @@ -29,6 +31,8 @@ type JwtToken struct {
ExternalIDType string `json:"externalIdType,omitempty"`
Scopes []string `json:"scope,omitempty"`
Admin bool `json:"admin,omitempty"`
PolicyID uuid.UUID `json:"policyId,omitempty"` // PolicyID is id of policy matching the token
PartnerID uuid.UUID `json:"partnerId,omitempty"` // PartnerID is id of partner matching the token
Raw string `json:"-"`
jwt.StandardClaims
}
Expand Down
15 changes: 9 additions & 6 deletions settingsmetadata/controllers/SettingsMetadataController.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,18 @@ type SettingsMetadataController struct {
// RegisterRoutes implements interface RouteSpecifier
func (controller *SettingsMetadataController) RegisterRoutes(muxRouter *mux.Router) {
apiRouter := muxRouter.PathPrefix("/api").Subrouter()
policySettingsRouter := apiRouter.PathPrefix(fmt.Sprintf("/%s", strings.ToLower(controller.app.Name))).Subrouter()

settingsMetadataRouter := policySettingsRouter.PathPrefix("/settings-metadata").Subrouter()
settingsMetadataRouter := apiRouter.PathPrefix(fmt.Sprintf("/%s/settings-metadata", strings.ToLower(controller.app.Name))).Subrouter()
settingsMetadataRouter.HandleFunc("", microappSecurity.Protect(controller.app.Config, controller.getSettingsMetadata, []string{"settingsmetadata:read"}, false)).Methods("GET")

tenantSettingsRouter := policySettingsRouter.PathPrefix("/tenants/{id}/settings").Subrouter()
tenantSettingsRouter.HandleFunc("", microappSecurity.Protect(controller.app.Config, controller.get, []string{"tenantSettings:read"}, false)).Methods("GET")
tenantSettingsRouter.HandleFunc("", microappSecurity.Protect(controller.app.Config, controller.update, []string{"tenantSettings:write"}, false)).Methods("PUT")
tenantSettingsRouter.HandleFunc("/{settingName}", microappSecurity.Protect(controller.app.Config, controller.getByName, []string{"tenantSettings:read"}, false)).Methods("GET")
pathLabel := strings.ToLower(controller.app.Name)
if strings.ToLower(controller.app.Name) == "tenant" {
pathLabel = "general"
}
settingsRouter := apiRouter.PathPrefix(fmt.Sprintf("/tenants/{id}/%s-settings", pathLabel)).Subrouter()
settingsRouter.HandleFunc("", microappSecurity.Protect(controller.app.Config, controller.get, []string{"tenantSettings:read"}, false)).Methods("GET")
settingsRouter.HandleFunc("", microappSecurity.Protect(controller.app.Config, controller.update, []string{"tenantSettings:write"}, false)).Methods("PUT")
settingsRouter.HandleFunc("/{settingName}", microappSecurity.Protect(controller.app.Config, controller.getByName, []string{"tenantSettings:read"}, false)).Methods("GET")

}

Expand Down

0 comments on commit 644e059

Please sign in to comment.