Search in sources :

Example 1 with POSTConsentRequest

use of net.petafuel.styx.api.v1.consent.entity.POSTConsentRequest in project styx by petafuel.

the class CreateConsentResource method createConsent.

/**
 * Creates a consent Resource on the target aspsp xs2a interface
 *
 * @param postConsentRequest must contain recurringIndicator and the AccountAccess
 * @return returns SCA related data for the consent authorisation
 * @throws BankRequestFailedException in case something goes wrong while communicating to the ASPSP interface
 */
@RequiresMandatoryHeader
@AcceptsPreStepAuth
@POST
@Path("/consents")
public Response createConsent(@Valid @NotNull POSTConsentRequest postConsentRequest) throws BankRequestFailedException {
    Consent requestConsent = new Consent();
    requestConsent.setCombinedServiceIndicator(false);
    requestConsent.setRecurringIndicator(postConsentRequest.isRecurringIndicator());
    requestConsent.setFrequencyPerDay(4);
    requestConsent.setAccess(postConsentRequest.getAccess());
    XS2AFactoryInput xs2AFactoryInput = new XS2AFactoryInput();
    xs2AFactoryInput.setConsent(requestConsent);
    xs2AFactoryInput.setPsu(getPsu());
    IOProcessor ioProcessor = new IOProcessor(getXS2AStandard());
    ioProcessor.modifyInput(xs2AFactoryInput);
    AISRequest xs2ARequest = new AISRequestFactory().create(getXS2AStandard().getRequestClassProvider().consentCreation(), xs2AFactoryInput);
    xs2ARequest.getHeaders().putAll(getAdditionalHeaders());
    xs2ARequest.setTppRedirectPreferred(getRedirectPreferred());
    ioProcessor.modifyRequest(xs2ARequest, xs2AFactoryInput);
    Consent consent = getXS2AStandard().getCs().createConsent(xs2ARequest);
    POSTConsentResponse postConsentResponse = new POSTConsentResponse();
    postConsentResponse.setConsentId(consent.getId());
    postConsentResponse.setAspspScaApproach(consent.getSca().getApproach());
    postConsentResponse.setPsuMessage(consent.getPsuMessage());
    postConsentResponse.setLinks(consent.getLinks());
    SCAApproach approach = SCAHandler.decision(consent);
    if (approach instanceof OAuth2) {
        postConsentResponse.getLinks().getScaOAuth().setUrl(((OAuth2) approach).getAuthoriseLink());
    }
    AspspUrlMapper aspspUrlMapper = new AspspUrlMapper(consent.getId(), null);
    postConsentResponse.setLinks(aspspUrlMapper.map(postConsentResponse.getLinks()));
    LOG.info("Created new AIS consent for bic={}", getXS2AStandard().getAspsp().getBic());
    return Response.status(Response.Status.CREATED).entity(postConsentResponse).build();
}
Also used : OAuth2(net.petafuel.styx.core.xs2a.sca.OAuth2) Consent(net.petafuel.styx.core.xs2a.entities.Consent) AISRequest(net.petafuel.styx.core.xs2a.contracts.AISRequest) XS2AFactoryInput(net.petafuel.styx.core.xs2a.factory.XS2AFactoryInput) SCAApproach(net.petafuel.styx.core.xs2a.sca.SCAApproach) AspspUrlMapper(net.petafuel.styx.api.util.AspspUrlMapper) AISRequestFactory(net.petafuel.styx.core.xs2a.factory.AISRequestFactory) POSTConsentResponse(net.petafuel.styx.api.v1.consent.entity.POSTConsentResponse) IOProcessor(net.petafuel.styx.core.ioprocessing.IOProcessor) AcceptsPreStepAuth(net.petafuel.styx.api.filter.authentication.boundary.AcceptsPreStepAuth) Path(javax.ws.rs.Path) ApplicationPath(javax.ws.rs.ApplicationPath) RequiresMandatoryHeader(net.petafuel.styx.api.filter.input.boundary.RequiresMandatoryHeader) POST(javax.ws.rs.POST)

Example 2 with POSTConsentRequest

use of net.petafuel.styx.api.v1.consent.entity.POSTConsentRequest in project styx by petafuel.

the class ConsentResourcesTest method createConsentEndpoint.

Response createConsentEndpoint() {
    Invocation.Builder invocationBuilder = getInvocationBuilder(String.format(POST_CONSENT, consentId));
    POSTConsentRequest request = new POSTConsentRequest();
    request.setAccess(new AccountAccess());
    request.getAccess().setAccounts(new ArrayList<>());
    request.getAccess().getAccounts().add(getAccountReference());
    request.getAccess().setBalances(new ArrayList<>());
    request.getAccess().getBalances().add(getAccountReference());
    request.getAccess().setTransactions(new ArrayList<>());
    request.getAccess().getTransactions().add(getAccountReference());
    request.setRecurringIndicator(true);
    Invocation invocation = invocationBuilder.buildPost(Entity.entity(request, MediaType.APPLICATION_JSON));
    return invocation.invoke(Response.class);
}
Also used : Invocation(javax.ws.rs.client.Invocation) AccountAccess(net.petafuel.styx.core.xs2a.entities.AccountAccess) POSTConsentRequest(net.petafuel.styx.api.v1.consent.entity.POSTConsentRequest)

Aggregations

ApplicationPath (javax.ws.rs.ApplicationPath)1 POST (javax.ws.rs.POST)1 Path (javax.ws.rs.Path)1 Invocation (javax.ws.rs.client.Invocation)1 AcceptsPreStepAuth (net.petafuel.styx.api.filter.authentication.boundary.AcceptsPreStepAuth)1 RequiresMandatoryHeader (net.petafuel.styx.api.filter.input.boundary.RequiresMandatoryHeader)1 AspspUrlMapper (net.petafuel.styx.api.util.AspspUrlMapper)1 POSTConsentRequest (net.petafuel.styx.api.v1.consent.entity.POSTConsentRequest)1 POSTConsentResponse (net.petafuel.styx.api.v1.consent.entity.POSTConsentResponse)1 IOProcessor (net.petafuel.styx.core.ioprocessing.IOProcessor)1 AISRequest (net.petafuel.styx.core.xs2a.contracts.AISRequest)1 AccountAccess (net.petafuel.styx.core.xs2a.entities.AccountAccess)1 Consent (net.petafuel.styx.core.xs2a.entities.Consent)1 AISRequestFactory (net.petafuel.styx.core.xs2a.factory.AISRequestFactory)1 XS2AFactoryInput (net.petafuel.styx.core.xs2a.factory.XS2AFactoryInput)1 OAuth2 (net.petafuel.styx.core.xs2a.sca.OAuth2)1 SCAApproach (net.petafuel.styx.core.xs2a.sca.SCAApproach)1