diff --git a/maxkey-identitys/maxkey-identity-scim/.settings/org.eclipse.wst.common.component b/maxkey-identitys/maxkey-identity-scim/.settings/org.eclipse.wst.common.component index 19c304bfc..1e2b16776 100644 --- a/maxkey-identitys/maxkey-identity-scim/.settings/org.eclipse.wst.common.component +++ b/maxkey-identitys/maxkey-identity-scim/.settings/org.eclipse.wst.common.component @@ -1,9 +1,8 @@ - + + - - uses diff --git a/maxkey-identitys/maxkey-identity-scim/src/main/java/org/maxkey/identity/scim/controller/GroupController.java b/maxkey-identitys/maxkey-identity-scim/src/main/java/org/maxkey/identity/scim/controller/GroupController.java index 36fb7ea39..b03b23b7d 100644 --- a/maxkey-identitys/maxkey-identity-scim/src/main/java/org/maxkey/identity/scim/controller/GroupController.java +++ b/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 { } diff --git a/maxkey-identitys/maxkey-identity-scim/src/main/java/org/maxkey/identity/scim/controller/ServiceProviderConfigController.java b/maxkey-identitys/maxkey-identity-scim/src/main/java/org/maxkey/identity/scim/controller/ServiceProviderConfigController.java index 96dc482d5..2f6bf3afb 100644 --- a/maxkey-identitys/maxkey-identity-scim/src/main/java/org/maxkey/identity/scim/controller/ServiceProviderConfigController.java +++ b/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; } diff --git a/maxkey-identitys/maxkey-identity-scim/src/main/java/org/maxkey/identity/scim/controller/UserController.java b/maxkey-identitys/maxkey-identity-scim/src/main/java/org/maxkey/identity/scim/controller/UserController.java index 5fc58bee7..bd13d7c55 100644 --- a/maxkey-identitys/maxkey-identity-scim/src/main/java/org/maxkey/identity/scim/controller/UserController.java +++ b/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 + *

+ * http://tools.ietf.org/html/draft-ietf-scim-core-schema-00#section-6 + *

+ * it is based on the SCIM 2.0 API Specification: + *

+ * 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 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 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 requestParameters) { + return searchWithPost(requestParameters); + } + + @RequestMapping(value = "/.search", method = RequestMethod.POST) + public MappingJacksonValue searchWithPost(@RequestParam Map requestParameters) { + ScimSearchResult 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; + } } diff --git a/maxkey-identitys/maxkey-identity-scim/src/main/java/org/maxkey/identity/scim/resources/ScimSearchResult.java b/maxkey-identitys/maxkey-identity-scim/src/main/java/org/maxkey/identity/scim/resources/ScimSearchResult.java new file mode 100644 index 000000000..5afd90175 --- /dev/null +++ b/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 { + + 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 schemas = new HashSet<>(Collections.singletonList(SCHEMA)); + private List resources = new ArrayList<>(); + + /** + * Default constructor for Jackson + */ + ScimSearchResult() { + } + + public ScimSearchResult(List 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 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 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; + } +} diff --git a/maxkey-web-manage/build.gradle b/maxkey-web-manage/build.gradle index 2fb895ac6..1264e7716 100644 --- a/maxkey-web-manage/build.gradle +++ b/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") } diff --git a/maxkey-web-manage/src/main/java/org/maxkey/MaxKeyMgtApplication.java b/maxkey-web-manage/src/main/java/org/maxkey/MaxKeyMgtApplication.java index 82a1cdbdf..4cb26eebf 100644 --- a/maxkey-web-manage/src/main/java/org/maxkey/MaxKeyMgtApplication.java +++ b/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 {