Ver Fonte

SCIM Support

shimingxy há 5 anos atrás
pai
commit
cd0ce7d54d

+ 2 - 3
maxkey-identitys/maxkey-identity-scim/.settings/org.eclipse.wst.common.component

@@ -1,9 +1,8 @@
-<?xml version="1.0" encoding="UTF-8"?><project-modules id="moduleCoreId" project-version="1.5.0">
+<?xml version="1.0" encoding="UTF-8"?>
+<project-modules id="moduleCoreId" project-version="1.5.0">
 	<wb-module deploy-name="maxkey-identity-scim">
 		<wb-resource deploy-path="/" source-path="src/main/resources"/>
 		<wb-resource deploy-path="/" source-path="src/main/java"/>
-        <wb-resource deploy-path="/" source-path="/src/main/java"/>
-        <wb-resource deploy-path="/" source-path="/src/main/resources"/>
 		<dependent-module deploy-path="../" handle="module:/resource/maxkey-core/maxkey-core">
 			<dependency-type>uses</dependency-type>
 		</dependent-module>

+ 3 - 0
maxkey-identitys/maxkey-identity-scim/src/main/java/org/maxkey/identity/scim/controller/GroupController.java

@@ -1,5 +1,8 @@
 package org.maxkey.identity.scim.controller;
 
+import org.springframework.web.bind.annotation.RequestMapping;
+
+@RequestMapping(value = "/identity/scim/v2/Groups")
 public class GroupController {
 
 }

+ 3 - 1
maxkey-identitys/maxkey-identity-scim/src/main/java/org/maxkey/identity/scim/controller/ServiceProviderConfigController.java

@@ -2,18 +2,20 @@ package org.maxkey.identity.scim.controller;
 
 import com.fasterxml.jackson.annotation.JsonInclude;
 import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.ResponseBody;
 import org.springframework.web.bind.annotation.RestController;
 
 import java.util.HashSet;
 import java.util.Set;
 
 @RestController
-@RequestMapping(value = "/ServiceProviderConfig")
+@RequestMapping(value = "/identity/scim/v2/ServiceProviderConfig")
 public class ServiceProviderConfigController {
 
     public static final int MAX_RESULTS = 100;
     
     @RequestMapping
+    @ResponseBody
     public ServiceProviderConfig getConfig() {
         return ServiceProviderConfig.INSTANCE;
     }

+ 77 - 0
maxkey-identitys/maxkey-identity-scim/src/main/java/org/maxkey/identity/scim/controller/UserController.java

@@ -1,5 +1,82 @@
 package org.maxkey.identity.scim.controller;
 
+import java.io.IOException;
+import java.util.Map;
+
+import org.maxkey.identity.scim.resources.ScimSearchResult;
+import org.maxkey.identity.scim.resources.User;
+import org.springframework.http.HttpStatus;
+import org.springframework.http.ResponseEntity;
+import org.springframework.http.converter.json.MappingJacksonValue;
+import org.springframework.web.bind.annotation.PathVariable;
+import org.springframework.web.bind.annotation.RequestBody;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestMethod;
+import org.springframework.web.bind.annotation.RequestParam;
+import org.springframework.web.bind.annotation.ResponseStatus;
+import org.springframework.web.bind.annotation.RestController;
+import org.springframework.web.util.UriComponentsBuilder;
+
+/**
+ * This Controller is used to manage User
+ * <p>
+ * http://tools.ietf.org/html/draft-ietf-scim-core-schema-00#section-6
+ * <p>
+ * it is based on the SCIM 2.0 API Specification:
+ * <p>
+ * http://tools.ietf.org/html/draft-ietf-scim-api-00#section-3
+ */
+@RestController
+@RequestMapping(value = "/identity/scim/v2/Users")
 public class UserController {
 
+    @RequestMapping(value = "/{id}", method = RequestMethod.GET)
+    public MappingJacksonValue getUser(@PathVariable String id,
+                                       @RequestParam(required = false) String attributes) {
+        User user = null;
+        return null;
+    }
+
+    @RequestMapping(method = RequestMethod.POST)
+    public ResponseEntity<MappingJacksonValue> create(@RequestBody  User user,
+                                                      @RequestParam(required = false) String attributes,
+                                                      UriComponentsBuilder builder) throws IOException {
+        User createdUser = null;
+        return null;
+    }
+
+    @RequestMapping(value = "/{id}", method = RequestMethod.PUT)
+    public ResponseEntity<MappingJacksonValue> replace(@PathVariable String id,
+                                                       @RequestBody User user,
+                                                       @RequestParam(required = false) String attributes)
+            throws IOException {
+        User createdUser = null;
+        return null;
+    }
+
+    @RequestMapping(value = "/{id}", method = RequestMethod.DELETE)
+    @ResponseStatus(HttpStatus.OK)
+    public void delete(@PathVariable final String id) {
+        //tokenService.revokeAllTokensOfUser(id);
+       
+    }
+
+    @RequestMapping(method = RequestMethod.GET)
+    public MappingJacksonValue searchWithGet(@RequestParam Map<String, String> requestParameters) {
+        return searchWithPost(requestParameters);
+    }
+
+    @RequestMapping(value = "/.search", method = RequestMethod.POST)
+    public MappingJacksonValue searchWithPost(@RequestParam Map<String, String> requestParameters) {
+        ScimSearchResult<User> scimSearchResult = null;
+        /*
+                requestParameters.get("filter"),
+                requestParameters.get("sortBy"),
+                requestParameters.getOrDefault("sortOrder", "ascending"),             // scim default
+                Integer.parseInt(requestParameters.getOrDefault("count", "" + ServiceProviderConfigController.MAX_RESULTS)),
+                Integer.parseInt(requestParameters.getOrDefault("startIndex", "1")); // scim default
+*/
+        String attributes = (requestParameters.containsKey("attributes") ? requestParameters.get("attributes") : "");
+        return null;
+    }
 }

+ 81 - 0
maxkey-identitys/maxkey-identity-scim/src/main/java/org/maxkey/identity/scim/resources/ScimSearchResult.java

@@ -0,0 +1,81 @@
+package org.maxkey.identity.scim.resources;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
+import com.fasterxml.jackson.annotation.JsonProperty;
+
+public class ScimSearchResult <T>{
+
+    public static final String SCHEMA = "urn:ietf:params:scim:api:messages:2.0:ListResponse";
+    public static final int MAX_RESULTS = 100;
+    private long totalResults;
+    private long itemsPerPage;
+    private long startIndex;
+    private Set<String> schemas = new HashSet<>(Collections.singletonList(SCHEMA));
+    private List<T> resources = new ArrayList<>();
+
+    /**
+     * Default constructor for Jackson
+     */
+    ScimSearchResult() {
+    }
+
+    public ScimSearchResult(List<T> resources, long totalResults, long itemsPerPage, long startIndex) {
+        this.resources = resources;
+        this.totalResults = totalResults;
+        this.itemsPerPage = itemsPerPage;
+        this.startIndex = startIndex;
+    }
+
+
+    /**
+     * gets a list of found {@link User}s or {@link Group}s
+     *
+     * @return a list of found resources
+     */
+    @JsonProperty("Resources")
+    public List<T> getResources() {
+        return resources;
+    }
+
+    /**
+     * The total number of results returned by the list or query operation. This may not be equal to the number of
+     * elements in the Resources attribute of the list response if pagination is requested.
+     *
+     * @return the total result
+     */
+    public long getTotalResults() {
+        return totalResults;
+    }
+
+    /**
+     * Gets the schemas of the search result
+     *
+     * @return the search result schemas
+     */
+    public Set<String> getSchemas() {
+        return schemas;
+    }
+
+    /**
+     * The number of Resources returned in a list response page.
+     *
+     * @return items per page
+     */
+    public long getItemsPerPage() {
+        return itemsPerPage;
+    }
+
+    /**
+     * The 1-based index of the first result in the current set of list results.
+     *
+     * @return the start index of the actual page
+     */
+    public long getStartIndex() {
+        return startIndex;
+    }
+}

+ 2 - 1
maxkey-web-manage/build.gradle

@@ -21,7 +21,8 @@ dependencies {
    	compile project(":maxkey-dao")
    	compile project(":maxkey-client-sdk")
    	compile project(":maxkey-protocols:maxkey-protocol-oauth-2.0")
-   	compile project(":maxkey-protocols:maxkey-protocol-saml-2.0")   	
+   	compile project(":maxkey-protocols:maxkey-protocol-saml-2.0")   
+   	compile project(":maxkey-identitys:maxkey-identity-scim")   	
    	
 }
 

+ 2 - 1
maxkey-web-manage/src/main/java/org/maxkey/MaxKeyMgtApplication.java

@@ -33,7 +33,8 @@ import org.springframework.context.annotation.ImportResource;
     "org.maxkey.authn",
     "org.maxkey.dao",
     "org.maxkey.web",
-    "org.maxkey.web.tag"
+    "org.maxkey.web.tag",
+    "org.maxkey.identity.scim.controller"
 })
 @MapperScan("org.maxkey.dao.persistence,")
 public class MaxKeyMgtApplication extends SpringBootServletInitializer {