Skip to content

Commit

Permalink
Merge 5908c2b into 5a8e85e
Browse files Browse the repository at this point in the history
  • Loading branch information
fperot74 committed May 15, 2019
2 parents 5a8e85e + 5908c2b commit 4151bcc
Show file tree
Hide file tree
Showing 38 changed files with 308 additions and 318 deletions.
77 changes: 12 additions & 65 deletions Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion Gopkg.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,11 @@
name = "github.com/gbrlsnchs/jwt"
version = "2.0.0"

[[constraint]]
name = "github.com/cloudtrust/common-service"
branch = "master"

[[constraint]]
name = "github.com/cloudtrust/keycloak-client"
source = "github.com/cloudtrust/keycloak-client"
branch = "master"
# version = "v1.0-rc1"
8 changes: 5 additions & 3 deletions internal/event/event.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package event
import (
"context"
"time"

cs "github.com/cloudtrust/common-service"
)

const (
Expand Down Expand Up @@ -42,12 +44,12 @@ func (er *ReportEventDetails) AddEventValues(values ...string) {
// AddAgentDetails add details from the context
func (er *ReportEventDetails) AddAgentDetails(ctx context.Context) {
//retrieve agent username
er.details["agent_username"] = ctx.Value("username").(string)
er.details["agent_username"] = ctx.Value(cs.CtContextUsername).(string)
//retrieve agent user id - not yet implemented
//to be uncommented once the ctx contains the userId value
//er.details["userId"] = ctx.Value("userId").(string)
//er.details["userId"] = ctx.Value(cs.CtContextUserId).(string)
//retrieve agent realm
er.details["agent_realm_name"] = ctx.Value("realm").(string)
er.details["agent_realm_name"] = ctx.Value(cs.CtContextRealm).(string)
}

// Report Report the event into the specified reporter
Expand Down
5 changes: 3 additions & 2 deletions internal/event/event_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"testing"

cs "github.com/cloudtrust/common-service"
"github.com/stretchr/testify/assert"
)

Expand Down Expand Up @@ -49,8 +50,8 @@ func TestReportEvent(t *testing.T) {

s := newStorer(t)
ctx := context.Background()
ctx = context.WithValue(ctx, "username", agentUsername)
ctx = context.WithValue(ctx, "realm", agentRealmName)
ctx = context.WithValue(ctx, cs.CtContextUsername, agentUsername)
ctx = context.WithValue(ctx, cs.CtContextRealm, agentRealmName)

ReportEvent(ctx, s, apiCall, origin, key1, value1, key2, value2)
s.assertLength(7)
Expand Down
13 changes: 7 additions & 6 deletions internal/security/authorization.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,13 @@ import (
"fmt"
"strings"

cs "github.com/cloudtrust/common-service"
kc "github.com/cloudtrust/keycloak-client"
"github.com/go-kit/kit/log"
)

func (am *authorizationManager) CheckAuthorizationOnTargetUser(ctx context.Context, action, targetRealm, userID string) error {
var accessToken = ctx.Value("access_token").(string)
var accessToken = ctx.Value(cs.CtContextAccessToken).(string)

bInfos, _ := json.Marshal(map[string]string{
"ThrownBy": "CheckAuthorizationOnTargetUser",
Expand Down Expand Up @@ -53,7 +54,7 @@ func (am *authorizationManager) CheckAuthorizationOnTargetUser(ctx context.Conte
}

func (am *authorizationManager) CheckAuthorizationOnTargetGroupID(ctx context.Context, action, targetRealm, targetGroupID string) error {
var accessToken = ctx.Value("access_token").(string)
var accessToken = ctx.Value(cs.CtContextAccessToken).(string)

bInfos, _ := json.Marshal(map[string]string{
"ThrownBy": "CheckAuthorizationOnTargetGroupID",
Expand Down Expand Up @@ -82,8 +83,8 @@ func (am *authorizationManager) CheckAuthorizationOnTargetGroupID(ctx context.Co
}

func (am *authorizationManager) CheckAuthorizationOnTargetGroup(ctx context.Context, action, targetRealm, targetGroup string) error {
var currentRealm = ctx.Value("realm").(string)
var currentGroups = ctx.Value("groups").([]string)
var currentRealm = ctx.Value(cs.CtContextRealm).(string)
var currentGroups = ctx.Value(cs.CtContextGroups).([]string)

bInfos, _ := json.Marshal(map[string]string{
"ThrownBy": "CheckAuthorizationOnTargetGroup",
Expand Down Expand Up @@ -137,8 +138,8 @@ func (am *authorizationManager) CheckAuthorizationOnTargetGroup(ctx context.Cont
}

func (am *authorizationManager) CheckAuthorizationOnTargetRealm(ctx context.Context, action, targetRealm string) error {
var currentRealm = ctx.Value("realm").(string)
var currentGroups = ctx.Value("groups").([]string)
var currentRealm = ctx.Value(cs.CtContextRealm).(string)
var currentGroups = ctx.Value(cs.CtContextGroups).([]string)

bInfos, _ := json.Marshal(map[string]string{
"ThrownBy": "CheckAuthorizationOnTargetRealm",
Expand Down

0 comments on commit 4151bcc

Please sign in to comment.