Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -208,8 +208,7 @@ public ConsentResponse getConsent(String consentId) {
String subjectId = ContextLoader.getUsernameFromContext();

try {
Receipt receipt = consentManager.getReceiptWithExtendedSchema(consentId);
validateOwnership(receipt, consentId, subjectId);
Receipt receipt = consentManager.getReceiptWithExtendedSchema(consentId, subjectId);
return toConsentResponse(receipt);
} catch (ConsentManagementException e) {
throw handleException(e);
Expand All @@ -221,8 +220,7 @@ public void revokeConsent(String consentId) {
String subjectId = ContextLoader.getUsernameFromContext();

try {
Receipt receipt = consentManager.getReceiptWithExtendedSchema(consentId);
validateOwnership(receipt, consentId, subjectId);
consentManager.getReceiptWithExtendedSchema(consentId, subjectId);
consentManager.authorizeConsent(consentId, subjectId, REVOKE_STATE);
} catch (ConsentManagementException e) {
throw handleException(e);
Expand All @@ -238,9 +236,7 @@ public void authorizeConsent(String consentId, AuthorizationRequest authorizatio
String authStatus = requestState != null ? requestState.value() :
AuthorizationRequest.StateEnum.APPROVED.value();

Receipt receipt = consentManager.getReceiptWithExtendedSchema(consentId);
List<ConsentAuthorization> authorizations = consentManager.getConsentAuthorizations(consentId);
validateAuthorizer(receipt, consentId, subjectId, authorizations);
consentManager.getConsentAuthorizations(consentId, subjectId);
consentManager.authorizeConsent(consentId, subjectId, authStatus);
} catch (ConsentManagementException e) {
throw handleException(e);
Expand All @@ -252,8 +248,7 @@ public ConsentValidationResponse validateConsent(String consentId) {
String subjectId = ContextLoader.getUsernameFromContext();

try {
Receipt receipt = consentManager.getReceiptWithExtendedSchema(consentId);
validateOwnership(receipt, consentId, subjectId);
Receipt receipt = consentManager.getReceiptWithExtendedSchema(consentId, subjectId);

String status = consentManager.validateConsentStatus(consentId);
ConsentValidationResponse response = new ConsentValidationResponse();
Expand Down Expand Up @@ -290,60 +285,6 @@ private List<PurposePIICategoryBinding> buildPurposeBindings(ConsentInput consen
return purposeBindings;
}

private void validateOwnership(Receipt receipt, String consentId, String subjectId) {

if (receipt == null) {
throw consentNotFoundError(consentId);
}
if (!subjectId.equals(receipt.getPiiPrincipalId())) {
throw userNotAuthorizedError();
}
}

private void validateAuthorizer(Receipt receipt, String consentId, String subjectId,
List<ConsentAuthorization> authorizations) {

if (receipt == null) {
throw consentNotFoundError(consentId);
}
if (subjectId.equals(receipt.getPiiPrincipalId())) {
return;
}
if (findUserAuthorization(authorizations, subjectId) != null) {
return;
}
throw userNotAuthorizedError();
}

private ConsentAuthorization findUserAuthorization(List<ConsentAuthorization> authorizations, String subjectId) {

if (authorizations != null) {
for (ConsentAuthorization auth : authorizations) {
if (subjectId.equals(auth.getUserId())) {
return auth;
}
}
}
return null;
}

private APIError consentNotFoundError(String consentId) {

return new APIError(Response.Status.NOT_FOUND, new ErrorResponse.Builder()
.withCode(ErrorMessages.ERROR_CODE_RECEIPT_ID_INVALID.getCode())
.withMessage("Consent not found.")
.withDescription("No consent found for ID: " + consentId)
.build());
}

private APIError userNotAuthorizedError() {

return new APIError(Response.Status.FORBIDDEN, new ErrorResponse.Builder()
.withCode(ErrorMessages.ERROR_CODE_USER_NOT_AUTHORIZED.getCode())
.withMessage(ErrorMessages.ERROR_CODE_USER_NOT_AUTHORIZED.getMessage())
.build());
}

private ConsentResponse toConsentResponse(Receipt receipt) {

ConsentResponse dto = new ConsentResponse();
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -556,7 +556,7 @@
<identity.organization.management.version>1.4.122</identity.organization.management.version>
<openapi-generator-maven-plugin.version>4.1.2</openapi-generator-maven-plugin.version>
<carbon.workflow-engine.version>1.1.6</carbon.workflow-engine.version>
<carbon.consent.mgt.version>2.9.10</carbon.consent.mgt.version>
<carbon.consent.mgt.version>2.9.14</carbon.consent.mgt.version>
</properties>

<modules>
Expand Down
Loading