Skip to content

Commit

Permalink
Fix detail in RegistrationService.findUserByEmail where the email…
Browse files Browse the repository at this point in the history
… is not found on UAC Keycloak

- Added proper error message in detail
- Added context field `notFoundEmails` JSON array containing not
found emails
- Update OpenAPI spec
  • Loading branch information
ThorodanBrom committed Oct 6, 2023
1 parent eb360cf commit 2e4c18f
Show file tree
Hide file tree
Showing 7 changed files with 59 additions and 118 deletions.
23 changes: 21 additions & 2 deletions docs/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1734,6 +1734,14 @@ paths:
type: 'urn:dx:as:InvalidInput'
title: Invalid URL
detail: The domain is invalid
Emails not on UAC:
value:
type: urn:dx:as:InvalidInput
title: Email IDs not found at UAC
detail: Some email IDs have not been registered at UAC
context:
notFoundEmails:
- [email protected]
'401':
description: |-
- Unauthorized - `token` invalid/expired
Expand Down Expand Up @@ -2572,8 +2580,11 @@ paths:
Emails not on UAC:
value:
type: urn:dx:as:InvalidInput
title: Some email IDs have not been registered at UAC
detail: "[[email protected]]"
title: Email IDs not found at UAC
detail: Some email IDs have not been registered at UAC
context:
notFoundEmails:
- [email protected]
headers:
Content-Type:
schema:
Expand Down Expand Up @@ -3155,6 +3166,14 @@ paths:
type: 'urn:dx:as:InvalidInput'
title: Invalid URL
detail: The URL is invalid
Emails not on UAC:
value:
type: urn:dx:as:InvalidInput
title: Email IDs not found at UAC
detail: Some email IDs have not been registered at UAC
context:
notFoundEmails:
- [email protected]
'401':
description: '- Unauthorized - `token` invalid/expired or not COS Admin'
content:
Expand Down
4 changes: 3 additions & 1 deletion src/main/java/iudx/aaa/server/registration/Constants.java
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,10 @@ public class Constants {
"The default client credentials have already been created. "
+ "If you have forgotten your client secret, please use the regenerate client secret API";

public static final String ERR_TITLE_EMAILS_NOT_AT_UAC_KEYCLOAK =
public static final String ERR_TITLE_EMAILS_NOT_AT_UAC_KEYCLOAK = "Email IDs not found at UAC";
public static final String ERR_DETAIL_EMAILS_NOT_AT_UAC_KEYCLOAK =
"Some email IDs have not been registered at UAC";
public static final String ERR_CONTEXT_NOT_FOUND_EMAILS = "notFoundEmails";

/* SQL queries */
public static final String SQL_CREATE_ROLE =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,11 @@
import static iudx.aaa.server.registration.Constants.CONFIG_OMITTED_SERVERS;
import static iudx.aaa.server.registration.Constants.DEFAULT_CLIENT;
import static iudx.aaa.server.registration.Constants.ERR_CONTEXT_EXISTING_ROLE_FOR_RS;
import static iudx.aaa.server.registration.Constants.ERR_CONTEXT_NOT_FOUND_EMAILS;
import static iudx.aaa.server.registration.Constants.ERR_CONTEXT_NOT_FOUND_RS_URLS;
import static iudx.aaa.server.registration.Constants.ERR_DETAIL_CONSUMER_FOR_RS_EXISTS;
import static iudx.aaa.server.registration.Constants.ERR_DETAIL_DEFAULT_CLIENT_EXISTS;
import static iudx.aaa.server.registration.Constants.ERR_DETAIL_EMAILS_NOT_AT_UAC_KEYCLOAK;
import static iudx.aaa.server.registration.Constants.ERR_DETAIL_INVALID_CLI_ID;
import static iudx.aaa.server.registration.Constants.ERR_DETAIL_NOT_TRUSTEE;
import static iudx.aaa.server.registration.Constants.ERR_DETAIL_NO_APPROVED_ROLES;
Expand Down Expand Up @@ -948,12 +950,18 @@ public RegistrationService findUserByEmail(
.collect(Collectors.toList());

if (!missingEmails.isEmpty()) {
return Future.failedFuture(
new ComposeException(
400,
Urn.URN_INVALID_INPUT,
ERR_TITLE_EMAILS_NOT_AT_UAC_KEYCLOAK,
missingEmails.toString()));
Response resp =
new ResponseBuilder()
.type(Urn.URN_INVALID_INPUT)
.status(400)
.title(ERR_TITLE_EMAILS_NOT_AT_UAC_KEYCLOAK)
.detail(ERR_DETAIL_EMAILS_NOT_AT_UAC_KEYCLOAK)
.errorContext(
new JsonObject()
.put(
ERR_CONTEXT_NOT_FOUND_EMAILS, new JsonArray(missingEmails)))
.build();
return Future.failedFuture(new ComposeException(resp));
}

return Future.succeededFuture();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -400,7 +400,9 @@ void createRsEmailNotOnUac(KcAdminInt kc) {
.statusCode(400)
.body("type", equalTo(Urn.URN_INVALID_INPUT.toString()))
.body("title", equalTo(ERR_TITLE_EMAILS_NOT_AT_UAC_KEYCLOAK))
.body("detail", stringContainsInOrder(badEmail.toLowerCase()));
.body("detail", equalTo(ERR_DETAIL_EMAILS_NOT_AT_UAC_KEYCLOAK))
.body(
"context." + ERR_CONTEXT_NOT_FOUND_EMAILS, containsInAnyOrder(badEmail.toLowerCase()));
}

@Nested
Expand Down
Loading

0 comments on commit 2e4c18f

Please sign in to comment.