From f3ad10e032c149be1a67a2361977567e30ff60ae Mon Sep 17 00:00:00 2001 From: Shan Jayathilaka Date: Wed, 13 Sep 2023 17:09:54 +0530 Subject: [PATCH] Improve the organization user invitation APIs --- .../invitation/management/v1/GuestsApi.java | 4 +- .../v1/model/InvitationRequestBody.java | 26 +-------- .../v1/model/InvitationResponse.java | 50 +---------------- .../v1/model/InvitationSuccessResponse.java | 54 ++----------------- .../v1/core/GuestApiServiceCore.java | 5 -- .../organization-user-invitation.yaml | 47 ++-------------- 6 files changed, 11 insertions(+), 175 deletions(-) diff --git a/components/org.wso2.carbon.identity.api.server.organization.user.invitation.management/org.wso2.carbon.identity.api.server.organization.user.invitation.management.v1/src/gen/java/org/wso2/carbon/identity/api/server/organization/user/invitation/management/v1/GuestsApi.java b/components/org.wso2.carbon.identity.api.server.organization.user.invitation.management/org.wso2.carbon.identity.api.server.organization.user.invitation.management.v1/src/gen/java/org/wso2/carbon/identity/api/server/organization/user/invitation/management/v1/GuestsApi.java index 2c64462235..d8e1d66ac1 100644 --- a/components/org.wso2.carbon.identity.api.server.organization.user.invitation.management/org.wso2.carbon.identity.api.server.organization.user.invitation.management.v1/src/gen/java/org/wso2/carbon/identity/api/server/organization/user/invitation/management/v1/GuestsApi.java +++ b/components/org.wso2.carbon.identity.api.server.organization.user.invitation.management/org.wso2.carbon.identity.api.server.organization.user.invitation.management.v1/src/gen/java/org/wso2/carbon/identity/api/server/organization/user/invitation/management/v1/GuestsApi.java @@ -53,12 +53,10 @@ public class GuestsApi { @Path("/invitation/accept") @Consumes({ "application/json" }) @Produces({ "application/json" }) - @ApiOperation(value = "Accepts an invitation from a user in the parent organization", notes = "After user clicks on the link provided, the application should invoke this API. In order to invoke this API a user should be logged in to the application. Then this API can be initiated with the access token issued for that user. This logged in user should be the same user which the invitation was initiated to. Scope required:
- none ", response = Void.class, tags={ "Parent Organization User Invitation", }) + @ApiOperation(value = "Accepts an invitation from a user in the parent organization", notes = "After user clicks on the link provided, the redirected application should invoke this API. This API is a public API and this should be invoked with the confirmation code which is appended to the notification. Scope required:
- none ", response = Void.class, tags={ "Parent Organization User Invitation", }) @ApiResponses(value = { @ApiResponse(code = 200, message = "Successful Response", response = Void.class), @ApiResponse(code = 400, message = "Bad Request", response = Error.class), - @ApiResponse(code = 401, message = "Unauthorized", response = Error.class), - @ApiResponse(code = 403, message = "Forbidden", response = Error.class), @ApiResponse(code = 500, message = "Internal Server Error", response = Error.class) }) public Response invitationAcceptPost(@ApiParam(value = "Details that need to confirm an invitation" ,required=true) @Valid AcceptanceRequestBody acceptanceRequestBody) { diff --git a/components/org.wso2.carbon.identity.api.server.organization.user.invitation.management/org.wso2.carbon.identity.api.server.organization.user.invitation.management.v1/src/gen/java/org/wso2/carbon/identity/api/server/organization/user/invitation/management/v1/model/InvitationRequestBody.java b/components/org.wso2.carbon.identity.api.server.organization.user.invitation.management/org.wso2.carbon.identity.api.server.organization.user.invitation.management.v1/src/gen/java/org/wso2/carbon/identity/api/server/organization/user/invitation/management/v1/model/InvitationRequestBody.java index 681eb3d540..85f0cef3b1 100644 --- a/components/org.wso2.carbon.identity.api.server.organization.user.invitation.management/org.wso2.carbon.identity.api.server.organization.user.invitation.management.v1/src/gen/java/org/wso2/carbon/identity/api/server/organization/user/invitation/management/v1/model/InvitationRequestBody.java +++ b/components/org.wso2.carbon.identity.api.server.organization.user.invitation.management/org.wso2.carbon.identity.api.server.organization.user.invitation.management.v1/src/gen/java/org/wso2/carbon/identity/api/server/organization/user/invitation/management/v1/model/InvitationRequestBody.java @@ -39,7 +39,6 @@ public class InvitationRequestBody { private String userDomain; private List roleAssignments = null; - private String userRedirectUrl; /** * Username of the user who will be invited to the organization. This can be an email or an alphanumeric username. @@ -108,26 +107,7 @@ public InvitationRequestBody addRoleAssignmentsItem(RoleAssignmentRequestBody ro return this; } - /** - * URL to which the user should be redirected for authenticate and a place where accepting API can be invoked. This should be able to invoke switch grant and get the token from the organization where the user is existing. - **/ - public InvitationRequestBody userRedirectUrl(String userRedirectUrl) { - - this.userRedirectUrl = userRedirectUrl; - return this; - } - @ApiModelProperty(example = "https://localhost:8080/travel-manager/invitations/accept", value = "URL to which the user should be redirected for authenticate and a place where accepting API can be invoked. This should be able to invoke switch grant and get the token from the organization where the user is existing.") - @JsonProperty("userRedirectUrl") - @Valid - public String getUserRedirectUrl() { - return userRedirectUrl; - } - public void setUserRedirectUrl(String userRedirectUrl) { - this.userRedirectUrl = userRedirectUrl; - } - - @Override public boolean equals(java.lang.Object o) { @@ -141,13 +121,12 @@ public boolean equals(java.lang.Object o) { InvitationRequestBody invitationRequestBody = (InvitationRequestBody) o; return Objects.equals(this.username, invitationRequestBody.username) && Objects.equals(this.userDomain, invitationRequestBody.userDomain) && - Objects.equals(this.roleAssignments, invitationRequestBody.roleAssignments) && - Objects.equals(this.userRedirectUrl, invitationRequestBody.userRedirectUrl); + Objects.equals(this.roleAssignments, invitationRequestBody.roleAssignments); } @Override public int hashCode() { - return Objects.hash(username, userDomain, roleAssignments, userRedirectUrl); + return Objects.hash(username, userDomain, roleAssignments); } @Override @@ -159,7 +138,6 @@ public String toString() { sb.append(" username: ").append(toIndentedString(username)).append("\n"); sb.append(" userDomain: ").append(toIndentedString(userDomain)).append("\n"); sb.append(" roleAssignments: ").append(toIndentedString(roleAssignments)).append("\n"); - sb.append(" userRedirectUrl: ").append(toIndentedString(userRedirectUrl)).append("\n"); sb.append("}"); return sb.toString(); } diff --git a/components/org.wso2.carbon.identity.api.server.organization.user.invitation.management/org.wso2.carbon.identity.api.server.organization.user.invitation.management.v1/src/gen/java/org/wso2/carbon/identity/api/server/organization/user/invitation/management/v1/model/InvitationResponse.java b/components/org.wso2.carbon.identity.api.server.organization.user.invitation.management/org.wso2.carbon.identity.api.server.organization.user.invitation.management.v1/src/gen/java/org/wso2/carbon/identity/api/server/organization/user/invitation/management/v1/model/InvitationResponse.java index 68bf423bfb..f1aa55d0a6 100644 --- a/components/org.wso2.carbon.identity.api.server.organization.user.invitation.management/org.wso2.carbon.identity.api.server.organization.user.invitation.management.v1/src/gen/java/org/wso2/carbon/identity/api/server/organization/user/invitation/management/v1/model/InvitationResponse.java +++ b/components/org.wso2.carbon.identity.api.server.organization.user.invitation.management/org.wso2.carbon.identity.api.server.organization.user.invitation.management.v1/src/gen/java/org/wso2/carbon/identity/api/server/organization/user/invitation/management/v1/model/InvitationResponse.java @@ -36,14 +36,12 @@ public class InvitationResponse { private String id; - private String confirmationCode; private String username; private String email; private List roleAssignments = null; private String status; private String expiredAt; - private String userRedirectUrl; /** **/ @@ -65,26 +63,6 @@ public void setId(String id) { this.id = id; } - /** - **/ - public InvitationResponse confirmationCode(String confirmationCode) { - - this.confirmationCode = confirmationCode; - return this; - } - - @ApiModelProperty(example = "2663329b-c8c5-4c71-9500-9ea8c4e77d94", required = true, value = "") - @JsonProperty("confirmationCode") - @Valid - @NotNull(message = "Property confirmationCode cannot be null.") - - public String getConfirmationCode() { - return confirmationCode; - } - public void setConfirmationCode(String confirmationCode) { - this.confirmationCode = confirmationCode; - } - /** **/ public InvitationResponse username(String username) { @@ -189,26 +167,6 @@ public void setExpiredAt(String expiredAt) { this.expiredAt = expiredAt; } - /** - **/ - public InvitationResponse userRedirectUrl(String userRedirectUrl) { - - this.userRedirectUrl = userRedirectUrl; - return this; - } - - @ApiModelProperty(example = "https://localhost:8080/travel-manager/login", required = true, value = "") - @JsonProperty("userRedirectUrl") - @Valid - @NotNull(message = "Property userRedirectUrl cannot be null.") - - public String getUserRedirectUrl() { - return userRedirectUrl; - } - public void setUserRedirectUrl(String userRedirectUrl) { - this.userRedirectUrl = userRedirectUrl; - } - @Override @@ -222,18 +180,16 @@ public boolean equals(java.lang.Object o) { } InvitationResponse invitationResponse = (InvitationResponse) o; return Objects.equals(this.id, invitationResponse.id) && - Objects.equals(this.confirmationCode, invitationResponse.confirmationCode) && Objects.equals(this.username, invitationResponse.username) && Objects.equals(this.email, invitationResponse.email) && Objects.equals(this.roleAssignments, invitationResponse.roleAssignments) && Objects.equals(this.status, invitationResponse.status) && - Objects.equals(this.expiredAt, invitationResponse.expiredAt) && - Objects.equals(this.userRedirectUrl, invitationResponse.userRedirectUrl); + Objects.equals(this.expiredAt, invitationResponse.expiredAt); } @Override public int hashCode() { - return Objects.hash(id, confirmationCode, username, email, roleAssignments, status, expiredAt, userRedirectUrl); + return Objects.hash(id, username, email, roleAssignments, status, expiredAt); } @Override @@ -243,13 +199,11 @@ public String toString() { sb.append("class InvitationResponse {\n"); sb.append(" id: ").append(toIndentedString(id)).append("\n"); - sb.append(" confirmationCode: ").append(toIndentedString(confirmationCode)).append("\n"); sb.append(" username: ").append(toIndentedString(username)).append("\n"); sb.append(" email: ").append(toIndentedString(email)).append("\n"); sb.append(" roleAssignments: ").append(toIndentedString(roleAssignments)).append("\n"); sb.append(" status: ").append(toIndentedString(status)).append("\n"); sb.append(" expiredAt: ").append(toIndentedString(expiredAt)).append("\n"); - sb.append(" userRedirectUrl: ").append(toIndentedString(userRedirectUrl)).append("\n"); sb.append("}"); return sb.toString(); } diff --git a/components/org.wso2.carbon.identity.api.server.organization.user.invitation.management/org.wso2.carbon.identity.api.server.organization.user.invitation.management.v1/src/gen/java/org/wso2/carbon/identity/api/server/organization/user/invitation/management/v1/model/InvitationSuccessResponse.java b/components/org.wso2.carbon.identity.api.server.organization.user.invitation.management/org.wso2.carbon.identity.api.server.organization.user.invitation.management.v1/src/gen/java/org/wso2/carbon/identity/api/server/organization/user/invitation/management/v1/model/InvitationSuccessResponse.java index 750f93606c..e38b5429af 100644 --- a/components/org.wso2.carbon.identity.api.server.organization.user.invitation.management/org.wso2.carbon.identity.api.server.organization.user.invitation.management.v1/src/gen/java/org/wso2/carbon/identity/api/server/organization/user/invitation/management/v1/model/InvitationSuccessResponse.java +++ b/components/org.wso2.carbon.identity.api.server.organization.user.invitation.management/org.wso2.carbon.identity.api.server.organization.user.invitation.management.v1/src/gen/java/org/wso2/carbon/identity/api/server/organization/user/invitation/management/v1/model/InvitationSuccessResponse.java @@ -35,33 +35,10 @@ public class InvitationSuccessResponse { - private String confirmationCode; private String username; private String email; private List roleAssignments = new ArrayList<>(); - private String userRedirectUrl; - - /** - * Confirmation code of the invitation which needs to be passed back from the confirmation API to accept the invitation. - **/ - public InvitationSuccessResponse confirmationCode(String confirmationCode) { - - this.confirmationCode = confirmationCode; - return this; - } - - @ApiModelProperty(example = "2663329b-c8c5-4c71-9500-9ea8c4e77d94", required = true, value = "Confirmation code of the invitation which needs to be passed back from the confirmation API to accept the invitation.") - @JsonProperty("confirmationCode") - @Valid - @NotNull(message = "Property confirmationCode cannot be null.") - - public String getConfirmationCode() { - return confirmationCode; - } - public void setConfirmationCode(String confirmationCode) { - this.confirmationCode = confirmationCode; - } /** * Username of the user who will be invited to the organization. This can be an email or an alphanumeric username. @@ -131,28 +108,7 @@ public InvitationSuccessResponse addRoleAssignmentsItem(RoleAssignmentResponse r return this; } - /** - * URL to which the user should be redirected for authenticate before accepting API is invoked. - **/ - public InvitationSuccessResponse userRedirectUrl(String userRedirectUrl) { - - this.userRedirectUrl = userRedirectUrl; - return this; - } - @ApiModelProperty(example = "https://localhost:8080/travel-manager/login", required = true, value = "URL to which the user should be redirected for authenticate before accepting API is invoked.") - @JsonProperty("userRedirectUrl") - @Valid - @NotNull(message = "Property userRedirectUrl cannot be null.") - - public String getUserRedirectUrl() { - return userRedirectUrl; - } - public void setUserRedirectUrl(String userRedirectUrl) { - this.userRedirectUrl = userRedirectUrl; - } - - @Override public boolean equals(java.lang.Object o) { @@ -164,16 +120,14 @@ public boolean equals(java.lang.Object o) { return false; } InvitationSuccessResponse invitationSuccessResponse = (InvitationSuccessResponse) o; - return Objects.equals(this.confirmationCode, invitationSuccessResponse.confirmationCode) && - Objects.equals(this.username, invitationSuccessResponse.username) && + return Objects.equals(this.username, invitationSuccessResponse.username) && Objects.equals(this.email, invitationSuccessResponse.email) && - Objects.equals(this.roleAssignments, invitationSuccessResponse.roleAssignments) && - Objects.equals(this.userRedirectUrl, invitationSuccessResponse.userRedirectUrl); + Objects.equals(this.roleAssignments, invitationSuccessResponse.roleAssignments); } @Override public int hashCode() { - return Objects.hash(confirmationCode, username, email, roleAssignments, userRedirectUrl); + return Objects.hash(username, email, roleAssignments); } @Override @@ -182,11 +136,9 @@ public String toString() { StringBuilder sb = new StringBuilder(); sb.append("class InvitationSuccessResponse {\n"); - sb.append(" confirmationCode: ").append(toIndentedString(confirmationCode)).append("\n"); sb.append(" username: ").append(toIndentedString(username)).append("\n"); sb.append(" email: ").append(toIndentedString(email)).append("\n"); sb.append(" roleAssignments: ").append(toIndentedString(roleAssignments)).append("\n"); - sb.append(" userRedirectUrl: ").append(toIndentedString(userRedirectUrl)).append("\n"); sb.append("}"); return sb.toString(); } diff --git a/components/org.wso2.carbon.identity.api.server.organization.user.invitation.management/org.wso2.carbon.identity.api.server.organization.user.invitation.management.v1/src/main/java/org/wso2/carbon/identity/api/server/organization/user/invitation/management/v1/core/GuestApiServiceCore.java b/components/org.wso2.carbon.identity.api.server.organization.user.invitation.management/org.wso2.carbon.identity.api.server.organization.user.invitation.management.v1/src/main/java/org/wso2/carbon/identity/api/server/organization/user/invitation/management/v1/core/GuestApiServiceCore.java index bab04b99ff..af7cab97a7 100644 --- a/components/org.wso2.carbon.identity.api.server.organization.user.invitation.management/org.wso2.carbon.identity.api.server.organization.user.invitation.management.v1/src/main/java/org/wso2/carbon/identity/api/server/organization/user/invitation/management/v1/core/GuestApiServiceCore.java +++ b/components/org.wso2.carbon.identity.api.server.organization.user.invitation.management/org.wso2.carbon.identity.api.server.organization.user.invitation.management.v1/src/main/java/org/wso2/carbon/identity/api/server/organization/user/invitation/management/v1/core/GuestApiServiceCore.java @@ -85,7 +85,6 @@ public InvitationSuccessResponse createInvitation(InvitationRequestBody invitati Invitation invitation = new Invitation(); invitation.setUsername(invitationRequestBody.getUsername()); invitation.setUserDomain(invitationRequestBody.getUserDomain()); - invitation.setUserRedirectUrl(invitationRequestBody.getUserRedirectUrl()); if (invitationRequestBody.getRoleAssignments() != null) { List roleAssignments = new ArrayList<>(); for (RoleAssignmentRequestBody roleAssignmentRequestBody : invitationRequestBody.getRoleAssignments()) { @@ -249,10 +248,8 @@ private String includeData(UserInvitationMgtConstants.ErrorMessage error, String private InvitationSuccessResponse createInvitationSuccessResponse(Invitation invitation) { InvitationSuccessResponse invitationSuccessResponse = new InvitationSuccessResponse(); - invitationSuccessResponse.setConfirmationCode(invitation.getConfirmationCode()); invitationSuccessResponse.setUsername(invitation.getUsername()); invitationSuccessResponse.setEmail(invitation.getEmail()); - invitationSuccessResponse.setUserRedirectUrl(invitation.getUserRedirectUrl()); if (invitation.getRoleAssignments().length > 0) { List roleAssignmentResponses = buildRoleAssignmentResponse(invitation); invitationSuccessResponse.setRoleAssignments(roleAssignmentResponses); @@ -266,12 +263,10 @@ private InvitationsListResponse buildInvitationsListResponse(List in for (Invitation invitationRecord : invitationList) { InvitationResponse invitationResponse = new InvitationResponse(); invitationResponse.setId(invitationRecord.getInvitationId()); - invitationResponse.setConfirmationCode(invitationRecord.getConfirmationCode()); invitationResponse.setUsername(invitationRecord.getUsername()); invitationResponse.setEmail(invitationRecord.getEmail()); invitationResponse.setStatus(invitationRecord.getStatus()); invitationResponse.setExpiredAt(invitationRecord.getExpiredAt().toString()); - invitationResponse.setUserRedirectUrl(invitationRecord.getUserRedirectUrl()); if (invitationRecord.getRoleAssignments().length > 0) { List roleAssignments = buildRoleAssignmentResponse(invitationRecord); invitationResponse.setRoleAssignments(roleAssignments); diff --git a/components/org.wso2.carbon.identity.api.server.organization.user.invitation.management/org.wso2.carbon.identity.api.server.organization.user.invitation.management.v1/src/main/resources/organization-user-invitation.yaml b/components/org.wso2.carbon.identity.api.server.organization.user.invitation.management/org.wso2.carbon.identity.api.server.organization.user.invitation.management.v1/src/main/resources/organization-user-invitation.yaml index 036313fe1f..0c32903cd5 100644 --- a/components/org.wso2.carbon.identity.api.server.organization.user.invitation.management/org.wso2.carbon.identity.api.server.organization.user.invitation.management.v1/src/main/resources/organization-user-invitation.yaml +++ b/components/org.wso2.carbon.identity.api.server.organization.user.invitation.management/org.wso2.carbon.identity.api.server.organization.user.invitation.management.v1/src/main/resources/organization-user-invitation.yaml @@ -104,10 +104,9 @@ paths: - Parent Organization User Invitation summary: Accepts an invitation from a user in the parent organization description: | - After user clicks on the link provided, the application should invoke this API. - In order to invoke this API a user should be logged in to the application. - Then this API can be initiated with the access token issued for that user. - This logged in user should be the same user which the invitation was initiated to. + After user clicks on the link provided, the redirected application should invoke this API. + This API is a public API and this should be invoked with the confirmation code which is + appended to the notification. Scope required:
- none @@ -123,18 +122,6 @@ paths: application/json: schema: $ref: '#/components/schemas/Error' - '401': - description: Unauthorized - content: - application/json: - schema: - $ref: '#/components/schemas/Error' - '403': - description: Forbidden - content: - application/json: - schema: - $ref: '#/components/schemas/Error' '500': description: Internal Server Error content: @@ -310,8 +297,6 @@ components: type: object required: - username - - applicationId - - roles properties: username: type: string @@ -327,26 +312,13 @@ components: description: Role assignments which the user will be assigned to. items: $ref: '#/components/schemas/RoleAssignmentRequestBody' - userRedirectUrl: - type: string - description: URL to which the user should be redirected for authenticate and a place where accepting API - can be invoked. This should be able to invoke switch grant and get the token from the organization where - the user is existing. - example: https://localhost:8080/travel-manager/invitations/accept InvitationSuccessResponse: type: object required: - - confirmationCode - username - email - roleAssignments - - userRedirectUrl properties: - confirmationCode: - type: string - description: Confirmation code of the invitation which needs to be passed back from the confirmation API - to accept the invitation. - example: 2663329b-c8c5-4c71-9500-9ea8c4e77d94 username: type: string description: Username of the user who will be invited to the organization. This can be an @@ -361,11 +333,6 @@ components: description: Role assignments which the user will be assigned to. items: $ref: '#/components/schemas/RoleAssignmentResponse' - userRedirectUrl: - type: string - description: URL to which the user should be redirected for authenticate before accepting API - is invoked. - example: https://localhost:8080/travel-manager/login IntrospectRequestBody: type: object required: @@ -423,18 +390,13 @@ components: type: object required: - id - - confirmationCode - username - email - status - - userRedirectUrl properties: id: type: string example: f7594498-5b52-4201-abd5-d7cf72565c73 - confirmationCode: - type: string - example: 2663329b-c8c5-4c71-9500-9ea8c4e77d94 username: type: string example: alex@gmail.com/alex @@ -451,9 +413,6 @@ components: expiredAt: type: string example: 2021-08-10T10:15:30.00Z - userRedirectUrl: - type: string - example: https://localhost:8080/travel-manager/login RoleAssignmentResponse: type: object required: