ilgrosso commented on code in PR #381:
URL: https://github.com/apache/syncope/pull/381#discussion_r993342196


##########
core/idrepo/rest-cxf/src/main/java/org/apache/syncope/core/rest/cxf/service/AbstractService.java:
##########
@@ -61,8 +61,23 @@ public abstract class AbstractService implements 
JAXRSService {
 
     protected String getActualKey(final AnyDAO<?> dao, final String 
pretendingKey) {
         String actualKey = pretendingKey;
-        if (!SyncopeConstants.UUID_PATTERN.matcher(pretendingKey).matches()) {
-            actualKey = dao.findKey(pretendingKey);
+        if (uriInfo.getPathParameters(true).containsKey("key")) {

Review Comment:
   This is how I'd refactor the current proposal:
   
   ```java
       protected String getActualKey(final AnyDAO<?> dao, final String 
pretendingKey) {
           String actualKey = pretendingKey;
           if (actualKey == null && 
uriInfo.getPathParameters(true).containsKey("key")) {
               final String keyInPath = 
uriInfo.getPathParameters(true).get("key").get(0);
               if (actualKey != null && !actualKey.equals(keyInPath)) {
                   SyncopeClientException sce = 
SyncopeClientException.build(ClientExceptionType.InvalidRequest);
                   sce.getElements().add("Key specified in request does not 
match key in the path");
                   throw sce;
               }
               actualKey = keyInPath;
           }
           if (actualKey == null) {
               SyncopeClientException sce = 
SyncopeClientException.build(ClientExceptionType.InvalidRequest);
               sce.getElements().add("Key is null");
               throw sce;
           }
           if (!SyncopeConstants.UUID_PATTERN.matcher(actualKey).matches()) {
               actualKey = dao.findKey(actualKey);
           }
   
           return actualKey;
       }
    ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscr...@syncope.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to