Skip to content

Commit

Permalink
Authorization
Browse files Browse the repository at this point in the history
  • Loading branch information
harture committed Apr 18, 2019
1 parent f5511a0 commit 4005903
Show file tree
Hide file tree
Showing 14 changed files with 1,662 additions and 40 deletions.
20 changes: 5 additions & 15 deletions Gopkg.lock

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

25 changes: 13 additions & 12 deletions api/management/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,19 @@ import (
)

type UserRepresentation struct {
Id *string `json:"id,omitempty"`
Username *string `json:"username,omitempty"`
Email *string `json:"email,omitempty"`
Enabled *bool `json:"enabled,omitempty"`
EmailVerified *bool `json:"emailVerified,omitempty"`
FirstName *string `json:"firstName,omitempty"`
LastName *string `json:"lastName,omitempty"`
MobilePhone *string `json:"mobilePhone,omitempty"`
Label *string `json:"label,omitempty"`
Gender *string `json:"gender,omitempty"`
BirthDate *string `json:"birthDate,omitempty"`
CreatedTimestamp *int64 `json:"createdTimestamp,omitempty"`
Id *string `json:"id,omitempty"`
Username *string `json:"username,omitempty"`
Email *string `json:"email,omitempty"`
Enabled *bool `json:"enabled,omitempty"`
EmailVerified *bool `json:"emailVerified,omitempty"`
FirstName *string `json:"firstName,omitempty"`
LastName *string `json:"lastName,omitempty"`
MobilePhone *string `json:"mobilePhone,omitempty"`
Label *string `json:"label,omitempty"`
Gender *string `json:"gender,omitempty"`
BirthDate *string `json:"birthDate,omitempty"`
Groups *[]string `json:"group,omitempty"`
CreatedTimestamp *int64 `json:"createdTimestamp,omitempty"`
}

type RealmRepresentation struct {
Expand Down
6 changes: 3 additions & 3 deletions api/management/swagger-api_management.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ paths:
get:
tags:
- Clients
summary: Update an existing pet
summary: Get representation of the client
parameters:
- name: realm
in: path
Expand Down Expand Up @@ -461,7 +461,7 @@ paths:
get:
tags:
- Roles
summary: Get all roles for the realm or client
summary: Get all roles for the realm
parameters:
- name: realm
in: path
Expand Down Expand Up @@ -507,7 +507,7 @@ paths:
get:
tags:
- Roles
summary: Get all roles for the realm or client
summary: Get all clients roles
parameters:
- name: realm
in: path
Expand Down
28 changes: 27 additions & 1 deletion cmd/keycloakb/keycloak_bridge.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"encoding/json"
"fmt"
"io"
"io/ioutil"
"math/rand"
"net/http"
"net/http/pprof"
Expand All @@ -15,6 +16,8 @@ import (
"syscall"
"time"

"github.com/cloudtrust/keycloak-bridge/internal/security"

"github.com/cloudtrust/keycloak-bridge/internal/idgenerator"
gen "github.com/cloudtrust/keycloak-bridge/internal/idgenerator"
"github.com/cloudtrust/keycloak-bridge/internal/keycloakb"
Expand Down Expand Up @@ -82,7 +85,8 @@ func main() {
var c = config(log.With(logger, "unit", "config"))
var (
// Component
httpAddr = c.GetString("component-http-host-port")
httpAddr = c.GetString("component-http-host-port")
authorizationConfigFile = c.GetString("authorization-file")

// Keycloak
keycloakConfig = keycloak.Config{
Expand Down Expand Up @@ -183,6 +187,24 @@ func main() {
}
}

// Authorization Manager
var authorizationManager security.AuthorizationManager
{
json, err := ioutil.ReadFile(authorizationConfigFile)

if err != nil {
logger.Log("msg", "could not read JSON authorization file", "error", err)
return
}

authorizationManager, err = security.NewAuthorizationManager(keycloakClient, string(json))

if err != nil {
logger.Log("msg", "could not load authorizations", "error", err)
return
}
}

// Sentry.
type Sentry interface {
CaptureError(err error, tags map[string]string, interfaces ...sentry.Interface) string
Expand Down Expand Up @@ -356,6 +378,7 @@ func main() {
var keycloakComponent management.Component
{
keycloakComponent = management.NewComponent(keycloakClient, eventsDBModule)
keycloakComponent = management.MakeAuthorizationManagementComponentMW(log.With(managementLogger, "mw", "endpoint"), keycloakClient, authorizationManager)(keycloakComponent)
}

managementEndpoints = management.Endpoints{
Expand Down Expand Up @@ -540,6 +563,7 @@ func config(logger log.Logger) *viper.Viper {

// Component default.
v.SetDefault("config-file", "./configs/keycloak_bridge.yml")
v.SetDefault("authorization-file", "./configs/authorization.json")
v.SetDefault("component-http-host-port", "0.0.0.0:8888")

// CORS configuration
Expand Down Expand Up @@ -603,7 +627,9 @@ func config(logger log.Logger) *viper.Viper {

// First level of override.
pflag.String("config-file", v.GetString("config-file"), "The configuration file path can be relative or absolute.")
pflag.String("authorization-file", v.GetString("authorization-file"), "The authorization file path can be relative or absolute.")
v.BindPFlag("config-file", pflag.Lookup("config-file"))
v.BindPFlag("authorization-file", pflag.Lookup("authorization-file"))
pflag.Parse()

// Load and log config.
Expand Down

0 comments on commit 4005903

Please sign in to comment.