102 lines
2.6 KiB
Go
102 lines
2.6 KiB
Go
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")
|
|
}
|