Skip to content

Commit

Permalink
chore: Make scopes constant and add annotation (#3163)
Browse files Browse the repository at this point in the history
Make scopes constant and add annotation
  • Loading branch information
jimmarino authored Jun 12, 2023
1 parent 4b935ca commit 26da270
Showing 1 changed file with 22 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import org.eclipse.edc.connector.transfer.spi.types.protocol.TransferTerminationMessage;
import org.eclipse.edc.jsonld.spi.JsonLd;
import org.eclipse.edc.policy.engine.spi.PolicyEngine;
import org.eclipse.edc.policy.engine.spi.PolicyScope;
import org.eclipse.edc.protocol.dsp.dispatcher.DspHttpRemoteMessageDispatcherImpl;
import org.eclipse.edc.protocol.dsp.serialization.JsonLdRemoteMessageSerializerImpl;
import org.eclipse.edc.protocol.dsp.spi.dispatcher.DspHttpRemoteMessageDispatcher;
Expand Down Expand Up @@ -55,6 +56,18 @@ public class DspHttpCoreExtension implements ServiceExtension {

public static final String NAME = "Dataspace Protocol Core Extension";

/**
* Policy scope evaluated when a contract negotiation request is made.
*/
@PolicyScope
private static final String CONTRACT_NEGOTIATION_REQUEST_SCOPE = "contract.negotiation.request";

/**
* Policy scope evaluated when a transfer process request is made.
*/
@PolicyScope
private static final String TRANSFER_PROCESS_REQUEST_SCOPE = "transfer.process.request";

@Inject
private RemoteMessageDispatcherRegistry dispatcherRegistry;
@Inject
Expand Down Expand Up @@ -95,20 +108,18 @@ public DspHttpRemoteMessageDispatcher dspHttpRemoteMessageDispatcher(ServiceExte
}

private void registerNegotiationPolicyScopes(DspHttpRemoteMessageDispatcher dispatcher) {
var scope = "contract.negotiation.request";
dispatcher.registerPolicyScope(ContractAgreementMessage.class, scope, ContractRemoteMessage::getPolicy);
dispatcher.registerPolicyScope(ContractNegotiationEventMessage.class, scope, ContractRemoteMessage::getPolicy);
dispatcher.registerPolicyScope(ContractRequestMessage.class, scope, ContractRemoteMessage::getPolicy);
dispatcher.registerPolicyScope(ContractNegotiationTerminationMessage.class, scope, ContractRemoteMessage::getPolicy);
dispatcher.registerPolicyScope(ContractAgreementVerificationMessage.class, scope, ContractRemoteMessage::getPolicy);
dispatcher.registerPolicyScope(ContractAgreementMessage.class, CONTRACT_NEGOTIATION_REQUEST_SCOPE, ContractRemoteMessage::getPolicy);
dispatcher.registerPolicyScope(ContractNegotiationEventMessage.class, CONTRACT_NEGOTIATION_REQUEST_SCOPE, ContractRemoteMessage::getPolicy);
dispatcher.registerPolicyScope(ContractRequestMessage.class, CONTRACT_NEGOTIATION_REQUEST_SCOPE, ContractRemoteMessage::getPolicy);
dispatcher.registerPolicyScope(ContractNegotiationTerminationMessage.class, CONTRACT_NEGOTIATION_REQUEST_SCOPE, ContractRemoteMessage::getPolicy);
dispatcher.registerPolicyScope(ContractAgreementVerificationMessage.class, CONTRACT_NEGOTIATION_REQUEST_SCOPE, ContractRemoteMessage::getPolicy);
}

private void registerTransferProcessPolicyScopes(DspHttpRemoteMessageDispatcher dispatcher) {
var scope = "transfer.process.request";
dispatcher.registerPolicyScope(TransferCompletionMessage.class, scope, TransferRemoteMessage::getPolicy);
dispatcher.registerPolicyScope(TransferTerminationMessage.class, scope, TransferRemoteMessage::getPolicy);
dispatcher.registerPolicyScope(TransferStartMessage.class, scope, TransferRemoteMessage::getPolicy);
dispatcher.registerPolicyScope(TransferRequestMessage.class, scope, TransferRemoteMessage::getPolicy);
dispatcher.registerPolicyScope(TransferCompletionMessage.class, TRANSFER_PROCESS_REQUEST_SCOPE, TransferRemoteMessage::getPolicy);
dispatcher.registerPolicyScope(TransferTerminationMessage.class, TRANSFER_PROCESS_REQUEST_SCOPE, TransferRemoteMessage::getPolicy);
dispatcher.registerPolicyScope(TransferStartMessage.class, TRANSFER_PROCESS_REQUEST_SCOPE, TransferRemoteMessage::getPolicy);
dispatcher.registerPolicyScope(TransferRequestMessage.class, TRANSFER_PROCESS_REQUEST_SCOPE, TransferRemoteMessage::getPolicy);
}

@Provider
Expand Down

0 comments on commit 26da270

Please sign in to comment.