You are viewing a plain text version of this content. The canonical link for it is here.
Posted to scimple@directory.apache.org by Azmathulla Chinnakondepalli <az...@broadcom.com.INVALID> on 2023/12/19 21:35:32 UTC
RE: Re: Scim-Client
HI,
The sample code i have is below along with dependencies in pom.xml
*import* jakarta.inject.Singleton;
*import* jakarta.ws.rs.client.Client;
*import* jakarta.ws.rs.client.ClientBuilder;
*import* jakarta.ws.rs.client.ClientRequestFilter;
*import* jakarta.ws.rs.core.MediaType;
*import* jakarta.ws.rs.core.Response;
*import* java.security.KeyManagementException;
*import* java.security.NoSuchAlgorithmException;
*import* java.util.ArrayList;
*import* javax.net.ssl.HttpsURLConnection;
*import* javax.net.ssl.SSLContext;
*import* javax.net.ssl.TrustManager;
*import* org.apache.directory.scim.client.rest.ScimUserClient;
*import* org.apache.directory.scim.core.schema.SchemaRegistry;
*import* org.apache.directory.scim.spec.resources.ScimUser;
*import* org.apache.directory.scim.spec.schema.ResourceType;
*import* org.apache.directory.scim.spec.schema.Schema;
*import* org.apache.directory.scim.spec.schema.Schemas;
*import* org.glassfish.jersey.client.ClientConfig;
//import org.glassfish.jersey.jdk.connector.JdkConnectorProvider;
*import* org.glassfish.jersey.server.ResourceConfig;
*import* org.apache.directory.scim.spec.filter.FilterBuilder;
*import* org.apache.directory.scim.spec.resources.Name;
*import* org.apache.directory.scim.protocol.data.ListResponse;
*import* org.apache.directory.scim.protocol.data.SearchRequest;
*import* org.apache.directory.scim.protocol.exception.ScimException;
*import* org.glassfish.hk2.utilities.binding.AbstractBinder;
*public* *class* SampleUserScim {
*public* *static* *void* main(String[] args) *throws*
NoSuchAlgorithmException, KeyManagementException {
// Create a TrustManager that trusts all certificates
TrustManager[] trustAllCerts = *new* TrustManager[] { *new*
TrustAllCertificates() };
// Create an SSLContext
SSLContext sslContext = SSLContext.*getInstance*("TLS");
sslContext.init(*null*, trustAllCerts, *null*);
// Define the base URL of the SCIM server
String baseUrl = "https://<server_addr>/default/scim2/v1";
// Set the SSLContext to the default HttpsURLConnection
HttpsURLConnection.*setDefaultSSLSocketFactory*(sslContext
.getSocketFactory());
String bearerToken =...";
*final* ResourceConfig config = *new* ResourceConfig();
config.register(*new* AbstractBinder() {
*protected* *void* configure() {
bind(SchemaRegistry.*class*).to(SchemaRegistry.*class*).in(
Singleton.*class*);
}
});
config.packages("org.apache.directory.scim");
Client client = ClientBuilder.*newBuilder*().sslContext(sslContext
).hostnameVerifier((s1, s2) -> *true*)
.withConfig(config)
.register((ClientRequestFilter) requestContext ->
requestContext.getHeaders().add("Authorization", "Bearer
" + bearerToken))
SchemaRegistry sch = *new* SchemaRegistry();
Schema userSchema = Schemas.*schemaFor*(ScimUser.*class*);
ResourceType userType = *new* ResourceType();
userType.setId(ScimUser.*RESOURCE_NAME*);
userType.setEndpoint("/Users");
userType.setSchemaUrn(ScimUser.*SCHEMA_URI*);
userType.setName(ScimUser.*RESOURCE_NAME*);
userType.setDescription("Top level ScimUser");
sch.addSchema(ScimUser.*class*, *null*);
ScimUserClient userClient = *new* ScimUserClient(client,baseUrl);
*try* {
SearchRequest searchRequest = *new* SearchRequest()
.setFilter(FilterBuilder.*create*().equalTo("userName",
"lawrence_haley").build());
ListResponse<ScimUser> users = userClient.find(searchRequest);
}*catch*(ScimException e) {
System.*out*.println("Exception while creating " + e.getMessage());
}
userClient.close();
}
}
the dependencies included without which the code would not compile.
<project xmlns=*"http://maven.apache.org/POM/4.0.0
<http://maven.apache.org/POM/4.0.0>"*
xmlns:xsi=*"http://www.w3.org/2001/XMLSchema-instance
<http://www.w3.org/2001/XMLSchema-instance>"*
xsi:schemaLocation=*"http://maven.apache.org/POM/4.0.0
<http://maven.apache.org/POM/4.0.0>
https://maven.apache.org/xsd/maven-4.0.0.xsd
<https://maven.apache.org/xsd/maven-4.0.0.xsd>"*>
<modelVersion>4.0.0</modelVersion>
<groupId>sampletest</groupId>
<artifactId>SampleMavenProject</artifactId>
<version>0.0.1-SNAPSHOT</version>
<description>sampletest</description>
<dependencies>
<dependency>
<groupId>org.apache.directory.scimple</groupId>
<artifactId>scim-client</artifactId>
<version>1.0.0</version>
<scope>system</scope>
<systemPath>*/*.../scim-client-1.0.0-SNAPSHOT.jar</systemPath>
</dependency>
<dependency>
<groupId>org.apache.directory.scimple</groupId>
<artifactId>scim-spec-schema</artifactId>
<version>1.0.0</version>
<scope>system</scope>
<systemPath>/.../scim-spec-schema-1.0.0-SNAPSHOT.jar</systemPath>
</dependency>
<dependency>
<groupId>org.apache.directory.scimple</groupId>
<artifactId>scim-core</artifactId>
<version>1.0.0</version>
<scope>system</scope>
<systemPath>/.../scim-core-1.0.0-SNAPSHOT.jar</systemPath>
</dependency>
<dependency>
<groupId>org.apache.directory.scimple</groupId>
<artifactId>scim-spec-protocol</artifactId>
<version>1.0.0</version>
<scope>system</scope>
<systemPath>/.../scim-spec-protocol-1.0.0-SNAPSHOT.jar</systemPath>
</dependency>
<dependency>
<groupId>org.apache.directory.scimple</groupId>
<artifactId>scim-server</artifactId>
<version>1.0.0</version>
<scope>system</scope>
<systemPath>/.../scim-server-1.0.0-SNAPSHOT.jar</systemPath>
</dependency>
<!-- https://mvnrepository.com/artifact/jakarta.ws.rs/jakarta.ws.rs-api -->
<dependency>
<groupId>jakarta.ws.rs</groupId>
<artifactId>jakarta.ws.rs-api</artifactId>
<version>3.1.0</version>
</dependency>
<!-- https://mvnrepository.com/artifact/jakarta.inject/jakarta.inject-api
-->
<dependency>
<groupId>jakarta.inject</groupId>
<artifactId>jakarta.inject-api</artifactId>
<version>2.0.1</version>
</dependency>
<dependency>
<groupId>jakarta.platform</groupId>
<artifactId>jakarta.jakartaee-bom</artifactId>
<version>10.0.0</version>
<scope>import</scope>
<type>pom</type>
</dependency>
<dependency>
<groupId>org.junit</groupId>
<artifactId>junit-bom</artifactId>
<version>5.10.1</version>
<scope>import</scope>
<type>pom</type>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson</groupId>
<artifactId>jackson-bom</artifactId>
<version>2.16.0</version>
<scope>import</scope>
<type>pom</type>
</dependency>
<dependency>
<groupId>io.rest-assured</groupId>
<artifactId>rest-assured-bom</artifactId>
<type>pom</type>
<version>5.4.0</version>
<scope>import</scope>
</dependency>
<dependency>
<groupId>org.glassfish.jersey</groupId>
<artifactId>jersey-bom</artifactId>
<version>3.1.5</version>
<type>pom</type>
<scope>import</scope>
</dependency>
<dependency>
<groupId>org.hibernate.validator</groupId>
<artifactId>hibernate-validator</artifactId>
<version>8.0.1.Final</version>
</dependency>
<dependency>
<groupId>org.glassfish</groupId>
<artifactId>jakarta.el</artifactId>
<version>4.0.2</version>
<scope>test</scope>
</dependency>
<!-- Guava is a transitive dep, forcing a newer version to avoid
older vulns -->
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>32.1.3-android</version>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>1.4.8</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>jul-to-slf4j</artifactId>
<version>2.0.9</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>2.0.9</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>jcl-over-slf4j</artifactId>
<version>2.0.9</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
<version>2.0.9</version>
<scope>test</scope>
</dependency>
<!-- Transitive dependencies specific versions -->
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-collections4</artifactId>
<version>4.4</version>
</dependency>
<dependency>
<groupId>commons-codec</groupId>
<artifactId>commons-codec</artifactId>
<version>1.16.0</version>
</dependency>
<!--
https://mvnrepository.com/artifact/org.glassfish.jersey.core/jersey-client
-->
<dependency>
<groupId>org.glassfish.jersey.core</groupId>
<artifactId>jersey-client</artifactId>
<version>3.1.5</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.glassfish.hk2/hk2-api -->
<dependency>
<groupId>org.glassfish.hk2</groupId>
<artifactId>hk2-api</artifactId>
<version>3.0.5</version>
</dependency>
<!--
https://mvnrepository.com/artifact/org.glassfish.jersey.core/jersey-server
-->
<dependency>
<groupId>org.glassfish.jersey.core</groupId>
<artifactId>jersey-server</artifactId>
<version>3.1.5</version>
</dependency>
<!--
https://mvnrepository.com/artifact/com.fasterxml.jackson.jakarta.rs/jackson-jakarta-rs-json-provider
-->
<dependency>
<groupId>com.fasterxml.jackson.jakarta.rs</groupId>
<artifactId>jackson-jakarta-rs-json-provider</artifactId>
<version>2.16.0</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.antlr/antlr4-runtime -->
<dependency>
<groupId>org.antlr</groupId>
<artifactId>antlr4-runtime</artifactId>
<version>4.13.1</version>
</dependency>
<!--
https://mvnrepository.com/artifact/org.apache.commons/commons-lang3 -->
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.14.0</version>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.inject</groupId>
<artifactId>jersey-hk2</artifactId>
<version>3.0.0</version>
</dependency>
<!-- https://mvnrepository.com/artifact/javax.ws.rs/javax.ws.rs-api
-->
<dependency>
<groupId>javax.ws.rs</groupId>
<artifactId>javax.ws.rs-api</artifactId>
<version>2.1.1</version>
</dependency>
</dependencies>
</project>
Thanks
--
This electronic communication and the information and any files transmitted
with it, or attached to it, are confidential and are intended solely for
the use of the individual or entity to whom it is addressed and may contain
information that is confidential, legally privileged, protected by privacy
laws, or otherwise restricted from disclosure to anyone else. If you are
not the intended recipient or the person responsible for delivering the
e-mail to the intended recipient, you are hereby notified that any use,
copying, distributing, dissemination, forwarding, printing, or copying of
this e-mail is strictly prohibited. If you received this e-mail in error,
please return the e-mail to the sender, delete it from your computer, and
destroy any printed copy of it.
Re: Re: Scim-Client
Posted by Brian Demers <bd...@apache.org>.
Sorry for the delay.
I was looking into this tonight, we probably need a better example in
the source tree, but that gets tricky with a standalone client. I'm
guessing most usage of the scimple client will be part of another app
that already has a CDI container.
But to help answer the question, you need to make sure you have a CDI
container available (e.g. a dependency) and initialize it.
In your example, you could probably add
<dependency>
<groupId>org.glassfish.jersey.ext.cdi</groupId>
<artifactId>jersey-weld2-se</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.jboss.weld.se</groupId>
<artifactId>weld-se-core</artifactId>
<scope>runtime</scope>
</dependency>
And then start the container:
import jakarta.enterprise.inject.se.SeContainer;
import jakarta.enterprise.inject.se.SeContainerInitializer;
...
// add this before you create the client
SeContainer container = SeContainerInitializer.newInstance().initialize();
On Tue, Dec 19, 2023 at 9:00 PM Azmathulla Chinnakondepalli
<az...@broadcom.com.invalid> wrote:
>
> the above code is for the issue mentioned on https://lists.apache.org/thread/v0p1zwskpqhy3grjp43mf28xgvb875pq
>
> On Tue, Dec 19, 2023 at 4:35 PM Azmathulla Chinnakondepalli <az...@broadcom.com> wrote:
>>
>> HI,
>>
>> The sample code i have is below along with dependencies in pom.xml
>>
>> import jakarta.inject.Singleton;
>>
>> import jakarta.ws.rs.client.Client;
>>
>> import jakarta.ws.rs.client.ClientBuilder;
>>
>> import jakarta.ws.rs.client.ClientRequestFilter;
>>
>> import jakarta.ws.rs.core.MediaType;
>>
>> import jakarta.ws.rs.core.Response;
>>
>>
>> import java.security.KeyManagementException;
>>
>> import java.security.NoSuchAlgorithmException;
>>
>> import java.util.ArrayList;
>>
>>
>> import javax.net.ssl.HttpsURLConnection;
>>
>> import javax.net.ssl.SSLContext;
>>
>> import javax.net.ssl.TrustManager;
>>
>>
>> import org.apache.directory.scim.client.rest.ScimUserClient;
>>
>> import org.apache.directory.scim.core.schema.SchemaRegistry;
>>
>> import org.apache.directory.scim.spec.resources.ScimUser;
>>
>> import org.apache.directory.scim.spec.schema.ResourceType;
>>
>> import org.apache.directory.scim.spec.schema.Schema;
>>
>> import org.apache.directory.scim.spec.schema.Schemas;
>>
>> import org.glassfish.jersey.client.ClientConfig;
>>
>> //import org.glassfish.jersey.jdk.connector.JdkConnectorProvider;
>>
>> import org.glassfish.jersey.server.ResourceConfig;
>>
>> import org.apache.directory.scim.spec.filter.FilterBuilder;
>>
>> import org.apache.directory.scim.spec.resources.Name;
>>
>> import org.apache.directory.scim.protocol.data.ListResponse;
>>
>> import org.apache.directory.scim.protocol.data.SearchRequest;
>>
>> import org.apache.directory.scim.protocol.exception.ScimException;
>>
>> import org.glassfish.hk2.utilities.binding.AbstractBinder;
>>
>>
>> public class SampleUserScim {
>>
>> public static void main(String[] args) throws NoSuchAlgorithmException, KeyManagementException {
>>
>>
>>
>>
>> // Create a TrustManager that trusts all certificates
>>
>> TrustManager[] trustAllCerts = new TrustManager[] { new TrustAllCertificates() };
>>
>>
>> // Create an SSLContext
>>
>> SSLContext sslContext = SSLContext.getInstance("TLS");
>>
>> sslContext.init(null, trustAllCerts, null);
>>
>>
>> // Define the base URL of the SCIM server
>>
>> String baseUrl = "https://<server_addr>/default/scim2/v1";
>>
>>
>>
>> // Set the SSLContext to the default HttpsURLConnection
>>
>> HttpsURLConnection.setDefaultSSLSocketFactory(sslContext.getSocketFactory());
>>
>>
>> String bearerToken =...";
>>
>>
>>
>> final ResourceConfig config = new ResourceConfig();
>>
>> config.register(new AbstractBinder() {
>>
>>
>> protected void configure() {
>>
>> bind(SchemaRegistry.class).to(SchemaRegistry.class).in(Singleton.class);
>>
>> }
>>
>> });
>>
>> config.packages("org.apache.directory.scim");
>>
>>
>>
>> Client client = ClientBuilder.newBuilder().sslContext(sslContext).hostnameVerifier((s1, s2) -> true)
>>
>> .withConfig(config)
>>
>> .register((ClientRequestFilter) requestContext ->
>>
>> requestContext.getHeaders().add("Authorization", "Bearer " + bearerToken))
>>
>>
>> SchemaRegistry sch = new SchemaRegistry();
>>
>> Schema userSchema = Schemas.schemaFor(ScimUser.class);
>>
>> ResourceType userType = new ResourceType();
>>
>> userType.setId(ScimUser.RESOURCE_NAME);
>>
>> userType.setEndpoint("/Users");
>>
>> userType.setSchemaUrn(ScimUser.SCHEMA_URI);
>>
>> userType.setName(ScimUser.RESOURCE_NAME);
>>
>> userType.setDescription("Top level ScimUser");
>>
>> sch.addSchema(ScimUser.class, null);
>>
>>
>> ScimUserClient userClient = new ScimUserClient(client,baseUrl);
>>
>>
>>
>>
>> try {
>>
>> SearchRequest searchRequest = new SearchRequest()
>>
>> .setFilter(FilterBuilder.create().equalTo("userName", "lawrence_haley").build());
>>
>>
>> ListResponse<ScimUser> users = userClient.find(searchRequest);
>>
>>
>> }catch(ScimException e) {
>>
>> System.out.println("Exception while creating " + e.getMessage());
>>
>> }
>>
>> userClient.close();
>>
>> }
>>
>> }
>>
>>
>>
>> the dependencies included without which the code would not compile.
>>
>>
>>
>>
>> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
>>
>> <modelVersion>4.0.0</modelVersion>
>>
>> <groupId>sampletest</groupId>
>>
>> <artifactId>SampleMavenProject</artifactId>
>>
>> <version>0.0.1-SNAPSHOT</version>
>>
>> <description>sampletest</description>
>>
>> <dependencies>
>>
>> <dependency>
>>
>> <groupId>org.apache.directory.scimple</groupId>
>>
>> <artifactId>scim-client</artifactId>
>>
>> <version>1.0.0</version>
>>
>> <scope>system</scope>
>>
>> <systemPath>/.../scim-client-1.0.0-SNAPSHOT.jar</systemPath>
>>
>> </dependency>
>>
>> <dependency>
>>
>> <groupId>org.apache.directory.scimple</groupId>
>>
>> <artifactId>scim-spec-schema</artifactId>
>>
>> <version>1.0.0</version>
>>
>> <scope>system</scope>
>>
>> <systemPath>/.../scim-spec-schema-1.0.0-SNAPSHOT.jar</systemPath>
>>
>> </dependency>
>>
>> <dependency>
>>
>> <groupId>org.apache.directory.scimple</groupId>
>>
>> <artifactId>scim-core</artifactId>
>>
>> <version>1.0.0</version>
>>
>> <scope>system</scope>
>>
>> <systemPath>/.../scim-core-1.0.0-SNAPSHOT.jar</systemPath>
>>
>> </dependency>
>>
>> <dependency>
>>
>> <groupId>org.apache.directory.scimple</groupId>
>>
>> <artifactId>scim-spec-protocol</artifactId>
>>
>> <version>1.0.0</version>
>>
>> <scope>system</scope>
>>
>> <systemPath>/.../scim-spec-protocol-1.0.0-SNAPSHOT.jar</systemPath>
>>
>> </dependency>
>>
>> <dependency>
>>
>> <groupId>org.apache.directory.scimple</groupId>
>>
>> <artifactId>scim-server</artifactId>
>>
>> <version>1.0.0</version>
>>
>> <scope>system</scope>
>>
>> <systemPath>/.../scim-server-1.0.0-SNAPSHOT.jar</systemPath>
>>
>> </dependency>
>>
>> <!-- https://mvnrepository.com/artifact/jakarta.ws.rs/jakarta.ws.rs-api -->
>>
>> <dependency>
>>
>> <groupId>jakarta.ws.rs</groupId>
>>
>> <artifactId>jakarta.ws.rs-api</artifactId>
>>
>> <version>3.1.0</version>
>>
>> </dependency>
>>
>> <!-- https://mvnrepository.com/artifact/jakarta.inject/jakarta.inject-api -->
>>
>> <dependency>
>>
>> <groupId>jakarta.inject</groupId>
>>
>> <artifactId>jakarta.inject-api</artifactId>
>>
>> <version>2.0.1</version>
>>
>> </dependency>
>>
>>
>>
>> <dependency>
>>
>> <groupId>jakarta.platform</groupId>
>>
>> <artifactId>jakarta.jakartaee-bom</artifactId>
>>
>> <version>10.0.0</version>
>>
>> <scope>import</scope>
>>
>> <type>pom</type>
>>
>> </dependency>
>>
>> <dependency>
>>
>> <groupId>org.junit</groupId>
>>
>> <artifactId>junit-bom</artifactId>
>>
>> <version>5.10.1</version>
>>
>> <scope>import</scope>
>>
>> <type>pom</type>
>>
>> </dependency>
>>
>> <dependency>
>>
>> <groupId>com.fasterxml.jackson</groupId>
>>
>> <artifactId>jackson-bom</artifactId>
>>
>> <version>2.16.0</version>
>>
>> <scope>import</scope>
>>
>> <type>pom</type>
>>
>> </dependency>
>>
>> <dependency>
>>
>> <groupId>io.rest-assured</groupId>
>>
>> <artifactId>rest-assured-bom</artifactId>
>>
>> <type>pom</type>
>>
>> <version>5.4.0</version>
>>
>> <scope>import</scope>
>>
>> </dependency>
>>
>> <dependency>
>>
>> <groupId>org.glassfish.jersey</groupId>
>>
>> <artifactId>jersey-bom</artifactId>
>>
>> <version>3.1.5</version>
>>
>> <type>pom</type>
>>
>> <scope>import</scope>
>>
>> </dependency>
>>
>> <dependency>
>>
>> <groupId>org.hibernate.validator</groupId>
>>
>> <artifactId>hibernate-validator</artifactId>
>>
>> <version>8.0.1.Final</version>
>>
>> </dependency>
>>
>> <dependency>
>>
>> <groupId>org.glassfish</groupId>
>>
>> <artifactId>jakarta.el</artifactId>
>>
>> <version>4.0.2</version>
>>
>> <scope>test</scope>
>>
>> </dependency>
>>
>>
>> <!-- Guava is a transitive dep, forcing a newer version to avoid older vulns -->
>>
>> <dependency>
>>
>> <groupId>com.google.guava</groupId>
>>
>> <artifactId>guava</artifactId>
>>
>> <version>32.1.3-android</version>
>>
>> </dependency>
>>
>> <dependency>
>>
>> <groupId>ch.qos.logback</groupId>
>>
>> <artifactId>logback-classic</artifactId>
>>
>> <version>1.4.8</version>
>>
>> </dependency>
>>
>> <dependency>
>>
>> <groupId>org.slf4j</groupId>
>>
>> <artifactId>jul-to-slf4j</artifactId>
>>
>> <version>2.0.9</version>
>>
>> </dependency>
>>
>> <dependency>
>>
>> <groupId>org.slf4j</groupId>
>>
>> <artifactId>slf4j-api</artifactId>
>>
>> <version>2.0.9</version>
>>
>> </dependency>
>>
>> <dependency>
>>
>> <groupId>org.slf4j</groupId>
>>
>> <artifactId>jcl-over-slf4j</artifactId>
>>
>> <version>2.0.9</version>
>>
>> </dependency>
>>
>> <dependency>
>>
>> <groupId>org.slf4j</groupId>
>>
>> <artifactId>slf4j-simple</artifactId>
>>
>> <version>2.0.9</version>
>>
>> <scope>test</scope>
>>
>> </dependency>
>>
>>
>>
>>
>>
>>
>> <!-- Transitive dependencies specific versions -->
>>
>> <dependency>
>>
>> <groupId>org.apache.commons</groupId>
>>
>> <artifactId>commons-collections4</artifactId>
>>
>> <version>4.4</version>
>>
>> </dependency>
>>
>> <dependency>
>>
>> <groupId>commons-codec</groupId>
>>
>> <artifactId>commons-codec</artifactId>
>>
>> <version>1.16.0</version>
>>
>> </dependency>
>>
>>
>>
>> <!-- https://mvnrepository.com/artifact/org.glassfish.jersey.core/jersey-client -->
>>
>> <dependency>
>>
>> <groupId>org.glassfish.jersey.core</groupId>
>>
>> <artifactId>jersey-client</artifactId>
>>
>> <version>3.1.5</version>
>>
>> </dependency>
>>
>>
>>
>> <!-- https://mvnrepository.com/artifact/org.glassfish.hk2/hk2-api -->
>>
>> <dependency>
>>
>> <groupId>org.glassfish.hk2</groupId>
>>
>> <artifactId>hk2-api</artifactId>
>>
>> <version>3.0.5</version>
>>
>> </dependency>
>>
>>
>>
>> <!-- https://mvnrepository.com/artifact/org.glassfish.jersey.core/jersey-server -->
>>
>> <dependency>
>>
>> <groupId>org.glassfish.jersey.core</groupId>
>>
>> <artifactId>jersey-server</artifactId>
>>
>> <version>3.1.5</version>
>>
>> </dependency>
>>
>>
>>
>> <!-- https://mvnrepository.com/artifact/com.fasterxml.jackson.jakarta.rs/jackson-jakarta-rs-json-provider -->
>>
>> <dependency>
>>
>> <groupId>com.fasterxml.jackson.jakarta.rs</groupId>
>>
>> <artifactId>jackson-jakarta-rs-json-provider</artifactId>
>>
>> <version>2.16.0</version>
>>
>> </dependency>
>>
>>
>>
>> <!-- https://mvnrepository.com/artifact/org.antlr/antlr4-runtime -->
>>
>> <dependency>
>>
>> <groupId>org.antlr</groupId>
>>
>> <artifactId>antlr4-runtime</artifactId>
>>
>> <version>4.13.1</version>
>>
>> </dependency>
>>
>> <!-- https://mvnrepository.com/artifact/org.apache.commons/commons-lang3 -->
>>
>> <dependency>
>>
>> <groupId>org.apache.commons</groupId>
>>
>> <artifactId>commons-lang3</artifactId>
>>
>> <version>3.14.0</version>
>>
>> </dependency>
>>
>>
>> <dependency>
>>
>> <groupId>org.glassfish.jersey.inject</groupId>
>>
>> <artifactId>jersey-hk2</artifactId>
>>
>> <version>3.0.0</version>
>>
>> </dependency>
>>
>>
>>
>> <!-- https://mvnrepository.com/artifact/javax.ws.rs/javax.ws.rs-api -->
>>
>> <dependency>
>>
>> <groupId>javax.ws.rs</groupId>
>>
>> <artifactId>javax.ws.rs-api</artifactId>
>>
>> <version>2.1.1</version>
>>
>> </dependency>
>>
>>
>>
>>
>>
>> </dependencies>
>>
>> </project>
>>
>>
>> Thanks
>>
>>
>>
>
> This electronic communication and the information and any files transmitted with it, or attached to it, are confidential and are intended solely for the use of the individual or entity to whom it is addressed and may contain information that is confidential, legally privileged, protected by privacy laws, or otherwise restricted from disclosure to anyone else. If you are not the intended recipient or the person responsible for delivering the e-mail to the intended recipient, you are hereby notified that any use, copying, distributing, dissemination, forwarding, printing, or copying of this e-mail is strictly prohibited. If you received this e-mail in error, please return the e-mail to the sender, delete it from your computer, and destroy any printed copy of it.
---------------------------------------------------------------------
To unsubscribe, e-mail: scimple-unsubscribe@directory.apache.org
For additional commands, e-mail: scimple-help@directory.apache.org
Re: Re: Scim-Client
Posted by Azmathulla Chinnakondepalli <az...@broadcom.com.INVALID>.
the above code is for the issue mentioned on
https://lists.apache.org/thread/v0p1zwskpqhy3grjp43mf28xgvb875pq
On Tue, Dec 19, 2023 at 4:35 PM Azmathulla Chinnakondepalli <
azmathulla.chinnakondepalli@broadcom.com> wrote:
> HI,
>
> The sample code i have is below along with dependencies in pom.xml
>
> *import* jakarta.inject.Singleton;
>
> *import* jakarta.ws.rs.client.Client;
>
> *import* jakarta.ws.rs.client.ClientBuilder;
>
> *import* jakarta.ws.rs.client.ClientRequestFilter;
>
> *import* jakarta.ws.rs.core.MediaType;
>
> *import* jakarta.ws.rs.core.Response;
>
>
> *import* java.security.KeyManagementException;
>
> *import* java.security.NoSuchAlgorithmException;
>
> *import* java.util.ArrayList;
>
>
> *import* javax.net.ssl.HttpsURLConnection;
>
> *import* javax.net.ssl.SSLContext;
>
> *import* javax.net.ssl.TrustManager;
>
>
> *import* org.apache.directory.scim.client.rest.ScimUserClient;
>
> *import* org.apache.directory.scim.core.schema.SchemaRegistry;
>
> *import* org.apache.directory.scim.spec.resources.ScimUser;
>
> *import* org.apache.directory.scim.spec.schema.ResourceType;
>
> *import* org.apache.directory.scim.spec.schema.Schema;
>
> *import* org.apache.directory.scim.spec.schema.Schemas;
>
> *import* org.glassfish.jersey.client.ClientConfig;
>
> //import org.glassfish.jersey.jdk.connector.JdkConnectorProvider;
>
> *import* org.glassfish.jersey.server.ResourceConfig;
>
> *import* org.apache.directory.scim.spec.filter.FilterBuilder;
>
> *import* org.apache.directory.scim.spec.resources.Name;
>
> *import* org.apache.directory.scim.protocol.data.ListResponse;
>
> *import* org.apache.directory.scim.protocol.data.SearchRequest;
>
> *import* org.apache.directory.scim.protocol.exception.ScimException;
>
> *import* org.glassfish.hk2.utilities.binding.AbstractBinder;
>
>
> *public* *class* SampleUserScim {
>
> *public* *static* *void* main(String[] args) *throws*
> NoSuchAlgorithmException, KeyManagementException {
>
>
>
>
> // Create a TrustManager that trusts all certificates
>
> TrustManager[] trustAllCerts = *new* TrustManager[] { *new*
> TrustAllCertificates() };
>
>
> // Create an SSLContext
>
> SSLContext sslContext = SSLContext.*getInstance*("TLS");
>
> sslContext.init(*null*, trustAllCerts, *null*);
>
>
> // Define the base URL of the SCIM server
>
> String baseUrl = "https://<server_addr>/default/scim2/v1";
>
>
>
> // Set the SSLContext to the default HttpsURLConnection
>
> HttpsURLConnection.*setDefaultSSLSocketFactory*(sslContext
> .getSocketFactory());
>
>
> String bearerToken =...";
>
>
>
> *final* ResourceConfig config = *new* ResourceConfig();
>
> config.register(*new* AbstractBinder() {
>
>
> *protected* *void* configure() {
>
> bind(SchemaRegistry.*class*).to(SchemaRegistry.*class*
> ).in(Singleton.*class*);
>
> }
>
> });
>
> config.packages("org.apache.directory.scim");
>
>
>
> Client client = ClientBuilder.*newBuilder*().sslContext(sslContext
> ).hostnameVerifier((s1, s2) -> *true*)
>
> .withConfig(config)
>
> .register((ClientRequestFilter) requestContext ->
>
> requestContext.getHeaders().add("Authorization", "Bearer
> " + bearerToken))
>
>
> SchemaRegistry sch = *new* SchemaRegistry();
>
> Schema userSchema = Schemas.*schemaFor*(ScimUser.*class*);
>
> ResourceType userType = *new* ResourceType();
>
> userType.setId(ScimUser.*RESOURCE_NAME*);
>
> userType.setEndpoint("/Users");
>
> userType.setSchemaUrn(ScimUser.*SCHEMA_URI*);
>
> userType.setName(ScimUser.*RESOURCE_NAME*);
>
> userType.setDescription("Top level ScimUser");
>
> sch.addSchema(ScimUser.*class*, *null*);
>
>
> ScimUserClient userClient = *new* ScimUserClient(client,baseUrl);
>
>
>
>
> *try* {
>
> SearchRequest searchRequest = *new* SearchRequest()
>
> .setFilter(FilterBuilder.*create*().equalTo("userName",
> "lawrence_haley").build());
>
>
> ListResponse<ScimUser> users = userClient.find(searchRequest);
>
>
> }*catch*(ScimException e) {
>
> System.*out*.println("Exception while creating " + e
> .getMessage());
>
> }
>
> userClient.close();
>
> }
>
> }
>
>
>
> the dependencies included without which the code would not compile.
>
>
>
>
> <project xmlns=*"http://maven.apache.org/POM/4.0.0
> <http://maven.apache.org/POM/4.0.0>"* xmlns:xsi=*"http://www.w3.org/2001/XMLSchema-instance
> <http://www.w3.org/2001/XMLSchema-instance>"* xsi:schemaLocation=*"http://maven.apache.org/POM/4.0.0
> <http://maven.apache.org/POM/4.0.0>
> https://maven.apache.org/xsd/maven-4.0.0.xsd
> <https://maven.apache.org/xsd/maven-4.0.0.xsd>"*>
>
> <modelVersion>4.0.0</modelVersion>
>
> <groupId>sampletest</groupId>
>
> <artifactId>SampleMavenProject</artifactId>
>
> <version>0.0.1-SNAPSHOT</version>
>
> <description>sampletest</description>
>
> <dependencies>
>
> <dependency>
>
> <groupId>org.apache.directory.scimple</groupId>
>
> <artifactId>scim-client</artifactId>
>
> <version>1.0.0</version>
>
> <scope>system</scope>
>
> <systemPath>*/*.../scim-client-1.0.0-SNAPSHOT.jar</systemPath>
>
> </dependency>
>
> <dependency>
>
> <groupId>org.apache.directory.scimple</groupId>
>
> <artifactId>scim-spec-schema</artifactId>
>
> <version>1.0.0</version>
>
> <scope>system</scope>
>
> <systemPath>/.../scim-spec-schema-1.0.0-SNAPSHOT.jar</systemPath>
>
> </dependency>
>
> <dependency>
>
> <groupId>org.apache.directory.scimple</groupId>
>
> <artifactId>scim-core</artifactId>
>
> <version>1.0.0</version>
>
> <scope>system</scope>
>
> <systemPath>/.../scim-core-1.0.0-SNAPSHOT.jar</systemPath>
>
> </dependency>
>
> <dependency>
>
> <groupId>org.apache.directory.scimple</groupId>
>
> <artifactId>scim-spec-protocol</artifactId>
>
> <version>1.0.0</version>
>
> <scope>system</scope>
>
> <systemPath>/.../scim-spec-protocol-1.0.0-SNAPSHOT.jar</systemPath>
>
> </dependency>
>
> <dependency>
>
> <groupId>org.apache.directory.scimple</groupId>
>
> <artifactId>scim-server</artifactId>
>
> <version>1.0.0</version>
>
> <scope>system</scope>
>
> <systemPath>/.../scim-server-1.0.0-SNAPSHOT.jar</systemPath>
>
> </dependency>
>
> <!-- https://mvnrepository.com/artifact/jakarta.ws.rs/jakarta.ws.rs-api
> -->
>
> <dependency>
>
> <groupId>jakarta.ws.rs</groupId>
>
> <artifactId>jakarta.ws.rs-api</artifactId>
>
> <version>3.1.0</version>
>
> </dependency>
>
> <!-- https://mvnrepository.com/artifact/jakarta.inject/jakarta.inject-api
> -->
>
> <dependency>
>
> <groupId>jakarta.inject</groupId>
>
> <artifactId>jakarta.inject-api</artifactId>
>
> <version>2.0.1</version>
>
> </dependency>
>
>
>
> <dependency>
>
> <groupId>jakarta.platform</groupId>
>
> <artifactId>jakarta.jakartaee-bom</artifactId>
>
> <version>10.0.0</version>
>
> <scope>import</scope>
>
> <type>pom</type>
>
> </dependency>
>
> <dependency>
>
> <groupId>org.junit</groupId>
>
> <artifactId>junit-bom</artifactId>
>
> <version>5.10.1</version>
>
> <scope>import</scope>
>
> <type>pom</type>
>
> </dependency>
>
> <dependency>
>
> <groupId>com.fasterxml.jackson</groupId>
>
> <artifactId>jackson-bom</artifactId>
>
> <version>2.16.0</version>
>
> <scope>import</scope>
>
> <type>pom</type>
>
> </dependency>
>
> <dependency>
>
> <groupId>io.rest-assured</groupId>
>
> <artifactId>rest-assured-bom</artifactId>
>
> <type>pom</type>
>
> <version>5.4.0</version>
>
> <scope>import</scope>
>
> </dependency>
>
> <dependency>
>
> <groupId>org.glassfish.jersey</groupId>
>
> <artifactId>jersey-bom</artifactId>
>
> <version>3.1.5</version>
>
> <type>pom</type>
>
> <scope>import</scope>
>
> </dependency>
>
> <dependency>
>
> <groupId>org.hibernate.validator</groupId>
>
> <artifactId>hibernate-validator</artifactId>
>
> <version>8.0.1.Final</version>
>
> </dependency>
>
> <dependency>
>
> <groupId>org.glassfish</groupId>
>
> <artifactId>jakarta.el</artifactId>
>
> <version>4.0.2</version>
>
> <scope>test</scope>
>
> </dependency>
>
>
> <!-- Guava is a transitive dep, forcing a newer version to avoid
> older vulns -->
>
> <dependency>
>
> <groupId>com.google.guava</groupId>
>
> <artifactId>guava</artifactId>
>
> <version>32.1.3-android</version>
>
> </dependency>
>
> <dependency>
>
> <groupId>ch.qos.logback</groupId>
>
> <artifactId>logback-classic</artifactId>
>
> <version>1.4.8</version>
>
> </dependency>
>
> <dependency>
>
> <groupId>org.slf4j</groupId>
>
> <artifactId>jul-to-slf4j</artifactId>
>
> <version>2.0.9</version>
>
> </dependency>
>
> <dependency>
>
> <groupId>org.slf4j</groupId>
>
> <artifactId>slf4j-api</artifactId>
>
> <version>2.0.9</version>
>
> </dependency>
>
> <dependency>
>
> <groupId>org.slf4j</groupId>
>
> <artifactId>jcl-over-slf4j</artifactId>
>
> <version>2.0.9</version>
>
> </dependency>
>
> <dependency>
>
> <groupId>org.slf4j</groupId>
>
> <artifactId>slf4j-simple</artifactId>
>
> <version>2.0.9</version>
>
> <scope>test</scope>
>
> </dependency>
>
>
>
>
>
>
> <!-- Transitive dependencies specific versions -->
>
> <dependency>
>
> <groupId>org.apache.commons</groupId>
>
> <artifactId>commons-collections4</artifactId>
>
> <version>4.4</version>
>
> </dependency>
>
> <dependency>
>
> <groupId>commons-codec</groupId>
>
> <artifactId>commons-codec</artifactId>
>
> <version>1.16.0</version>
>
> </dependency>
>
>
>
> <!--
> https://mvnrepository.com/artifact/org.glassfish.jersey.core/jersey-client
> -->
>
> <dependency>
>
> <groupId>org.glassfish.jersey.core</groupId>
>
> <artifactId>jersey-client</artifactId>
>
> <version>3.1.5</version>
>
> </dependency>
>
>
>
> <!-- https://mvnrepository.com/artifact/org.glassfish.hk2/hk2-api
> -->
>
> <dependency>
>
> <groupId>org.glassfish.hk2</groupId>
>
> <artifactId>hk2-api</artifactId>
>
> <version>3.0.5</version>
>
> </dependency>
>
>
>
> <!--
> https://mvnrepository.com/artifact/org.glassfish.jersey.core/jersey-server
> -->
>
> <dependency>
>
> <groupId>org.glassfish.jersey.core</groupId>
>
> <artifactId>jersey-server</artifactId>
>
> <version>3.1.5</version>
>
> </dependency>
>
>
>
> <!--
> https://mvnrepository.com/artifact/com.fasterxml.jackson.jakarta.rs/jackson-jakarta-rs-json-provider
> -->
>
> <dependency>
>
> <groupId>com.fasterxml.jackson.jakarta.rs</groupId>
>
> <artifactId>jackson-jakarta-rs-json-provider</artifactId>
>
> <version>2.16.0</version>
>
> </dependency>
>
>
>
> <!-- https://mvnrepository.com/artifact/org.antlr/antlr4-runtime -->
>
> <dependency>
>
> <groupId>org.antlr</groupId>
>
> <artifactId>antlr4-runtime</artifactId>
>
> <version>4.13.1</version>
>
> </dependency>
>
> <!--
> https://mvnrepository.com/artifact/org.apache.commons/commons-lang3 -->
>
> <dependency>
>
> <groupId>org.apache.commons</groupId>
>
> <artifactId>commons-lang3</artifactId>
>
> <version>3.14.0</version>
>
> </dependency>
>
>
> <dependency>
>
> <groupId>org.glassfish.jersey.inject</groupId>
>
> <artifactId>jersey-hk2</artifactId>
>
> <version>3.0.0</version>
>
> </dependency>
>
>
>
> <!-- https://mvnrepository.com/artifact/javax.ws.rs/javax.ws.rs-api
> -->
>
> <dependency>
>
> <groupId>javax.ws.rs</groupId>
>
> <artifactId>javax.ws.rs-api</artifactId>
>
> <version>2.1.1</version>
>
> </dependency>
>
>
>
>
>
> </dependencies>
>
> </project>
>
>
> Thanks
>
>
>
--
This electronic communication and the information and any files transmitted
with it, or attached to it, are confidential and are intended solely for
the use of the individual or entity to whom it is addressed and may contain
information that is confidential, legally privileged, protected by privacy
laws, or otherwise restricted from disclosure to anyone else. If you are
not the intended recipient or the person responsible for delivering the
e-mail to the intended recipient, you are hereby notified that any use,
copying, distributing, dissemination, forwarding, printing, or copying of
this e-mail is strictly prohibited. If you received this e-mail in error,
please return the e-mail to the sender, delete it from your computer, and
destroy any printed copy of it.