@@ -389,6 +389,7 @@ private Optional<ProvisioningResponse> newRequest(Provisioning provisioning, Str
389389 boolean isUser = provisionable instanceof User ;
390390 String apiType = isUser ? USER_API : GROUP_API ;
391391 RequestEntity <String > requestEntity = null ;
392+ boolean requiresRemoteIdentifier = false ;
392393 if (hasEvaHook (provisioning ) && isUser ) {
393394 LOG .info (String .format ("Provisioning new eva account for user %s and provisioning %s" ,
394395 ((User ) provisionable ).getEmail (), provisioning .getEntityId ()));
@@ -397,6 +398,7 @@ private Optional<ProvisioningResponse> newRequest(Provisioning provisioning, Str
397398 LOG .info (String .format ("Provisioning new SCIM account for provisionable %s and provisioning %s" ,
398399 provisionable .getName (), provisioning .getEntityId ()));
399400 URI uri = this .provisioningUri (provisioning , apiType , Optional .empty ());
401+ requiresRemoteIdentifier = true ;
400402 requestEntity = new RequestEntity <>(request , httpHeaders (provisioning ), HttpMethod .POST , uri );
401403 } else if (hasGraphHook (provisioning ) && isUser ) {
402404 LOG .info (String .format ("Provisioning new Graph user for provisionable %s and provisioning %s" ,
@@ -406,7 +408,15 @@ private Optional<ProvisioningResponse> newRequest(Provisioning provisioning, Str
406408 }
407409 if (requestEntity != null ) {
408410 Map <String , Object > results = doExchange (requestEntity , apiType , mapParameterizedTypeReference , provisioning );
409- return Optional .of (new DefaultProvisioningResponse (String .valueOf (results .get ("id" ))));
411+ String id = String .valueOf (results .get ("id" ));
412+ if (!StringUtils .hasText (id ) && requiresRemoteIdentifier ) {
413+ String errorMessage = String .format ("Error in %s response %s send to entityID %s. ID is required, but empty SCIM request." ,
414+ apiType ,
415+ results ,
416+ provisioning .getEntityId ());
417+ throw new RemoteException (HttpStatus .BAD_REQUEST , errorMessage , null );
418+ }
419+ return Optional .of (new DefaultProvisioningResponse (id ));
410420 }
411421 return Optional .empty ();
412422
@@ -475,14 +485,13 @@ private <T, S> T doExchange(RequestEntity<S> requestEntity,
475485 provisioning .getEntityId ()));
476486 return restTemplate .exchange (requestEntity , typeReference ).getBody ();
477487 } catch (RestClientException e ) {
478- LOG .error (String .format ("Error from %s with original stack-trace" , provisioning .getEntityId ()), e );
479-
480488 String errorMessage = String .format ("Error %s SCIM request (entityID %s) to %s with %s httpMethod and body %s" ,
481489 api ,
482490 provisioning .getEntityId (),
483491 requestEntity .getUrl (),
484492 requestEntity .getMethod (),
485493 requestEntity .getBody ());
494+ LOG .error (errorMessage , e );
486495 throw new RemoteException (HttpStatus .BAD_REQUEST , errorMessage , e );
487496 }
488497 }
@@ -531,7 +540,7 @@ private HttpHeaders httpHeaders(Provisioning provisioning) {
531540 } else if (StringUtils .hasText (provisioning .getScimBearerToken ())) {
532541 String decryptedScimBearerToken = this .decryptScimBearerToken (provisioning );
533542 //For testing only, remove before prod
534- LOG .debug (String .format ("Inserting header Authorization: Bearer %s " ,decryptedScimBearerToken ));
543+ LOG .debug (String .format ("Inserting header Authorization: Bearer %s " , decryptedScimBearerToken ));
535544 headers .add (HttpHeaders .AUTHORIZATION , String .format ("Bearer %s" , decryptedScimBearerToken ));
536545 }
537546 headers .setContentType (MediaType .APPLICATION_JSON );
0 commit comments