servers

package
v0.0.0-...-ca24b28 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 18, 2024 License: Apache-2.0 Imports: 24 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var UAAGetTokenKey = http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) {
	response, err := json.Marshal(map[string]string{
		"alg":   "SHA256withRSA",
		"kid":   "legacy-key-id",
		"value": ReadFile("/testing/fixtures/public.pem"),
	})
	if err != nil {
		panic(err)
	}

	w.WriteHeader(http.StatusOK)
	w.Write(response)
})
View Source
var UAAGetTokenKeys = http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) {
	response, err := json.Marshal(map[string]interface{}{
		"keys": []interface{}{
			map[string]string{
				"alg":   "SHA256withRSA",
				"kid":   "legacy-key-id",
				"value": ReadFile("/testing/fixtures/public.pem"),
			},
			map[string]string{
				"alg":   "SHA256withRSA",
				"kid":   "new-key-id",
				"value": ReadFile("/testing/fixtures/public.pem"),
			},
		},
	})
	if err != nil {
		panic(err)
	}

	w.WriteHeader(http.StatusOK)
	w.Write(response)
})
View Source
var UAAGetUser = http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) {
	userGUID := mux.Vars(req)["userGUID"]

	user, ok := UAAUsers[userGUID]
	if !ok {
		w.WriteHeader(http.StatusNotFound)
		return
	}

	response, err := json.Marshal(user)
	if err != nil {
		panic(err)
	}

	w.WriteHeader(http.StatusOK)
	w.Write(response)
})
View Source
var UAAGetUserFilter = http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) {
	err := req.ParseForm()
	if err != nil {
		panic(err)
	}

	filter := req.Form.Get("filter")
	filterParts := strings.Split(filter, " or ")
	queryRegexp := regexp.MustCompile(`Id eq "(.*)"`)
	resources := []interface{}{}
	for _, part := range filterParts {
		matches := queryRegexp.FindAllStringSubmatch(part, 1)
		match := matches[0]

		if match[1] == "user-malformed-email" {
			w.WriteHeader(http.StatusBadRequest)
			w.Write([]byte(`{}`))
			return
		}

		if user, ok := UAAUsers[match[1]]; ok {
			resources = append(resources, user)
		}
	}

	response, err := json.Marshal(map[string]interface{}{
		"resources":    resources,
		"startIndex":   1,
		"itemsPerPage": 100,
		"totalResults": 1,
		"schemas":      []string{"urn:scim:schemas:core:1.0"},
	})
	if err != nil {
		panic(err)
	}

	w.WriteHeader(http.StatusOK)
	w.Write(response)
})
View Source
var UAAGetUsers = http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) {
	response, err := json.Marshal(map[string]interface{}{
		"resources":    allUsersResponse,
		"startIndex":   1,
		"itemsPerPage": 100,
		"totalResults": 1,
		"schemas":      []string{"urn:scim:schemas:core:1.0"},
	})
	if err != nil {
		panic(err)
	}

	w.WriteHeader(http.StatusOK)
	w.Write(response)
})
View Source
var UAAGetUsersByScope = http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) {
	err := req.ParseForm()
	if err != nil {
		panic(err)
	}

	attribute := req.Form.Get("attributes")
	if attribute != "members" {
		w.WriteHeader(http.StatusNotFound)
		w.Write([]byte(`{"errors": "attribute not found"}`))
	}

	filter := req.Form.Get("filter")
	queryRegexp := regexp.MustCompile(`displayName eq "(.*)"`)
	matches := queryRegexp.FindAllStringSubmatch(filter, 1)
	match := matches[0]
	resources := UAAUsersByScope[match[1]]

	response, err := json.Marshal(map[string]interface{}{
		"resources":    resources,
		"startIndex":   1,
		"itemsPerPage": 100,
		"totalResults": 1,
		"schemas":      []string{"urn:scim:schemas:core:1.0"},
	})
	if err != nil {
		panic(err)
	}

	w.WriteHeader(http.StatusOK)
	w.Write(response)
})
View Source
var UAAPostOAuthToken = http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) {
	err := req.ParseForm()
	if err != nil {
		panic(err)
	}

	encodedCredentials := strings.TrimPrefix(req.Header.Get("Authorization"), "Basic ")
	decodedCredentials, err := base64.StdEncoding.DecodeString(encodedCredentials)
	credentialsParts := strings.Split(string(decodedCredentials), ":")
	clientID := credentialsParts[0]

	token := jwt.New(jwt.GetSigningMethod("RS256"))
	claims := jwt.MapClaims{}
	token.Claims = claims
	token.Header["kid"] = "legacy-key-id"
	claims["exp"] = time.Now().Add(time.Hour * 72).Unix()
	claims["client_id"] = clientID
	claims["iss"] = "http://" + req.Host + "/oauth/token"

	switch req.Form.Get("grant_type") {
	case "client_credentials":
		switch clientID {
		case "non-critical-client":
			claims["scope"] = []string{"notifications.manage", "notifications.write",
				"emails.write", "notification_preferences.admin", "notification_templates.admin",
				"notification_templates.write", "notification_templates.read"}
		case "unauthorized-client":
			claims["scope"] = []string{}
		case "non-admin-client":
			claims["scope"] = []string{"notifications.write"}
		case "admin-client":
			claims["scope"] = []string{"notifications.admin"}
		default:
			claims["scope"] = []string{"notifications.manage",
				"notifications.write", "emails.write", "notification_preferences.admin",
				"critical_notifications.write", "notification_templates.admin",
				"notification_templates.write", "notification_templates.read"}
		}
	case "authorization_code":
		claims["user_id"] = strings.TrimSuffix(req.Form.Get("code"), "-code")
		switch claims["user_id"] {
		case "unauthorized-user":
			claims["scope"] = []string{}
		default:
			claims["scope"] = []string{"notification_preferences.read", "notification_preferences.write"}
		}
	}

	key, err := jwt.ParseRSAPrivateKeyFromPEM([]byte(ReadFile("/testing/fixtures/private.pem")))
	if err != nil {
		panic(err)
	}

	tokenString, err := token.SignedString(key)
	if err != nil {
		panic(err)
	}

	response, err := json.Marshal(map[string]string{
		"access_token": tokenString,
	})
	if err != nil {
		panic(err)
	}

	w.WriteHeader(http.StatusOK)
	w.Write(response)
})
View Source
var UAAUsers = map[string]map[string]interface{}{
	"user-111": {
		"id": "user-111",
		"meta": map[string]interface{}{
			"version":      4,
			"created":      "2014-07-16T21:00:09.021Z",
			"lastModified": "2014-08-04T19:16:29.172Z",
		},
		"userName": "User111",
		"name":     map[string]string{},
		"emails": []map[string]string{
			{"value": "user-111@example.com"},
		},
		"groups": []map[string]string{
			{
				"value":   "some-group-guid",
				"display": "notifications.write",
				"type":    "DIRECT",
			},
		},
		"approvals": []interface{}{},
		"active":    true,
		"verified":  false,
		"origin":    "uaa",
		"schemas":   []string{"urn:scim:schemas:core:1.0"},
	},
	"user-123": {
		"id": "user-123",
		"meta": map[string]interface{}{
			"version":      4,
			"created":      "2014-07-16T21:00:09.021Z",
			"lastModified": "2014-08-04T19:16:29.172Z",
		},
		"userName": "User123",
		"name":     map[string]string{},
		"emails": []map[string]string{
			{"value": "user-123@example.com"},
		},
		"groups": []map[string]string{
			{
				"value":   "some-group-guid",
				"display": "notifications.write",
				"type":    "DIRECT",
			},
		},
		"approvals": []interface{}{},
		"active":    true,
		"verified":  false,
		"origin":    "uaa",
		"schemas":   []string{"urn:scim:schemas:core:1.0"},
	},
	"user-456": {
		"id": "user-456",
		"meta": map[string]interface{}{
			"version":      4,
			"created":      "2014-07-16T21:00:09.021Z",
			"lastModified": "2014-08-04T19:16:29.172Z",
		},
		"userName": "User456",
		"name":     map[string]string{},
		"emails": []map[string]string{
			{"value": "user-456@example.com"},
		},
		"groups": []map[string]string{
			{
				"value":   "some-group-guid",
				"display": "notifications.write",
				"type":    "DIRECT",
			},
		},
		"approvals": []interface{}{},
		"active":    true,
		"verified":  false,
		"origin":    "uaa",
		"schemas":   []string{"urn:scim:schemas:core:1.0"},
	},
	"user-789": {
		"id": "user-789",
		"meta": map[string]interface{}{
			"version":      4,
			"created":      "2014-07-16T21:00:09.021Z",
			"lastModified": "2014-08-04T19:16:29.172Z",
		},
		"userName": "User789",
		"name":     map[string]string{},
		"emails": []map[string]string{
			{"value": "user-789"},
		},
		"groups": []map[string]string{
			{
				"value":   "some-group-guid",
				"display": "notifications.write",
				"type":    "DIRECT",
			},
		},
		"approvals": []interface{}{},
		"active":    true,
		"verified":  false,
		"origin":    "uaa",
		"schemas":   []string{"urn:scim:schemas:core:1.0"},
	},
	"user-369": {
		"id": "user-369",
		"meta": map[string]interface{}{
			"version":      4,
			"created":      "2014-07-16T21:00:09.021Z",
			"lastModified": "2014-08-04T19:16:29.172Z",
		},
		"userName": "User369",
		"name":     map[string]string{},
		"emails": []map[string]string{
			{"value": "user-369@example.com"},
		},
		"groups": []map[string]string{
			{
				"value":   "some-group-guid",
				"display": "notifications.write",
				"type":    "DIRECT",
			},
			{
				"value":   "this-scope-guid",
				"display": "this.scope",
				"type":    "DIRECT",
			},
		},
		"approvals": []interface{}{},
		"active":    true,
		"verified":  false,
		"origin":    "uaa",
		"schemas":   []string{"urn:scim:schemas:core:1.0"},
	},
	"091b6583-0933-4d17-a5b6-66e54666c88e": {
		"id": "091b6583-0933-4d17-a5b6-66e54666c88e",
		"meta": map[string]interface{}{
			"version":      6,
			"created":      "2014-05-22T22:36:36.941Z",
			"lastModified": "2014-06-25T23:10:03.845Z",
		},
		"userName": "admin",
		"name": map[string]string{
			"familyName": "Admin",
			"givenName":  "Mister",
		},
		"emails": []map[string]string{
			{"value": "why-email@example.com"},
		},
		"groups": []map[string]string{
			{
				"value":   "e7f74565-4c7e-44ba-b068-b16072cbf08f",
				"display": "clients.read",
				"type":    "DIRECT",
			},
		},
		"approvals": []string{},
		"active":    true,
		"verified":  false,
		"schemas":   []string{"urn:scim:schemas:core:1.0"},
	},
	"943e6076-b1a5-4404-811b-a1ee9253bf56": {
		"id": "943e6076-b1a5-4404-811b-a1ee9253bf56",
		"meta": map[string]interface{}{
			"version":      6,
			"created":      "2014-05-22T22:36:36.941Z",
			"lastModified": "2014-06-25T23:10:03.845Z",
		},
		"userName": "some-user",
		"name": map[string]string{
			"familyName": "Some",
			"givenName":  "User",
		},
		"emails": []map[string]string{
			{"value": "slayer@example.com"},
		},
		"groups": []map[string]string{
			{
				"value":   "e7f74565-4c7e-44ba-b068-b16072cbf08f",
				"display": "clients.read",
				"type":    "DIRECT",
			},
		},
		"approvals": []string{},
		"active":    true,
		"verified":  false,
		"schemas":   []string{"urn:scim:schemas:core:1.0"},
	},
}
View Source
var UAAUsersByScope = map[string]interface{}{
	"this.scope": []map[string]interface{}{
		{
			"members": []map[string]string{
				{
					"origin": "uaa",
					"type":   "user",
					"value":  "user-369",
				},
			},
		},
	},
}

Functions

func ReadFile

func ReadFile(filename string) string

Types

type CC

type CC struct {
	// contains filtered or unexported fields
}

func NewCC

func NewCC(userNameToIdMap map[string]string) CC

func (CC) Boot

func (s CC) Boot()

func (CC) Close

func (s CC) Close()

func (CC) GetOrg

func (cc CC) GetOrg(w http.ResponseWriter, req *http.Request)

func (CC) GetOrgAuditors

func (cc CC) GetOrgAuditors(w http.ResponseWriter, req *http.Request)

func (CC) GetOrgBillingManagers

func (cc CC) GetOrgBillingManagers(w http.ResponseWriter, req *http.Request)

func (CC) GetOrgManagers

func (cc CC) GetOrgManagers(w http.ResponseWriter, req *http.Request)

func (CC) GetOrgUsers

func (cc CC) GetOrgUsers(w http.ResponseWriter, req *http.Request)

func (CC) GetSpace

func (cc CC) GetSpace(w http.ResponseWriter, req *http.Request)

func (CC) GetSpaceUsers

func (cc CC) GetSpaceUsers(w http.ResponseWriter, req *http.Request)

type Notifications

type Notifications struct {
	// contains filtered or unexported fields
}

func NewNotifications

func NewNotifications() Notifications

func (*Notifications) Boot

func (s *Notifications) Boot()

func (Notifications) Close

func (s Notifications) Close()

func (Notifications) Compile

func (s Notifications) Compile()

func (Notifications) Destroy

func (s Notifications) Destroy()

func (Notifications) MigrateDatabase

func (s Notifications) MigrateDatabase()

func (Notifications) ResetDatabase

func (s Notifications) ResetDatabase()

func (*Notifications) Restart

func (s *Notifications) Restart()

func (Notifications) URL

func (s Notifications) URL() string

func (Notifications) WaitForJobsQueueToEmpty

func (s Notifications) WaitForJobsQueueToEmpty() error

type SMTP

type SMTP struct {
	Deliveries []smtpd.Envelope

	HandlerCall struct {
		Callback func()
		Returns  struct {
			Error error
		}
	}
	// contains filtered or unexported fields
}

func NewSMTP

func NewSMTP() *SMTP

func (*SMTP) Boot

func (s *SMTP) Boot()

func (*SMTP) Close

func (s *SMTP) Close()

func (*SMTP) Handler

func (s *SMTP) Handler(peer smtpd.Peer, env smtpd.Envelope) error

func (*SMTP) Reset

func (s *SMTP) Reset()

type UAA

type UAA struct {
	ServerURL string
	// contains filtered or unexported fields
}

func NewUAA

func NewUAA() *UAA

func (*UAA) Boot

func (s *UAA) Boot()

func (UAA) Close

func (s UAA) Close()

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL