You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@directory.apache.org by bd...@apache.org on 2022/10/26 13:04:32 UTC

[directory-scimple] branch repo-501-not-found created (now b0e2bdd6)

This is an automated email from the ASF dual-hosted git repository.

bdemers pushed a change to branch repo-501-not-found
in repository https://gitbox.apache.org/repos/asf/directory-scimple.git


      at b0e2bdd6 Return a 501 (not implemented) status code when a Repository is not found

This branch includes the following new commits:

     new b0e2bdd6 Return a 501 (not implemented) status code when a Repository is not found

The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.



[directory-scimple] 01/01: Return a 501 (not implemented) status code when a Repository is not found

Posted by bd...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

bdemers pushed a commit to branch repo-501-not-found
in repository https://gitbox.apache.org/repos/asf/directory-scimple.git

commit b0e2bdd6a66beb66b99e386d43a096c7a7240737
Author: Brian Demers <bd...@apache.org>
AuthorDate: Fri Sep 30 09:51:37 2022 -0700

    Return a 501 (not implemented) status code when a Repository is not found
    
    ScimExceptionMapper now _correctly_ uses the ErrorResponse object from the ScimException instead of creating a new one and dropping the detail message
---
 .../scim/server/exception/ScimExceptionMapper.java       |  4 +---
 .../scim/server/rest/BaseResourceTypeResourceImpl.java   |  2 +-
 .../server/rest/BaseResourceTypeResourceImplTest.java    | 16 ++++++++++++++++
 .../directory/scim/protocol/exception/ScimException.java |  4 ++--
 4 files changed, 20 insertions(+), 6 deletions(-)

diff --git a/scim-server/src/main/java/org/apache/directory/scim/server/exception/ScimExceptionMapper.java b/scim-server/src/main/java/org/apache/directory/scim/server/exception/ScimExceptionMapper.java
index e8454237..beb58418 100644
--- a/scim-server/src/main/java/org/apache/directory/scim/server/exception/ScimExceptionMapper.java
+++ b/scim-server/src/main/java/org/apache/directory/scim/server/exception/ScimExceptionMapper.java
@@ -35,9 +35,7 @@ public class ScimExceptionMapper implements ExceptionMapper<ScimException> {
 
   @Override
   public Response toResponse(ScimException e) {
-    ErrorResponse errorResponse = new ErrorResponse(e.getStatus(), e.getMessage());
-
-    Response response = errorResponse.toResponse();
+    Response response = e.getError().toResponse();
     response.getHeaders().putSingle(HttpHeaders.CONTENT_TYPE, Constants.SCIM_CONTENT_TYPE);
 
     return response;
diff --git a/scim-server/src/main/java/org/apache/directory/scim/server/rest/BaseResourceTypeResourceImpl.java b/scim-server/src/main/java/org/apache/directory/scim/server/rest/BaseResourceTypeResourceImpl.java
index c1850748..afc2a889 100644
--- a/scim-server/src/main/java/org/apache/directory/scim/server/rest/BaseResourceTypeResourceImpl.java
+++ b/scim-server/src/main/java/org/apache/directory/scim/server/rest/BaseResourceTypeResourceImpl.java
@@ -103,7 +103,7 @@ public abstract class BaseResourceTypeResourceImpl<T extends ScimResource> imple
   Repository<T> getRepositoryInternal() throws ScimException {
     Repository<T> repository = getRepository();
     if (repository == null) {
-      throw new ScimException(Status.INTERNAL_SERVER_ERROR, "Provider not defined");
+      throw new ScimException(Status.NOT_IMPLEMENTED, "Provider not defined");
     }
     return repository;
   }
diff --git a/scim-server/src/test/java/org/apache/directory/scim/server/rest/BaseResourceTypeResourceImplTest.java b/scim-server/src/test/java/org/apache/directory/scim/server/rest/BaseResourceTypeResourceImplTest.java
index 5b2d04ec..8b69d3cf 100644
--- a/scim-server/src/test/java/org/apache/directory/scim/server/rest/BaseResourceTypeResourceImplTest.java
+++ b/scim-server/src/test/java/org/apache/directory/scim/server/rest/BaseResourceTypeResourceImplTest.java
@@ -197,6 +197,22 @@ public class BaseResourceTypeResourceImplTest {
     assertThat(exception.getError().getDetail(), is("Cannot include both attributes and excluded attributes in a single request"));
   }
 
+  @Test
+  public void repositoryNotImplemented() throws ScimException {
+    // given
+    @SuppressWarnings("rawtypes")
+    BaseResourceTypeResourceImpl baseResourceImpl = Mockito.mock(BaseResourceTypeResourceImpl.class);
+    when(baseResourceImpl.getRepository()).thenReturn(null);
+    when(baseResourceImpl.getRepositoryInternal()).thenCallRealMethod();
+
+    // when
+    ScimException exception = assertThrows(ScimException.class, baseResourceImpl::getRepositoryInternal);
+
+    // then
+    assertEquals(exception.getStatus(), Status.NOT_IMPLEMENTED);
+    assertThat(exception.getError().getDetail(), is("Provider not defined"));
+  }
+
   private ScimUser getScimUser() throws PhoneNumberParseException {
     ScimUser user = new ScimUser();
 
diff --git a/scim-spec/scim-spec-protocol/src/main/java/org/apache/directory/scim/protocol/exception/ScimException.java b/scim-spec/scim-spec-protocol/src/main/java/org/apache/directory/scim/protocol/exception/ScimException.java
index 63cec55a..2b38e7db 100644
--- a/scim-spec/scim-spec-protocol/src/main/java/org/apache/directory/scim/protocol/exception/ScimException.java
+++ b/scim-spec/scim-spec-protocol/src/main/java/org/apache/directory/scim/protocol/exception/ScimException.java
@@ -30,8 +30,8 @@ import lombok.EqualsAndHashCode;
 public class ScimException extends Exception {
 
   private static final long serialVersionUID = 3643485564325176463L;
-  private ErrorResponse error;
-  private Status status;
+  private final ErrorResponse error;
+  private final Status status;
 
   public ScimException(Status status, String message, Throwable cause) {
     super(message, cause);