SCIM SDK (System for Cross-domain Identity Management)

repository·main·Indexed 41 days ago

https://github.com/captain-p-goldfish/scim-sdk

An open-source implementation of the SCIM 2.0 protocol providing client and server-side capabilities for managing identities via RESTful services. It supports standard operations including create, read, list, update, patch, delete, and bulk, with features like cursor-based pagination (RFC9865) and a POJO creator for generating Java objects from SCIM schemas. Requires JDK 8 or higher and supports Jackson 2 and Jackson 3.

Tokens
3.1K
Snippets
6
Records
16
Agent score
99%

What's inside SCIM SDK

  1. How the SCIM Server implementation works

    main

    The server implementation is highly generic, allowing you to define custom schema representations for resources. You can even override default core schemata like User or Group (e.g., to exclude attributes like ims or phoneNumbers).

    To define a resource, you need two JSON documents:

    1. A schema definition: Describes the resource you want to supply.
    2. A resource type definition: Describes the endpoint and any additional schema extensions used within the schema definition.
  2. Configure REST API dependencies for SCIM

    main

    The SCIM SDK provides API libraries for REST methods but does not include the implementations as transitive dependencies. You must provide the corresponding JAX-RS API dependencies in your project to use the built-in REST API methods.

    <dependency>
        <groupId>javax.ws.rs</groupId>
        <artifactId>javax.ws.rs-api</artifactId>
        <optional>true</optional>
    </dependency>
    <dependency>
        <groupId>jakarta.ws.rs</groupId>
        <artifactId>jakarta.ws.rs-api</artifactId>
        <optional>true</optional>
    </dependency>
  3. Access SCIM endpoints via Servlet or JAXRS

    main

    The JBoss SCIM example provides the same SCIM 2.0 endpoints through two different implementation styles: a Servlet implementation and a JAXRS implementation. The endpoints are distinguished by their URL paths.

    Servlet Endpoints

    Use the /servlet/ path prefix:

    • http://localhost:8080/scim-jboss-example/servlet/scim/v2/ServiceProviderConfig
    • http://localhost:8080/scim-jboss-example/servlet/scim/v2/Schemas
    • http://localhost:8080/scim-jboss-example/servlet/scim/v2/ResourceTypes
    • http://localhost:8080/scim-jboss-example/servlet/scim/v2/Users
    • http://localhost:8080/scim-jboss-example/servlet/scim/v2/Groups

    JAXRS Endpoints

    Use the /jaxrs/ path prefix:

    • http://localhost:8080/scim-jboss-example/jaxrs/scim/v2/ServiceProviderConfig
    • http://localhost:8080/scim-jboss-example/jaxrs/scim/v2/Schemas
    • http://localhost:8080/scim-jboss-example/jaxrs/scim/v2/ResourceTypes
    • http://localhost:8080/scim-jboss-example/jaxrs/scim/v2/Users
    • http://localhost:8080/scim-jboss-example/jaxrs/scim/v2/Groups

    Both implementations support all standard SCIM operation types: list, get, create, update, delete, patch, bulk, filtering, and sorting.

  4. Run the scim-sdk-schema-pojo-creator

    main

    The scim-sdk-schema-pojo-creator is a Spring Shell application used to generate Java POJO objects from SCIM schema files.

    To use it:

    1. Ensure you have JDK 8 or higher installed.
    2. Download the JAR artifact from the SCIM-SDK releases section.
    3. Run the JAR directly from a terminal (PowerShell, Linux shell, etc.) using the following command:
    java -jar scim-sdk-schema-pojo-creator-${version}.jar
  5. Install the SCIM SDK via Maven

    main

    The SCIM SDK is split into scim-sdk-server and scim-sdk-client. You must choose the dependency version based on whether you are using Jackson 2 or Jackson 3. This project requires JDK 8 or higher.

    Note: If your IDE fails to compile, ensure you have the Lombok plugin installed and restart your IDE.

    <!-- For Jackson 2 usage -->
    <dependency>
        <groupId>de.captaingoldfish</groupId>
        <artifactId>scim-sdk-server</artifactId>
        <version>${project.version}</version>
    </dependency>
    <dependency>
        <groupId>de.captaingoldfish</groupId>
        <artifactId>scim-sdk-client</artifactId>
        <version>${project.version}</version>
    </dependency>
    
    <!-- For Jackson 3 usage -->
    <dependency>
        <groupId>de.captaingoldfish</groupId>
        <artifactId>scim-sdk-server</artifactId>
        <version>${project.version}-jackson3</version>
    </dependency>
    <dependency>
        <groupId>de.captaingoldfish</groupId>
        <artifactId>scim-sdk-client</artifactId>
        <version>${project.version}-jackson3</version>
    </dependency>
  6. Deploy the JBoss SCIM example project

    main

    To deploy the SCIM example in a JBoss/WildFly environment, build the WAR archive using Maven and move the resulting file to your JBoss deployments directory.

    1. Build the project: mvn clean package
    2. Locate the generated file: scim-sdk-jboss-example-${project.version}.war.
    3. Copy this file into the deployments directory of your JBoss instance.

    This sample has been tested with WildFly 19.1.0 and WildFly 22.0.0.

    mvn clean package
  7. Bulk operation constraints and validation

    main

    When constructing a Bulk request, the following constraints are enforced by the BulkEndpoint:

    • Allowed HTTP Methods: Typically POST, PUT, PATCH, and DELETE. GET is only allowed if the service provider explicitly supports bulk GET.
    • POST Requirement: Every POST operation within a bulk request must include a bulkId to allow for subsequent referencing.
    • Payload Size: The request body must not exceed the maxPayloadSize defined in the BulkConfig.
    • Operation Count: The number of operations in the request must not exceed maxOperations defined in the BulkConfig.
    • Duplicate IDs: Each bulkId in the request must be unique.
  8. How Bulk operations work in the SCIM server

    main

    The BulkEndpoint allows executing multiple SCIM operations (POST, PUT, PATCH, DELETE, and optionally GET) within a single HTTP request.

    Key behaviors include:

    • Bulk ID References: Operations can reference the results of previous operations using bulkId. The server resolves these references (e.g., using an ID created in a POST to perform a subsequent PATCH).
    • Error Handling: The server respects a failOnErrors configuration. If the number of failed operations exceeds this threshold, the server stops processing and returns 412 Precondition Failed.
    • Bulk GET Support: If enabled via BulkConfig.isSupportBulkGet(), GET operations can be included. The server can also perform transitive resource retrieval (fetching child resources) if configured.
    • Resource Returns: Whether the response includes the full resource body depends on the BulkConfig (via isReturnResourcesEnabled and isReturnResourcesByDefault) and the specific operation's returnResource flag.
  9. Troubleshoot missing generated resources

    main

    If the translate command runs but expected resources are not generated, ensure the following rules are met:

    1. Resource Type Presence: ResourceHandler and EndpointDefinition implementations are only created if a corresponding resource-type JSON definition exists.
    2. Schema Validation: Schemas are validated against meta-schema representations; invalid schemas will be skipped.
    3. File Extensions: Both resource-schema and resource-type filenames must end with .json.
    4. Reference Integrity: If a resource-type file contains a reference in its schema attribute to a resource-schema that cannot be found, the entire resource will be ignored because the underlying resource base is missing.
  10. Use the translate command to generate POJOs

    main

    Once the application shell is open, use the translate command to process SCIM schemas into Java POJOs. This command gathers resource-schema and resource-type files, validates their relations, and writes the generated classes to your specified output directory.

    Command Syntax

    translate [--location String] --recursive boolean --output String --package String --useLombok boolean --override boolean --create-config boolean

    translate -r -l /path/to/scim/resources -o /path/to/src/main/java -p com.example.scim --useLombok --create-config
  11. Configure Bulk operation limits via BulkConfig

    main

    The behavior of the BulkEndpoint is governed by the BulkConfig object provided by the ServiceProvider. Developers implementing a ServiceProvider should configure these keys to control server load and behavior:

    • supported: Boolean indicating if bulk operations are enabled.
    • maxOperations: The maximum number of operations allowed in a single bulk request.
    • maxPayloadSize: The maximum allowed size (in bytes) for the bulk request body.
    • supportBulkGet: Boolean indicating if GET operations are permitted in bulk requests.
    • returnResourcesEnabled: Global toggle for whether resource bodies are returned in responses.
    • returnResourcesByDefault: If returnResourcesEnabled is true, this determines if resources are returned even if the client doesn't explicitly ask for them.