From cfd5f47698ca8c543e62ed189e9cfe803a278d0b Mon Sep 17 00:00:00 2001 From: Hugo Renard Date: Thu, 20 Jan 2022 17:59:46 +0100 Subject: [PATCH] first try --- .vscode/launch.json | 15 ++++++ cmd/liiibre-sp/main.go | 102 +++++++++++++++++++++++++++++++++++++++++ docker-compose.yml | 29 ++++++++++++ go.mod | 13 ++++++ go.sum | 8 ++++ keycloak/Dockerfile | 15 ++++++ 6 files changed, 182 insertions(+) create mode 100644 .vscode/launch.json create mode 100644 cmd/liiibre-sp/main.go create mode 100644 docker-compose.yml create mode 100644 go.mod create mode 100644 go.sum create mode 100644 keycloak/Dockerfile diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 0000000..3eae675 --- /dev/null +++ b/.vscode/launch.json @@ -0,0 +1,15 @@ +{ + // Utilisez IntelliSense pour en savoir plus sur les attributs possibles. + // Pointez pour afficher la description des attributs existants. + // Pour plus d'informations, visitez : https://go.microsoft.com/fwlink/?linkid=830387 + "version": "0.2.0", + "configurations": [ + { + "name": "Launch Package", + "type": "go", + "request": "launch", + "mode": "auto", + "program": "${workspaceFolder}/cmd/liiibre-sp/main.go" + } + ] +} \ No newline at end of file diff --git a/cmd/liiibre-sp/main.go b/cmd/liiibre-sp/main.go new file mode 100644 index 0000000..444f288 --- /dev/null +++ b/cmd/liiibre-sp/main.go @@ -0,0 +1,102 @@ +package main + +import ( + "errors" + "fmt" + "log" + "math/rand" + "net/http" + "time" + + "github.com/elimity-com/scim" + "github.com/elimity-com/scim/optional" + "github.com/elimity-com/scim/schema" +) + +type testResourceHandler struct { +} + +func main() { + config := scim.ServiceProviderConfig{ + DocumentationURI: optional.NewString("localhost:8282"), + } + + // schema := schema.Schema{ + // ID: schema.UserSchema, + // Name: optional.NewString("User"), + // Description: optional.NewString("User Account"), + // Attributes: []schema.CoreAttribute{ + // schema.SimpleCoreAttribute(schema.SimpleStringParams(schema.StringParams{ + // Name: "userName", + // Required: true, + // Uniqueness: schema.AttributeUniquenessServer(), + // })), + // }, + // } + + resourceTypes := []scim.ResourceType{ + { + ID: optional.NewString("User"), + Name: "User", + Endpoint: "/Users", + Description: optional.NewString("User Account"), + Schema: schema.CoreUserSchema(), + Handler: testResourceHandler{}, + }, + { + ID: optional.NewString("Group"), + Name: "Group", + Endpoint: "/Groups", + Description: optional.NewString("Group"), + Schema: schema.CoreGroupSchema(), + Handler: testResourceHandler{}, + }, + } + + server := scim.Server{ + Config: config, + ResourceTypes: resourceTypes, + } + + http.Handle("/", server) + log.Fatal(http.ListenAndServe(":8282", nil)) + +} + +func (h testResourceHandler) Create(r *http.Request, attributes scim.ResourceAttributes) (scim.Resource, error) { + rand.Seed(time.Now().UnixNano()) + id := fmt.Sprintf("%04d", rand.Intn(9999)) + + // now := time.Now() + + return scim.Resource{ + ID: id, + ExternalID: optional.NewString(attributes["externalId"].(string)), + Attributes: attributes, + Meta: scim.Meta{ + // Created: &now, + // LastModified: &now, + Version: fmt.Sprintf("v%s", id), + }, + }, nil +} + +func (h testResourceHandler) Get(r *http.Request, id string) (scim.Resource, error) { + return scim.Resource{}, errors.New("not implemented") +} + +func (h testResourceHandler) GetAll(r *http.Request, params scim.ListRequestParams) (scim.Page, error) { + return scim.Page{}, errors.New("not implemented") +} + +func (h testResourceHandler) Replace(r *http.Request, id string, attributes scim.ResourceAttributes) (scim.Resource, error) { + return scim.Resource{}, errors.New("not implemented") +} + +func (h testResourceHandler) Delete(r *http.Request, id string) error { + return errors.New("not implemented") +} + +func (h testResourceHandler) Patch(r *http.Request, id string, operations []scim.PatchOperation) (scim.Resource, error) { + return scim.Resource{}, errors.New("not implemented") +} diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..54a9dc8 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,29 @@ +version: "3" + +services: + postgres: + image: postgres + volumes: + - db:/var/lib/postgresql/data + environment: + POSTGRES_USER: keycloak + POSTGRES_PASSWORD: keycloak + keycloak: + build: + context: keycloak + environment: + DB_VENDOR: POSTGRES + DB_ADDR: postgres + DB_DATABASE: keycloak + DB_USER: keycloak + DB_SCHEMA: public + DB_PASSWORD: keycloak + KEYCLOAK_USER: admin + KEYCLOAK_PASSWORD: admin + ports: + - 8080:8080 + depends_on: + - postgres + +volumes: + db: diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..ac3e9d1 --- /dev/null +++ b/go.mod @@ -0,0 +1,13 @@ +module lab.libreho.st/libre.sh/scim + +go 1.17 + +require github.com/elimity-com/scim v0.0.0-20211119105057-007f1a2691f0 + +require ( + github.com/di-wu/parser v0.2.2 // indirect + github.com/di-wu/xsd-datetime v1.0.0 // indirect + github.com/scim2/filter-parser/v2 v2.2.0 // indirect +) + +// replace github.com/elimity-com/scim => /home/hougo/git/hrenard/scim diff --git a/go.sum b/go.sum new file mode 100644 index 0000000..c604f1b --- /dev/null +++ b/go.sum @@ -0,0 +1,8 @@ +github.com/di-wu/parser v0.2.2 h1:I9oHJ8spBXOeL7Wps0ffkFFFiXJf/pk7NX9lcAMqRMU= +github.com/di-wu/parser v0.2.2/go.mod h1:SLp58pW6WamdmznrVRrw2NTyn4wAvT9rrEFynKX7nYo= +github.com/di-wu/xsd-datetime v1.0.0 h1:vZoGNkbzpBNoc+JyfVLEbutNDNydYV8XwHeV7eUJoxI= +github.com/di-wu/xsd-datetime v1.0.0/go.mod h1:i3iEhrP3WchwseOBeIdW/zxeoleXTOzx1WyDXgdmOww= +github.com/elimity-com/scim v0.0.0-20211119105057-007f1a2691f0 h1:/26/OeOlwid0okzLB3ZN0p/wgzxOmQhGnH0VYPhRBVU= +github.com/elimity-com/scim v0.0.0-20211119105057-007f1a2691f0/go.mod h1:JkjcmqbLW+khwt2fmBPJFBhx2zGZ8XobRZ+O0VhlwWo= +github.com/scim2/filter-parser/v2 v2.2.0 h1:QGadEcsmypxg8gYChRSM2j1edLyE/2j72j+hdmI4BJM= +github.com/scim2/filter-parser/v2 v2.2.0/go.mod h1:jWnkDToqX/Y0ugz0P5VvpVEUKcWcyHHj+X+je9ce5JA= diff --git a/keycloak/Dockerfile b/keycloak/Dockerfile new file mode 100644 index 0000000..7869ba2 --- /dev/null +++ b/keycloak/Dockerfile @@ -0,0 +1,15 @@ +FROM maven:3-openjdk-11 as base + +# RUN apt-get update && apt-get install -y git maven + +RUN git clone https://github.com/suvera/keycloak-scim2-storage.git + +WORKDIR /keycloak-scim2-storage + +RUN mvn clean install + +FROM docker.io/jboss/keycloak:16.1.0 + +COPY --from=base /keycloak-scim2-storage/target/suvera-keycloak-scim2-outbound-provisioning-jar-with-dependencies.jar /opt/jboss/keycloak/standalone/deployments/ + +# RUN curl https://github.com/Captain-P-Goldfish/scim-for-keycloak/releases/download/kc-16-b2/scim-for-keycloak-kc-16-b2.ear -o /opt/jboss/keycloak/standalone/deployments/scim-for-keycloak-kc-16-b2.ear \ No newline at end of file