diff --git a/components/org.wso2.carbon.identity.api.server.organization.user.invitation.management/org.wso2.carbon.identity.api.server.organization.user.invitation.management.common/src/main/java/org/wso2/carbon/identity/api/server/organization/user/invitation/management/common/UserInvitationMgtConstants.java b/components/org.wso2.carbon.identity.api.server.organization.user.invitation.management/org.wso2.carbon.identity.api.server.organization.user.invitation.management.common/src/main/java/org/wso2/carbon/identity/api/server/organization/user/invitation/management/common/UserInvitationMgtConstants.java index 328186a641..0c390ab223 100644 --- a/components/org.wso2.carbon.identity.api.server.organization.user.invitation.management/org.wso2.carbon.identity.api.server.organization.user.invitation.management.common/src/main/java/org/wso2/carbon/identity/api/server/organization/user/invitation/management/common/UserInvitationMgtConstants.java +++ b/components/org.wso2.carbon.identity.api.server.organization.user.invitation.management/org.wso2.carbon.identity.api.server.organization.user.invitation.management.common/src/main/java/org/wso2/carbon/identity/api/server/organization/user/invitation/management/common/UserInvitationMgtConstants.java @@ -64,6 +64,18 @@ public enum ErrorMessage { ERROR_CODE_INVALID_FILTER("60009", "Invalid filter.", "Provided filter %s is not valid."), + ERROR_CODE_INVALID_APPLICATION("60009", + "Invalid application provided.", + "One of the provided applications with roles are not valid."), + ERROR_CODE_INVALID_CONFIRMATION_CODE_FOR_ACCEPTANCE("60010", + "Invalid confirmation code.", + "Could not accept the invitation since the confirmation code %s is not valid."), + ERROR_CODE_INVALID_USER("60011", + "Invalid user provided.", + "Invalid user is provided."), + ERROR_CODE_EXISTING_USER("60012", + "Authenticated user exist.", + "The authenticated user is already available in the organization."), // Server errors. ERROR_CODE_CREATE_INVITATION("65001", @@ -78,6 +90,9 @@ public enum ErrorMessage { ERROR_CODE_DELETE_INVITATION("65004", "Unable to delete the invitation.", "Could not delete the invitation with the id %s."), + ERROR_CODE_ACCEPT_INVITATION("65005", + "Unable to accept the invitation.", + "Could not accept the invitation with the confirmation code %s."), ERROR_CODE_NOT_IMPLEMENTED("65100", "Not Implemented.", "Method is not implemented."); 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 7c4ac0c1ec..8d3430f708 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 @@ -44,9 +44,12 @@ import static org.wso2.carbon.identity.organization.user.invitation.management.constant.UserInvitationMgtConstants.ErrorMessage.ERROR_CODE_INVALID_CONFIRMATION_CODE; import static org.wso2.carbon.identity.organization.user.invitation.management.constant.UserInvitationMgtConstants.ErrorMessage.ERROR_CODE_INVALID_FILTER; import static org.wso2.carbon.identity.organization.user.invitation.management.constant.UserInvitationMgtConstants.ErrorMessage.ERROR_CODE_INVALID_INVITATION_ID; +import static org.wso2.carbon.identity.organization.user.invitation.management.constant.UserInvitationMgtConstants.ErrorMessage.ERROR_CODE_INVALID_USER; import static org.wso2.carbon.identity.organization.user.invitation.management.constant.UserInvitationMgtConstants.ErrorMessage.ERROR_CODE_MULTIPLE_INVITATIONS_FOR_USER; +import static org.wso2.carbon.identity.organization.user.invitation.management.constant.UserInvitationMgtConstants.ErrorMessage.ERROR_CODE_STORE_ROLES_APP_ID_INVALID; import static org.wso2.carbon.identity.organization.user.invitation.management.constant.UserInvitationMgtConstants.ErrorMessage.ERROR_CODE_UNSUPPORTED_FILTER_ATTRIBUTE; import static org.wso2.carbon.identity.organization.user.invitation.management.constant.UserInvitationMgtConstants.ErrorMessage.ERROR_CODE_UNSUPPORTED_FILTER_ATTRIBUTE_VALUE; +import static org.wso2.carbon.identity.organization.user.invitation.management.constant.UserInvitationMgtConstants.ErrorMessage.ERROR_CODE_USER_ALREADY_EXISTS; import static org.wso2.carbon.identity.organization.user.invitation.management.constant.UserInvitationMgtConstants.ErrorMessage.ERROR_CODE_USER_NOT_FOUND; import static javax.ws.rs.core.Response.Status.BAD_REQUEST; import static javax.ws.rs.core.Response.Status.INTERNAL_SERVER_ERROR; @@ -109,6 +112,9 @@ public InvitationSuccessResponse createInvitation(InvitationRequestBody invitati } else if (ERROR_CODE_ACTIVE_INVITATION_EXISTS.getCode().equals(e.getErrorCode())) { throw handleException(BAD_REQUEST, UserInvitationMgtConstants.ErrorMessage .ERROR_CODE_ACTIVE_INVITATION_AVAILABLE, invitation.getUsername()); + } else if (ERROR_CODE_STORE_ROLES_APP_ID_INVALID.getCode().equals(e.getErrorCode())) { + throw handleException(BAD_REQUEST, UserInvitationMgtConstants.ErrorMessage + .ERROR_CODE_INVALID_APPLICATION, StringUtils.EMPTY); } throw handleException(Response.Status.INTERNAL_SERVER_ERROR, UserInvitationMgtConstants.ErrorMessage.ERROR_CODE_CREATE_INVITATION, @@ -199,8 +205,24 @@ public boolean deleteInvitation(String invitationId) { */ public void acceptInvitation(AcceptanceRequestBody acceptanceRequestBody) { - throw handleException(NOT_IMPLEMENTED, UserInvitationMgtConstants - .ErrorMessage.ERROR_CODE_NOT_IMPLEMENTED, null); + InvitationCoreServiceImpl invitationCoreService = new InvitationCoreServiceImpl(); + try { + invitationCoreService.acceptInvitation(acceptanceRequestBody.getConfirmationCode()); + } catch (UserInvitationMgtException e) { + if (ERROR_CODE_INVALID_CONFIRMATION_CODE.getCode().equals(e.getErrorCode())) { + throw handleException(BAD_REQUEST, UserInvitationMgtConstants.ErrorMessage + .ERROR_CODE_INVALID_CONFIRMATION_CODE_FOR_ACCEPTANCE, acceptanceRequestBody + .getConfirmationCode()); + } else if (ERROR_CODE_INVALID_USER.getCode().equals(e.getErrorCode())) { + throw handleException(BAD_REQUEST, UserInvitationMgtConstants.ErrorMessage + .ERROR_CODE_INVALID_USER, StringUtils.EMPTY); + } else if (ERROR_CODE_USER_ALREADY_EXISTS.getCode().equals(e.getErrorCode())) { + throw handleException(BAD_REQUEST, UserInvitationMgtConstants.ErrorMessage + .ERROR_CODE_EXISTING_USER, StringUtils.EMPTY); + } + throw handleException(INTERNAL_SERVER_ERROR, UserInvitationMgtConstants.ErrorMessage + .ERROR_CODE_ACCEPT_INVITATION, acceptanceRequestBody.getConfirmationCode()); + } } private APIError handleException(Response.Status status, UserInvitationMgtConstants.ErrorMessage error, diff --git a/pom.xml b/pom.xml index 7fb1b9403e..e08f264b6d 100644 --- a/pom.xml +++ b/pom.xml @@ -717,7 +717,7 @@ - 1.3.54 + 1.3.61