smoyer64 closed pull request #2: Add in memory example - Port PennState in 
memory server example to new Apache structure
URL: https://github.com/apache/directory-scimple/pull/2
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/.editorconfig b/.editorconfig
new file mode 100644
index 0000000..cec47b0
--- /dev/null
+++ b/.editorconfig
@@ -0,0 +1,20 @@
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+[*]
+charset=utf-8
+end_of_line=lf
+insert_final_newline=true
+indent_style=space
+indent_size=2
diff --git a/pom.xml b/pom.xml
index 1819963..4732e37 100644
--- a/pom.xml
+++ b/pom.xml
@@ -128,7 +128,7 @@
       <dependency>
         <groupId>edu.psu.swe.commons</groupId>
         <artifactId>commons-jaxrs</artifactId>
-        <version>1.30</version>
+        <version>1.31</version>
       </dependency>
       <dependency>
         <groupId>javax</groupId>
@@ -336,7 +336,7 @@
         <plugin>
           <groupId>org.wildfly.plugins</groupId>
           <artifactId>wildfly-maven-plugin</artifactId>
-          <version>1.0.2.Final</version>
+          <version>1.2.2.Final</version>
           <inherited>true</inherited>
           <configuration>
             <id>${jbossServerId}</id>
diff --git a/scim-server/pom.xml b/scim-server/pom.xml
index a0fc94e..f301823 100644
--- a/scim-server/pom.xml
+++ b/scim-server/pom.xml
@@ -30,6 +30,7 @@
 
   <modules>
     <module>scim-server-common</module>
+    <module>scim-server-example</module>
   </modules>
 
 </project>
diff --git a/scim-server/scim-server-example/pom.xml 
b/scim-server/scim-server-example/pom.xml
new file mode 100644
index 0000000..297ad48
--- /dev/null
+++ b/scim-server/scim-server-example/pom.xml
@@ -0,0 +1,34 @@
+<!--  Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements.  See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership.  The ASF licenses this file
+ to you under the Apache License, Version 2.0 (the
+ "License"); you may not use this file except in compliance
+ with the License.  You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing,
+ software distributed under the License is distributed on an
+ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ KIND, either express or implied.  See the License for the
+ specific language governing permissions and limitations
+ under the License. -->
+<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 
http://maven.apache.org/xsd/maven-4.0.0.xsd";>
+  <modelVersion>4.0.0</modelVersion>
+
+  <parent>
+    <groupId>org.apache.directory.scim</groupId>
+    <artifactId>scim-server</artifactId>
+    <version>2.23-SNAPSHOT</version>
+  </parent>
+
+  <artifactId>scim-server-examples</artifactId>
+  <name>SCIM - Server - Examples</name>
+  <packaging>pom</packaging>
+
+  <modules>
+    <module>scim-server-memory</module>
+  </modules>
+
+</project>
diff --git a/scim-server/scim-server-example/scim-server-memory/README.md 
b/scim-server/scim-server-example/scim-server-memory/README.md
new file mode 100644
index 0000000..70f014e
--- /dev/null
+++ b/scim-server/scim-server-example/scim-server-memory/README.md
@@ -0,0 +1,20 @@
+Apache Directory SCIMple In Memory Example
+==========================================
+
+This example WAR project demo's how to:
+
+* Add a custom SCIM Extension
+* Manage Users and Groups (in memory)
+
+Use this as a starter point on how to integrate Apache Directory SCIMple into 
your own project.
+
+Run: `mvn tomee:run` and then access one of the endpoints:
+
+```bash
+# httpie
+http :8080/v2/Users
+
+# curl
+curl localhost:8080/v2/Users
+```
+n
diff --git a/scim-server/scim-server-example/scim-server-memory/pom.xml 
b/scim-server/scim-server-example/scim-server-memory/pom.xml
new file mode 100644
index 0000000..d5a2f3c
--- /dev/null
+++ b/scim-server/scim-server-example/scim-server-memory/pom.xml
@@ -0,0 +1,106 @@
+<!--  Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements.  See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership.  The ASF licenses this file
+ to you under the Apache License, Version 2.0 (the
+ "License"); you may not use this file except in compliance
+ with the License.  You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing,
+ software distributed under the License is distributed on an
+ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ KIND, either express or implied.  See the License for the
+ specific language governing permissions and limitations
+ under the License. -->
+<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 
http://maven.apache.org/xsd/maven-4.0.0.xsd";>
+  <modelVersion>4.0.0</modelVersion>
+
+  <parent>
+    <groupId>org.apache.directory.scim</groupId>
+    <artifactId>scim-server-examples</artifactId>
+    <version>2.23-SNAPSHOT</version>
+  </parent>
+
+  <artifactId>scim-server-memory</artifactId>
+  <name>SCIM - Server - Memory</name>
+  <packaging>war</packaging>
+
+  <dependencies>
+    <dependency>
+      <groupId>javax.ws.rs</groupId>
+      <artifactId>javax.ws.rs-api</artifactId>
+      <version>2.1</version>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.directory.scim</groupId>
+      <artifactId>scim-server-common</artifactId>
+    </dependency>
+    <dependency>
+      <groupId>org.projectlombok</groupId>
+      <artifactId>lombok</artifactId>
+      <scope>provided</scope>
+    </dependency>
+  </dependencies>
+
+  <build>
+    <plugins>
+      <plugin>
+        <groupId>org.apache.geronimo.genesis.plugins</groupId>
+        <artifactId>tools-maven-plugin</artifactId>
+        <configuration>
+          <requiredFiles></requiredFiles>
+        </configuration>
+      </plugin>
+      <plugin>
+        <groupId>org.apache.openejb.maven</groupId>
+        <artifactId>tomee-maven-plugin</artifactId>
+        <version>1.7.1</version>
+        <configuration>
+          <context>ROOT</context>
+          
<warFile>target/${project.artifactId}-${project.version}.war</warFile>
+          <tomeeVersion>1.7.1</tomeeVersion>
+          <tomeeClassifier>plus</tomeeClassifier>
+          <simpleLog>true</simpleLog>
+        </configuration>
+      </plugin>
+      <plugin>
+        <groupId>org.wildfly.plugins</groupId>
+        <artifactId>wildfly-maven-plugin</artifactId>
+        <configuration>
+          <skip>false</skip>
+          <filename>${project.artifactId}-${project.version}.war</filename>
+          <add-user>
+            <users>
+              <user>
+                <username>admin</username>
+                <password>admin.1234</password>
+              </user>
+            </users>
+          </add-user>
+        </configuration>
+      </plugin>
+    </plugins>
+  </build>
+
+  <profiles>
+    <profile>
+      <id>debug</id>
+      <build>
+        <plugins>
+          <plugin>
+            <groupId>org.wildfly.plugins</groupId>
+            <artifactId>wildfly-maven-plugin</artifactId>
+            <configuration>
+              <java-opts>
+                
<java-opt>-agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=5005</java-opt>
+              </java-opts>
+            </configuration>
+          </plugin>
+        </plugins>
+      </build>
+    </profile>
+  </profiles>
+
+</project>
diff --git 
a/scim-server/scim-server-example/scim-server-memory/src/main/java/org/apache/directory/scim/example/memory/extensions/LuckyNumberExtension.java
 
b/scim-server/scim-server-example/scim-server-memory/src/main/java/org/apache/directory/scim/example/memory/extensions/LuckyNumberExtension.java
new file mode 100644
index 0000000..c82af27
--- /dev/null
+++ 
b/scim-server/scim-server-example/scim-server-memory/src/main/java/org/apache/directory/scim/example/memory/extensions/LuckyNumberExtension.java
@@ -0,0 +1,62 @@
+/*
+* Licensed to the Apache Software Foundation (ASF) under one
+* or more contributor license agreements.  See the NOTICE file
+* distributed with this work for additional information
+* regarding copyright ownership.  The ASF licenses this file
+* to you under the Apache License, Version 2.0 (the
+* "License"); you may not use this file except in compliance
+* with the License.  You may obtain a copy of the License at
+
+* http://www.apache.org/licenses/LICENSE-2.0
+
+* Unless required by applicable law or agreed to in writing,
+* software distributed under the License is distributed on an
+* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+* KIND, either express or implied.  See the License for the
+* specific language governing permissions and limitations
+* under the License.
+*/
+
+package org.apache.directory.scim.example.memory.extensions;
+
+import javax.xml.bind.annotation.XmlAccessType;
+import javax.xml.bind.annotation.XmlAccessorType;
+import javax.xml.bind.annotation.XmlElement;
+import javax.xml.bind.annotation.XmlRootElement;
+
+import lombok.Data;
+import org.apache.directory.scim.spec.annotation.ScimAttribute;
+import org.apache.directory.scim.spec.annotation.ScimExtensionType;
+import org.apache.directory.scim.spec.resources.ScimExtension;
+import org.apache.directory.scim.spec.schema.Schema;
+
+/**
+ * Allows a User's lucky number to be passed as part of the User's entry via
+ * the SCIM protocol.
+ * 
+ * @author Chris Harm &lt;crh5...@psu.edu&gt;
+ */
+@XmlRootElement( name = "LuckyNumberExtension", namespace = 
"http://www.psu.edu/schemas/psu-scim"; )
+@XmlAccessorType(XmlAccessType.NONE)
+@Data
+@ScimExtensionType(id = LuckyNumberExtension.SCHEMA_URN, description="Lucky 
Numbers", name="LuckyNumbers", required=true)
+public class LuckyNumberExtension implements ScimExtension {
+  
+  public static final String  SCHEMA_URN = 
"urn:mem:params:scim:schemas:extension:LuckyNumberExtension";
+
+  @ScimAttribute(returned=Schema.Attribute.Returned.DEFAULT, required=true)
+  @XmlElement
+  private long luckyNumber;
+  
+  /**
+   * Provides the URN associated with this extension which, as defined by the
+   * SCIM specification is the extension's unique identifier.
+   * 
+   * @return The extension's URN.
+   */
+  @Override
+  public String getUrn() {
+    return SCHEMA_URN;
+  }
+
+}
diff --git 
a/scim-server/scim-server-example/scim-server-memory/src/main/java/org/apache/directory/scim/example/memory/rest/RestApplication.java
 
b/scim-server/scim-server-example/scim-server-memory/src/main/java/org/apache/directory/scim/example/memory/rest/RestApplication.java
new file mode 100644
index 0000000..625ee20
--- /dev/null
+++ 
b/scim-server/scim-server-example/scim-server-memory/src/main/java/org/apache/directory/scim/example/memory/rest/RestApplication.java
@@ -0,0 +1,43 @@
+/*
+* Licensed to the Apache Software Foundation (ASF) under one
+* or more contributor license agreements.  See the NOTICE file
+* distributed with this work for additional information
+* regarding copyright ownership.  The ASF licenses this file
+* to you under the Apache License, Version 2.0 (the
+* "License"); you may not use this file except in compliance
+* with the License.  You may obtain a copy of the License at
+
+* http://www.apache.org/licenses/LICENSE-2.0
+
+* Unless required by applicable law or agreed to in writing,
+* software distributed under the License is distributed on an
+* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+* KIND, either express or implied.  See the License for the
+* specific language governing permissions and limitations
+* under the License.
+*/
+
+package org.apache.directory.scim.example.memory.rest;
+
+import org.apache.directory.scim.server.rest.ScimResourceHelper;
+
+import java.util.HashSet;
+import java.util.Set;
+
+import javax.ws.rs.ApplicationPath;
+import javax.ws.rs.core.Application;
+
+@ApplicationPath("v2")
+public class RestApplication extends Application {
+  
+  @Override
+  public Set<Class<?>> getClasses() {
+    Set<Class<?>> clazzes = new HashSet<Class<?>>();
+    
+    clazzes.addAll(ScimResourceHelper.getScimClassesToLoad());
+    clazzes.addAll(ScimResourceHelper.getSwaggerClassesToLoad());
+
+    return clazzes;
+  }
+  
+}
diff --git 
a/scim-server/scim-server-example/scim-server-memory/src/main/java/org/apache/directory/scim/example/memory/rest/SwaggerJaxrsConfig.java
 
b/scim-server/scim-server-example/scim-server-memory/src/main/java/org/apache/directory/scim/example/memory/rest/SwaggerJaxrsConfig.java
new file mode 100644
index 0000000..66df243
--- /dev/null
+++ 
b/scim-server/scim-server-example/scim-server-memory/src/main/java/org/apache/directory/scim/example/memory/rest/SwaggerJaxrsConfig.java
@@ -0,0 +1,66 @@
+/*
+* Licensed to the Apache Software Foundation (ASF) under one
+* or more contributor license agreements.  See the NOTICE file
+* distributed with this work for additional information
+* regarding copyright ownership.  The ASF licenses this file
+* to you under the Apache License, Version 2.0 (the
+* "License"); you may not use this file except in compliance
+* with the License.  You may obtain a copy of the License at
+
+* http://www.apache.org/licenses/LICENSE-2.0
+
+* Unless required by applicable law or agreed to in writing,
+* software distributed under the License is distributed on an
+* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+* KIND, either express or implied.  See the License for the
+* specific language governing permissions and limitations
+* under the License.
+*/
+
+package org.apache.directory.scim.example.memory.rest;
+
+import io.swagger.jaxrs.config.BeanConfig;
+import io.swagger.util.Json;
+import io.swagger.util.Yaml;
+
+import javax.servlet.ServletContextEvent;
+import javax.servlet.ServletContextListener;
+import javax.servlet.annotation.WebListener;
+
+import org.apache.directory.scim.server.rest.ScimResourceHelper;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.fasterxml.jackson.module.jaxb.JaxbAnnotationModule;
+
+@WebListener
+public class SwaggerJaxrsConfig implements ServletContextListener {
+
+  private static final Logger LOGGER = 
LoggerFactory.getLogger(SwaggerJaxrsConfig.class);
+
+  public static BeanConfig beanConfig = new BeanConfig();
+
+  public void contextInitialized(ServletContextEvent event) {
+    LOGGER.debug("Initializing swagger...");
+
+    try {
+      // BeanConfig beanConfig = new BeanConfig();
+      beanConfig.setBasePath(event.getServletContext().getContextPath() + 
"/v2");
+      
beanConfig.setResourcePackage(ScimResourceHelper.class.getPackage().getName().replaceAll("server\\.rest$",
 ""));
+      beanConfig.setScan(true);
+      beanConfig.setTitle("In-Memory SCIM Server");
+      beanConfig.setDescription("In Memory SCIM Server Example 
Implementation");
+      beanConfig.setVersion("2.0");
+
+      Json.mapper().registerModule(new JaxbAnnotationModule());
+      Yaml.mapper().registerModule(new JaxbAnnotationModule());
+
+    } catch (Exception e) {
+      LOGGER.error("Error initializing swagger", e);
+    }
+  }
+
+  public void contextDestroyed(ServletContextEvent event) {
+    // do on application destroy
+  }
+}
diff --git 
a/scim-server/scim-server-example/scim-server-memory/src/main/java/org/apache/directory/scim/example/memory/service/InMemoryGroupService.java
 
b/scim-server/scim-server-example/scim-server-memory/src/main/java/org/apache/directory/scim/example/memory/service/InMemoryGroupService.java
new file mode 100644
index 0000000..b39d0d7
--- /dev/null
+++ 
b/scim-server/scim-server-example/scim-server-memory/src/main/java/org/apache/directory/scim/example/memory/service/InMemoryGroupService.java
@@ -0,0 +1,89 @@
+/*
+* Licensed to the Apache Software Foundation (ASF) under one
+* or more contributor license agreements.  See the NOTICE file
+* distributed with this work for additional information
+* regarding copyright ownership.  The ASF licenses this file
+* to you under the Apache License, Version 2.0 (the
+* "License"); you may not use this file except in compliance
+* with the License.  You may obtain a copy of the License at
+
+* http://www.apache.org/licenses/LICENSE-2.0
+
+* Unless required by applicable law or agreed to in writing,
+* software distributed under the License is distributed on an
+* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+* KIND, either express or implied.  See the License for the
+* specific language governing permissions and limitations
+* under the License.
+*/
+
+package org.apache.directory.scim.example.memory.service;
+
+import 
org.apache.directory.scim.server.exception.UnableToUpdateResourceException;
+import org.apache.directory.scim.server.provider.Provider;
+import org.apache.directory.scim.server.provider.UpdateRequest;
+import org.apache.directory.scim.spec.protocol.filter.FilterResponse;
+import org.apache.directory.scim.spec.protocol.search.Filter;
+import org.apache.directory.scim.spec.protocol.search.PageRequest;
+import org.apache.directory.scim.spec.protocol.search.SortRequest;
+import org.apache.directory.scim.spec.resources.ScimExtension;
+import org.apache.directory.scim.spec.resources.ScimGroup;
+
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import javax.enterprise.context.ApplicationScoped;
+import javax.inject.Named;
+
+@Named
+@ApplicationScoped
+public class InMemoryGroupService implements Provider<ScimGroup> {
+
+  private Map<String, ScimGroup> groups = new HashMap<>();
+  
+  @Override
+  public ScimGroup create(ScimGroup resource) {
+    String resourceId = resource.getId();
+    int idCandidate = resource.hashCode();
+    String id = resourceId != null ? resourceId : 
Integer.toString(idCandidate);
+
+    while (groups.containsKey(id)) {
+      id = Integer.toString(idCandidate);
+      ++idCandidate;
+    }
+    groups.put(id, resource);
+    resource.setId(id);
+    return resource;
+  }
+
+  @Override
+  public ScimGroup update(UpdateRequest<ScimGroup> updateRequest) throws 
UnableToUpdateResourceException {
+    String id = updateRequest.getId();
+    ScimGroup resource = updateRequest.getResource();
+    groups.put(id, resource);
+    return resource;
+  }
+
+  @Override
+  public ScimGroup get(String id) {
+    return groups.get(id);
+  }
+
+  @Override
+  public void delete(String id) {
+    groups.remove(id);
+  }
+
+  @Override
+  public FilterResponse<ScimGroup> find(Filter filter, PageRequest 
pageRequest, SortRequest sortRequest) {
+    return new FilterResponse<>(groups.values(), pageRequest, groups.size());
+  }
+
+  @Override
+  public List<Class<? extends ScimExtension>> getExtensionList() {
+    return Collections.emptyList();
+  }
+
+}
diff --git 
a/scim-server/scim-server-example/scim-server-memory/src/main/java/org/apache/directory/scim/example/memory/service/InMemorySelfResolverImpl.java
 
b/scim-server/scim-server-example/scim-server-memory/src/main/java/org/apache/directory/scim/example/memory/service/InMemorySelfResolverImpl.java
new file mode 100644
index 0000000..cbdf4db
--- /dev/null
+++ 
b/scim-server/scim-server-example/scim-server-memory/src/main/java/org/apache/directory/scim/example/memory/service/InMemorySelfResolverImpl.java
@@ -0,0 +1,38 @@
+/*
+* Licensed to the Apache Software Foundation (ASF) under one
+* or more contributor license agreements.  See the NOTICE file
+* distributed with this work for additional information
+* regarding copyright ownership.  The ASF licenses this file
+* to you under the Apache License, Version 2.0 (the
+* "License"); you may not use this file except in compliance
+* with the License.  You may obtain a copy of the License at
+
+* http://www.apache.org/licenses/LICENSE-2.0
+
+* Unless required by applicable law or agreed to in writing,
+* software distributed under the License is distributed on an
+* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+* KIND, either express or implied.  See the License for the
+* specific language governing permissions and limitations
+* under the License.
+*/
+
+package org.apache.directory.scim.example.memory.service;
+
+import org.apache.directory.scim.server.exception.UnableToResolveIdException;
+import org.apache.directory.scim.server.provider.SelfIdResolver;
+
+import java.security.Principal;
+
+import javax.ejb.Stateless;
+import javax.ws.rs.core.Response.Status;
+
+@Stateless
+public class InMemorySelfResolverImpl implements SelfIdResolver {
+
+  @Override
+  public String resolveToInternalId(Principal principal) throws 
UnableToResolveIdException {
+    throw new UnableToResolveIdException(Status.NOT_IMPLEMENTED, "Caller 
Principal not available");
+  }
+
+}
diff --git 
a/scim-server/scim-server-example/scim-server-memory/src/main/java/org/apache/directory/scim/example/memory/service/InMemoryUserService.java
 
b/scim-server/scim-server-example/scim-server-memory/src/main/java/org/apache/directory/scim/example/memory/service/InMemoryUserService.java
new file mode 100644
index 0000000..a8479e6
--- /dev/null
+++ 
b/scim-server/scim-server-example/scim-server-memory/src/main/java/org/apache/directory/scim/example/memory/service/InMemoryUserService.java
@@ -0,0 +1,146 @@
+/*
+* Licensed to the Apache Software Foundation (ASF) under one
+* or more contributor license agreements.  See the NOTICE file
+* distributed with this work for additional information
+* regarding copyright ownership.  The ASF licenses this file
+* to you under the Apache License, Version 2.0 (the
+* "License"); you may not use this file except in compliance
+* with the License.  You may obtain a copy of the License at
+
+* http://www.apache.org/licenses/LICENSE-2.0
+
+* Unless required by applicable law or agreed to in writing,
+* software distributed under the License is distributed on an
+* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+* KIND, either express or implied.  See the License for the
+* specific language governing permissions and limitations
+* under the License.
+*/
+
+package org.apache.directory.scim.example.memory.service;
+
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import javax.annotation.PostConstruct;
+import javax.enterprise.context.ApplicationScoped;
+import javax.inject.Named;
+
+import 
org.apache.directory.scim.example.memory.extensions.LuckyNumberExtension;
+import 
org.apache.directory.scim.server.exception.UnableToUpdateResourceException;
+import org.apache.directory.scim.server.provider.Provider;
+import org.apache.directory.scim.server.provider.UpdateRequest;
+import org.apache.directory.scim.spec.protocol.filter.FilterResponse;
+import org.apache.directory.scim.spec.protocol.search.Filter;
+import org.apache.directory.scim.spec.protocol.search.PageRequest;
+import org.apache.directory.scim.spec.protocol.search.SortRequest;
+import org.apache.directory.scim.spec.resources.Email;
+import org.apache.directory.scim.spec.resources.ScimExtension;
+import org.apache.directory.scim.spec.resources.ScimResource;
+import org.apache.directory.scim.spec.resources.ScimUser;
+
+/**
+ * Creates a singleton (effectively) Provider<User> with a memory-based
+ * persistence layer.
+ * 
+ * @author Chris Harm &lt;crh5...@psu.edu&gt;
+ */
+@Named
+@ApplicationScoped
+public class InMemoryUserService implements Provider<ScimUser> {
+  
+  static final String DEFAULT_USER_ID = "1";
+  static final String DEFAULT_USER_EXTERNAL_ID = "e" + DEFAULT_USER_ID;
+  static final String DEFAULT_USER_DISPLAY_NAME = "User " + DEFAULT_USER_ID;
+  static final String DEFAULT_USER_EMAIL_VALUE = "e...@example.com";
+  static final String DEFAULT_USER_EMAIL_TYPE = "work";
+  static final int DEFAULT_USER_LUCKY_NUMBER = 7;
+
+  private Map<String, ScimUser> users = new HashMap<>();
+  
+  @PostConstruct
+  public void init() {
+    ScimUser user = new ScimUser();
+    user.setId(DEFAULT_USER_ID);
+    user.setExternalId(DEFAULT_USER_EXTERNAL_ID);
+    user.setUserName(DEFAULT_USER_EXTERNAL_ID);
+    user.setDisplayName(DEFAULT_USER_DISPLAY_NAME);
+    Email email = new Email();
+    email.setDisplay(DEFAULT_USER_EMAIL_VALUE);
+    email.setValue(DEFAULT_USER_EMAIL_VALUE);
+    email.setType(DEFAULT_USER_EMAIL_TYPE);
+    email.setPrimary(true);
+    user.setEmails(Arrays.asList(email));
+    
+    LuckyNumberExtension luckyNumberExtension = new LuckyNumberExtension();
+    luckyNumberExtension.setLuckyNumber(DEFAULT_USER_LUCKY_NUMBER);
+    
+    user.addExtension(luckyNumberExtension);
+    
+    users.put(user.getId(), user);
+  }
+  
+  /**
+   * @see Provider#create(ScimResource)
+   */
+  @Override
+  public ScimUser create(ScimUser resource) {
+    String resourceId = resource.getId();
+    int idCandidate = resource.hashCode();
+    String id = resourceId != null ? resourceId : 
Integer.toString(idCandidate);
+
+    while (users.containsKey(id)) {
+      id = Integer.toString(idCandidate);
+      ++idCandidate;
+    }
+    users.put(id, resource);
+    resource.setId(id);
+    return resource;
+  }
+
+  /**
+   * @see Provider#update(UpdateRequest)
+   */
+  @Override
+  public ScimUser update(UpdateRequest<ScimUser> updateRequest) throws 
UnableToUpdateResourceException {
+    String id = updateRequest.getId();
+    ScimUser resource = updateRequest.getResource();
+    users.put(id, resource);
+    return resource;
+  }
+
+  /**
+   * @see Provider#get(java.lang.String)
+   */
+  @Override
+  public ScimUser get(String id) {
+    return users.get(id);
+  }
+
+  /**
+   * @see Provider#delete(java.lang.String)
+   */
+  @Override
+  public void delete(String id) {
+    users.remove(id);
+  }
+
+  /**
+   * @see Provider#find(Filter, PageRequest, SortRequest)
+   */
+  @Override
+  public FilterResponse<ScimUser> find(Filter filter, PageRequest pageRequest, 
SortRequest sortRequest) {
+    return new FilterResponse<>(users.values(), pageRequest, users.size());
+  }
+
+  /**
+   * @see Provider#getExtensionList()
+   */
+  @Override
+  public List<Class<? extends ScimExtension>> getExtensionList() {
+    return Arrays.asList(LuckyNumberExtension.class);
+  }
+
+}
diff --git 
a/scim-server/scim-server-example/scim-server-memory/src/main/java/org/apache/directory/scim/example/memory/service/ScimConfigurator.java
 
b/scim-server/scim-server-example/scim-server-memory/src/main/java/org/apache/directory/scim/example/memory/service/ScimConfigurator.java
new file mode 100644
index 0000000..f8fe3d4
--- /dev/null
+++ 
b/scim-server/scim-server-example/scim-server-memory/src/main/java/org/apache/directory/scim/example/memory/service/ScimConfigurator.java
@@ -0,0 +1,67 @@
+/*
+* Licensed to the Apache Software Foundation (ASF) under one
+* or more contributor license agreements.  See the NOTICE file
+* distributed with this work for additional information
+* regarding copyright ownership.  The ASF licenses this file
+* to you under the Apache License, Version 2.0 (the
+* "License"); you may not use this file except in compliance
+* with the License.  You may obtain a copy of the License at
+
+* http://www.apache.org/licenses/LICENSE-2.0
+
+* Unless required by applicable law or agreed to in writing,
+* software distributed under the License is distributed on an
+* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+* KIND, either express or implied.  See the License for the
+* specific language governing permissions and limitations
+* under the License.
+*/
+
+package org.apache.directory.scim.example.memory.service;
+
+import javax.enterprise.inject.Instance;
+import javax.inject.Inject;
+import javax.servlet.ServletContextEvent;
+import javax.servlet.ServletContextListener;
+import javax.servlet.annotation.WebListener;
+
+import org.apache.directory.scim.server.exception.InvalidProviderException;
+import 
org.apache.directory.scim.server.exception.UnableToRetrieveExtensionsException;
+import org.apache.directory.scim.server.provider.ProviderRegistry;
+import org.apache.directory.scim.spec.resources.ScimGroup;
+import org.apache.directory.scim.spec.resources.ScimUser;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.fasterxml.jackson.core.JsonProcessingException;
+
+@WebListener
+public class ScimConfigurator implements ServletContextListener {
+
+  public static final Logger LOG = 
LoggerFactory.getLogger(ScimConfigurator.class);
+
+  @Inject
+  private ProviderRegistry providerRegistry;
+
+  @Inject
+  private Instance<InMemoryUserService> userProviderInstance;
+
+  @Inject
+  private Instance<InMemoryGroupService> groupProviderInstance;
+
+  @Override
+  public void contextInitialized(ServletContextEvent sce) {
+    try {
+      providerRegistry.registerProvider(ScimUser.class, userProviderInstance);
+      providerRegistry.registerProvider(ScimGroup.class, 
groupProviderInstance);
+    } catch (InvalidProviderException | JsonProcessingException | 
UnableToRetrieveExtensionsException e) {
+      e.printStackTrace();
+    }
+  }
+
+  @Override
+  public void contextDestroyed(ServletContextEvent arg0) {
+    // NOOP
+  }
+
+}
diff --git 
a/scim-server/scim-server-example/scim-server-memory/src/main/webapp/WEB-INF/beans.xml
 
b/scim-server/scim-server-example/scim-server-memory/src/main/webapp/WEB-INF/beans.xml
new file mode 100644
index 0000000..a47f43b
--- /dev/null
+++ 
b/scim-server/scim-server-example/scim-server-memory/src/main/webapp/WEB-INF/beans.xml
@@ -0,0 +1,22 @@
+<!--  Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements.  See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership.  The ASF licenses this file
+ to you under the Apache License, Version 2.0 (the
+ "License"); you may not use this file except in compliance
+ with the License.  You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing,
+ software distributed under the License is distributed on an
+ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ KIND, either express or implied.  See the License for the
+ specific language governing permissions and limitations
+ under the License. -->
+<beans xmlns="http://xmlns.jcp.org/xml/ns/javaee";
+       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
+       xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee 
http://xmlns.jcp.org/xml/ns/javaee/beans_1_1.xsd";
+       version="1.1" bean-discovery-mode="all">
+       
+</beans>
diff --git 
a/scim-server/scim-server-example/scim-server-memory/src/main/webapp/WEB-INF/jboss-web.xml
 
b/scim-server/scim-server-example/scim-server-memory/src/main/webapp/WEB-INF/jboss-web.xml
new file mode 100644
index 0000000..ed064f3
--- /dev/null
+++ 
b/scim-server/scim-server-example/scim-server-memory/src/main/webapp/WEB-INF/jboss-web.xml
@@ -0,0 +1,8 @@
+<?xml version="1.0" encoding="UTF-8"?>
+ <jboss-web xmlns="http://www.jboss.com/xml/ns/javaee";
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
+  xsi:schemaLocation="
+  http://www.jboss.com/xml/ns/javaee
+  http://www.jboss.org/j2ee/schema/jboss-web_5_1.xsd";>
+  <context-root>/</context-root>
+ </jboss-web>
diff --git 
a/scim-server/scim-server-example/scim-server-memory/src/main/webapp/WEB-INF/web.xml
 
b/scim-server/scim-server-example/scim-server-memory/src/main/webapp/WEB-INF/web.xml
new file mode 100644
index 0000000..a363e6c
--- /dev/null
+++ 
b/scim-server/scim-server-example/scim-server-memory/src/main/webapp/WEB-INF/web.xml
@@ -0,0 +1,22 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--  Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements.  See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership.  The ASF licenses this file
+ to you under the Apache License, Version 2.0 (the
+ "License"); you may not use this file except in compliance
+ with the License.  You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing,
+ software distributed under the License is distributed on an
+ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ KIND, either express or implied.  See the License for the
+ specific language governing permissions and limitations
+ under the License. -->
+<web-app version="3.0" xmlns="http://java.sun.com/xml/ns/javaee";
+         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
+         xsi:schemaLocation="http://java.sun.com/xml/ns/javaee 
http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd";>
+
+</web-app>


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services

Reply via email to