Skip to content

Commit

Permalink
Merge pull request #122 from Freja-eID/master
Browse files Browse the repository at this point in the history
Supported updating issued organisation ids
  • Loading branch information
tanjaFrejaEid authored Dec 15, 2023
2 parents 04e6db4 + f4307a8 commit e8a89a4
Show file tree
Hide file tree
Showing 16 changed files with 405 additions and 18 deletions.
2 changes: 1 addition & 1 deletion FrejaEidClient/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>com.verisec.frejaeid</groupId>
<artifactId>FrejaEidClient</artifactId>
<version>2.19.1-SNAPSHOT</version>
<version>2.20.0-SNAPSHOT</version>
<packaging>jar</packaging>

<name>FrejaEidClient</name>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
package com.verisec.frejaeid.client.beans.general;

import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty;

import java.util.Objects;

public class UpdateOrganisationIdStatus {

private final int added;
private final int updated;
private final int deleted;

@JsonCreator
public UpdateOrganisationIdStatus(@JsonProperty("added") int added,
@JsonProperty("updated") int updated,
@JsonProperty("deleted") int deleted) {
this.added = added;
this.updated = updated;
this.deleted = deleted;
}

public int getAdded() {
return added;
}

public int getUpdated() {
return updated;
}

public int getDeleted() {
return deleted;
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
if (!(o instanceof UpdateOrganisationIdStatus)) return false;
UpdateOrganisationIdStatus that = (UpdateOrganisationIdStatus) o;
return added == that.added && updated == that.updated && deleted == that.deleted;
}

@Override
public int hashCode() {
return Objects.hash(added, updated, deleted);
}

@Override
public String toString() {
return "UpdateOrganisationIdStatus{" +
"added=" + added +
", updated=" + updated +
", deleted=" + deleted +
'}';
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
package com.verisec.frejaeid.client.beans.organisationid.update;

import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.verisec.frejaeid.client.beans.common.RelyingPartyRequest;
import com.verisec.frejaeid.client.beans.general.OrganisationIdAttribute;

import java.util.List;
import java.util.Objects;

public class UpdateOrganisationIdRequest implements RelyingPartyRequest {

private final String identifier;
private final List<OrganisationIdAttribute> additionalAttributes;
private final String relyingPartyId;

public static UpdateOrganisationIdRequest create(String identifier, List<OrganisationIdAttribute> additionalAttributes) {
return new UpdateOrganisationIdRequest(identifier, additionalAttributes, null);
}

public static UpdateOrganisationIdRequest create(String identifier, List<OrganisationIdAttribute> additionalAttributes, String relyingPartyId) {
return new UpdateOrganisationIdRequest(identifier, additionalAttributes, relyingPartyId);
}


/**
* Returns instance of {@linkplain UpdateOrganisationIdRequest}
*
* @param identifier identifier to be updated for the end user. It cannot be
* {@code null} or empty.
* @param additionalAttributes additional attributes related to the identifier.
* It can be {@code null} or empty.
* @param relyingPartyId specifies relying party id for which transaction is
* initiated. It cannot be {@code null} or empty.
* @return request
*/
@JsonCreator
private UpdateOrganisationIdRequest(
@JsonProperty("identifier") String identifier,
@JsonProperty("additionalAttributes") List<OrganisationIdAttribute> additionalAttributes,
@JsonProperty("relyingPartyId") String relyingPartyId) {
this.identifier = identifier;
this.additionalAttributes = additionalAttributes;
this.relyingPartyId = relyingPartyId;
}

public String getIdentifier() {
return identifier;
}

public List<OrganisationIdAttribute> getAdditionalAttributes() {
return additionalAttributes;
}

public String getRelyingPartyId() {
return relyingPartyId;
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
if (!(o instanceof UpdateOrganisationIdRequest)) return false;
UpdateOrganisationIdRequest that = (UpdateOrganisationIdRequest) o;
return Objects.equals(identifier, that.identifier) &&
Objects.equals(additionalAttributes, that.additionalAttributes) &&
Objects.equals(relyingPartyId, that.relyingPartyId);
}

@Override
public int hashCode() {
return Objects.hash(identifier, additionalAttributes, relyingPartyId);
}

@Override
public String toString() {
return "UpdateOrganisationIdRequest{" +
"identifier='" + identifier + '\'' +
", additionalAttributes=" + additionalAttributes +
", relyingPartyId='" + relyingPartyId + '\'' +
'}';
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package com.verisec.frejaeid.client.beans.organisationid.update;

import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.verisec.frejaeid.client.beans.common.FrejaHttpResponse;
import com.verisec.frejaeid.client.beans.general.UpdateOrganisationIdStatus;

import java.util.Objects;

public class UpdateOrganisationIdResponse implements FrejaHttpResponse {

private final UpdateOrganisationIdStatus updateOrganisationIdStatus;

@JsonCreator
public UpdateOrganisationIdResponse(
@JsonProperty("updateOrganisationIdStatus") UpdateOrganisationIdStatus updateOrganisationIdStatus) {
this.updateOrganisationIdStatus = updateOrganisationIdStatus;
}

public UpdateOrganisationIdStatus getUpdateOrganisationIdStatus() {
return updateOrganisationIdStatus;
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
if (!(o instanceof UpdateOrganisationIdResponse)) return false;
UpdateOrganisationIdResponse that = (UpdateOrganisationIdResponse) o;
return Objects.equals(updateOrganisationIdStatus, that.updateOrganisationIdStatus);
}

@Override
public int hashCode() {
return Objects.hash(updateOrganisationIdStatus);
}

@Override
public String toString() {
return "UpdateOrganisationIdResponse{" +
"updateOrganisationIdStatus=" + updateOrganisationIdStatus +
'}';
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@
import com.verisec.frejaeid.client.beans.general.OrganisationIdUserInfo;
import com.verisec.frejaeid.client.beans.organisationid.cancel.CancelAddOrganisationIdRequest;
import com.verisec.frejaeid.client.beans.organisationid.delete.DeleteOrganisationIdRequest;
import com.verisec.frejaeid.client.beans.organisationid.get.OrganisationIdResultRequest;
import com.verisec.frejaeid.client.beans.organisationid.get.OrganisationIdResult;
import com.verisec.frejaeid.client.beans.organisationid.get.OrganisationIdResultRequest;
import com.verisec.frejaeid.client.beans.organisationid.getall.GetAllOrganisationIdUsersRequest;
import com.verisec.frejaeid.client.beans.organisationid.init.InitiateAddOrganisationIdRequest;
import com.verisec.frejaeid.client.beans.organisationid.update.UpdateOrganisationIdRequest;
import com.verisec.frejaeid.client.beans.organisationid.update.UpdateOrganisationIdResponse;
import com.verisec.frejaeid.client.enums.TransactionStatus;
import com.verisec.frejaeid.client.exceptions.FrejaEidClientInternalException;
import com.verisec.frejaeid.client.exceptions.FrejaEidClientPollingException;
Expand Down Expand Up @@ -100,4 +102,19 @@ public void delete(DeleteOrganisationIdRequest deleteOrganisationIdRequest)
*/
public List<OrganisationIdUserInfo> getAllUsers(GetAllOrganisationIdUsersRequest getAllOrganisationIdUsersRequest)
throws FrejaEidClientInternalException, FrejaEidException;

/**
* Updates issued organisation id for a specific person.
*
* @param updateOrganisationIdRequest instance of
* {@linkplain UpdateOrganisationIdRequest} with corresponding
* parameters
* @return {@linkplain UpdateOrganisationIdResponse}
* @throws FrejaEidClientInternalException if internal validation of request
* fails.
* @throws FrejaEidException if server returns an error.
*/
public UpdateOrganisationIdResponse update(UpdateOrganisationIdRequest updateOrganisationIdRequest)
throws FrejaEidClientInternalException, FrejaEidException;

}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
import com.verisec.frejaeid.client.beans.organisationid.get.OrganisationIdResultRequest;
import com.verisec.frejaeid.client.beans.organisationid.getall.GetAllOrganisationIdUsersRequest;
import com.verisec.frejaeid.client.beans.organisationid.init.InitiateAddOrganisationIdRequest;
import com.verisec.frejaeid.client.beans.organisationid.update.UpdateOrganisationIdRequest;
import com.verisec.frejaeid.client.beans.organisationid.update.UpdateOrganisationIdResponse;
import com.verisec.frejaeid.client.client.api.OrganisationIdClientApi;
import com.verisec.frejaeid.client.enums.FrejaEnvironment;
import com.verisec.frejaeid.client.enums.TransactionContext;
Expand Down Expand Up @@ -135,6 +137,16 @@ public List<OrganisationIdUserInfo> getAllUsers(GetAllOrganisationIdUsersRequest
return organisationIdUserInfos;
}

@Override
public UpdateOrganisationIdResponse update(UpdateOrganisationIdRequest updateOrganisationIdRequest)
throws FrejaEidClientInternalException, FrejaEidException {
requestValidationService.validateUpdateOrganisationIdRequest(updateOrganisationIdRequest);
LOG.debug("Updating organisation ID with identifier {}. ", updateOrganisationIdRequest.getIdentifier());
UpdateOrganisationIdResponse response = organisationIdService.update(updateOrganisationIdRequest);
LOG.debug("Successfully updated organisation ID with identifier {}.", updateOrganisationIdRequest.getIdentifier());
return response;
}

public static class Builder extends GenericBuilder {

public static final Logger LOG = LogManager.getLogger(Builder.class);
Expand Down Expand Up @@ -178,5 +190,4 @@ public OrganisationIdClient build() throws FrejaEidClientInternalException {
}

}

}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public CustomIdentifierService(String serverAddress, HttpServiceApi httpService,
public void set(SetCustomIdentifierRequest customIdentifierRequest)
throws FrejaEidClientInternalException, FrejaEidException {
httpService.send(getUrl(serverAddress, MethodUrl.CUSTOM_IDENTIFIER_SET),
RequestTemplate.SET_CUSTOM_IDENITIFIER_TEMPLATE, customIdentifierRequest,
RequestTemplate.SET_CUSTOM_IDENTIFIER_TEMPLATE, customIdentifierRequest,
EmptyFrejaResponse.class, customIdentifierRequest.getRelyingPartyId());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
import com.verisec.frejaeid.client.beans.organisationid.getall.GetAllOrganisationIdUsersResponse;
import com.verisec.frejaeid.client.beans.organisationid.init.InitiateAddOrganisationIdRequest;
import com.verisec.frejaeid.client.beans.organisationid.init.InitiateAddOrganisationIdResponse;
import com.verisec.frejaeid.client.beans.organisationid.update.UpdateOrganisationIdRequest;
import com.verisec.frejaeid.client.beans.organisationid.update.UpdateOrganisationIdResponse;
import com.verisec.frejaeid.client.exceptions.FrejaEidClientInternalException;
import com.verisec.frejaeid.client.exceptions.FrejaEidClientPollingException;
import com.verisec.frejaeid.client.exceptions.FrejaEidException;
Expand All @@ -28,7 +30,7 @@ public OrganisationIdService(String serverAddress, int pollingTimeoutInMilliseco
this.pollingTimeoutInMilliseconds = pollingTimeoutInMilliseconds;
}

public OrganisationIdService(String serverAddress, HttpServiceApi httpService, String resourceServiceUrl) {
public OrganisationIdService(String serverAddress, HttpServiceApi httpService, String resourceServiceUrl) {
super(serverAddress, httpService, resourceServiceUrl);
this.pollingTimeoutInMilliseconds = 0;
}
Expand Down Expand Up @@ -73,7 +75,7 @@ public OrganisationIdResult pollForResult(OrganisationIdResultRequest organisati
public EmptyFrejaResponse delete(DeleteOrganisationIdRequest deleteOrganisationIdRequest)
throws FrejaEidClientInternalException, FrejaEidException {
return httpService.send(getUrl(serverAddress, MethodUrl.ORGANISATION_ID_DELETE),
RequestTemplate.DELETE_ORGANINSATION_ID_TEMPLATE, deleteOrganisationIdRequest,
RequestTemplate.DELETE_ORGANISATION_ID_TEMPLATE, deleteOrganisationIdRequest,
EmptyFrejaResponse.class, deleteOrganisationIdRequest.getRelyingPartyId());
}

Expand All @@ -92,6 +94,13 @@ public GetAllOrganisationIdUsersResponse getAllUsers(
getAllOrganisationIdUsersRequest.getRelyingPartyId());
}

public UpdateOrganisationIdResponse update(UpdateOrganisationIdRequest updateOrganisationIdRequest)
throws FrejaEidClientInternalException, FrejaEidException {
return httpService.send(getUrl(serverAddress, MethodUrl.ORGANISATION_ID_UPDATE),
RequestTemplate.UPDATE_ORGANISATION_ID_TEMPLATE, updateOrganisationIdRequest,
UpdateOrganisationIdResponse.class, updateOrganisationIdRequest.getRelyingPartyId());
}

private boolean isPollingTimeExpired(long pollingEndTime) {
return (System.currentTimeMillis() + pollingTimeoutInMilliseconds) < pollingEndTime;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import com.verisec.frejaeid.client.beans.organisationid.delete.DeleteOrganisationIdRequest;
import com.verisec.frejaeid.client.beans.organisationid.getall.GetAllOrganisationIdUsersRequest;
import com.verisec.frejaeid.client.beans.organisationid.init.InitiateAddOrganisationIdRequest;
import com.verisec.frejaeid.client.beans.organisationid.update.UpdateOrganisationIdRequest;
import com.verisec.frejaeid.client.beans.sign.init.InitiateSignRequest;
import com.verisec.frejaeid.client.beans.usermanagement.customidentifier.delete.DeleteCustomIdentifierRequest;
import com.verisec.frejaeid.client.beans.usermanagement.customidentifier.set.SetCustomIdentifierRequest;
Expand Down Expand Up @@ -130,6 +131,13 @@ public void validateGetAllOrganisationIdUsersRequest(
validateRelyingPartyIdIsEmpty(getAllOrganisationIdUsersRequest.getRelyingPartyId());
}

public void validateUpdateOrganisationIdRequest(UpdateOrganisationIdRequest updateOrganisationIdRequest)
throws FrejaEidClientInternalException {
validateRequest(updateOrganisationIdRequest);
validateIdentifier(updateOrganisationIdRequest.getIdentifier());
validateRelyingPartyIdIsEmpty(updateOrganisationIdRequest.getRelyingPartyId());
}

private void validateRequest(RelyingPartyRequest relyingPartyRequest) throws FrejaEidClientInternalException {
if (relyingPartyRequest == null) {
throw new FrejaEidClientInternalException("Request cannot be null value.");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ public enum MethodUrl {
ORGANISATION_ID_DELETE("/organisation/management/orgId/1.0/delete"),
ORGANISATION_ID_CANCEL_ADD("/organisation/management/orgId/1.0/cancelAdd"),
ORGANISATION_ID_GET_ALL_USERS("/organisation/management/orgId/1.0/users/getAll"),
ORGANISATION_ID_UPDATE("/organisation/management/orgId/1.0/update"),
CUSTOM_IDENTIFIER_SET("/user/manage/1.0/setCustomIdentifier"),
CUSTOM_IDENTIFIER_DELETE("/user/manage/1.0/deleteCustomIdentifier"),
QR_CODE_GENERATE("/qrcode/generate"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,12 @@ public enum RequestTemplate {
CANCEL_SIGN_TEMPLATE("cancelSignRequest={0}"),
INIT_ADD_ORGANISATION_ID_TEMPLATE("initAddOrganisationIdRequest={0}"),
ORGANISATION_ID_RESULT_TEMPLATE("getOneOrganisationIdResultRequest={0}"),
DELETE_ORGANINSATION_ID_TEMPLATE("deleteOrganisationIdRequest={0}"),
DELETE_ORGANISATION_ID_TEMPLATE("deleteOrganisationIdRequest={0}"),
CANCEL_ADD_ORGANISATION_ID_TEMPLATE("cancelAddOrganisationIdRequest={0}"),
GET_ALL_ORGANISATION_ID_USERS_TEMPLATE("getAllOrganisationIdUsersRequest={0}"),
UPDATE_ORGANISATION_ID_TEMPLATE("updateOrganisationIdRequest={0}"),
RELYING_PARTY_ID("relyingPartyId={0}"),
SET_CUSTOM_IDENITIFIER_TEMPLATE("setCustomIdentifierRequest={0}"),
SET_CUSTOM_IDENTIFIER_TEMPLATE("setCustomIdentifierRequest={0}"),
DELETE_CUSTOM_IDENTIFIER_TEMPLATE("deleteCustomIdentifierRequest={0}"),
GET_CUSTODIANSHIP_STATUS_TEMPLATE("getCustodianshipStatusRequest={0}");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,14 +50,14 @@ public void setCustomIdentifier_success() throws FrejaEidClientInternalException
SetCustomIdentifierRequest.createDefaultWithEmail(EMAIL, CUSTOM_IDENTIFIER);
customIdentifierClient.set(setCustomIdentifierRequestDefaultEmail);
Mockito.verify(httpServiceMock).send(FrejaEnvironment.TEST.getServiceUrl() + MethodUrl.CUSTOM_IDENTIFIER_SET,
RequestTemplate.SET_CUSTOM_IDENITIFIER_TEMPLATE,
RequestTemplate.SET_CUSTOM_IDENTIFIER_TEMPLATE,
setCustomIdentifierRequestDefaultEmail, EmptyFrejaResponse.class, null);
SetCustomIdentifierRequest setCustomIdentifierRequestDefaultSsn =
SetCustomIdentifierRequest.createDefaultWithSsn(SsnUserInfo.create(Country.NORWAY, SSN),
CUSTOM_IDENTIFIER);
customIdentifierClient.set(setCustomIdentifierRequestDefaultSsn);
Mockito.verify(httpServiceMock).send(FrejaEnvironment.TEST.getServiceUrl() + MethodUrl.CUSTOM_IDENTIFIER_SET,
RequestTemplate.SET_CUSTOM_IDENITIFIER_TEMPLATE,
RequestTemplate.SET_CUSTOM_IDENTIFIER_TEMPLATE,
setCustomIdentifierRequestDefaultSsn, EmptyFrejaResponse.class, null);
}

Expand All @@ -84,7 +84,7 @@ public void setCustomIdentifier_relyingPartyIdFromRequest_expectedSuccess()
for (SetCustomIdentifierRequest request : requests) {
customIdentifierClient.set(request);
Mockito.verify(httpServiceMock).send(FrejaEnvironment.TEST.getServiceUrl() + MethodUrl.CUSTOM_IDENTIFIER_SET,
RequestTemplate.SET_CUSTOM_IDENITIFIER_TEMPLATE, request,
RequestTemplate.SET_CUSTOM_IDENTIFIER_TEMPLATE, request,
EmptyFrejaResponse.class, RELYING_PARTY_ID);
}

Expand All @@ -108,7 +108,7 @@ public void setCustomIdentifier_customIdentifierAlreadySetForUser_expectCustomId
} catch (FrejaEidException rpEx) {
Mockito.verify(httpServiceMock)
.send(FrejaEnvironment.TEST.getServiceUrl() + MethodUrl.CUSTOM_IDENTIFIER_SET,
RequestTemplate.SET_CUSTOM_IDENITIFIER_TEMPLATE, setCustomIdentifierRequest,
RequestTemplate.SET_CUSTOM_IDENTIFIER_TEMPLATE, setCustomIdentifierRequest,
EmptyFrejaResponse.class, null);
Assert.assertEquals(5002, rpEx.getErrorCode());
Assert.assertEquals("You have already used this custom identifier.", rpEx.getLocalizedMessage());
Expand Down
Loading

0 comments on commit e8a89a4

Please sign in to comment.