Search in sources :

Example 1 with POSTConsentResponse

use of net.petafuel.styx.api.v1.consent.entity.POSTConsentResponse 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 POSTConsentResponse

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

the class ConsentResourcesConsorsTest method A_createConsentTest.

@Override
@Test
@Category(IntegrationTest.class)
public void A_createConsentTest() throws IOException {
    Response response = createConsentEndpoint();
    Assertions.assertEquals(201, response.getStatus());
    POSTConsentResponse consentResponse = jsonb.fromJson(IOUtils.toString((InputStream) response.getEntity(), StandardCharsets.UTF_8), POSTConsentResponse.class);
    Assertions.assertNotNull(consentResponse.getConsentId());
    Assertions.assertNotNull(consentResponse.getAspspScaApproach());
    Assertions.assertNotNull(consentResponse.getLinks());
    Response validateConsent = ClientBuilder.newClient().target(consentResponse.getLinks().getScaRedirect().getUrl() + "?psu-id=" + getPsuId()).request().buildGet().invoke();
    Assertions.assertTrue(validateConsent.readEntity(String.class).contains("valid"));
    consentId = consentResponse.getConsentId();
}
Also used : Response(javax.ws.rs.core.Response) GetConsentResponse(net.petafuel.styx.api.v1.consent.entity.GetConsentResponse) POSTConsentResponse(net.petafuel.styx.api.v1.consent.entity.POSTConsentResponse) GetConsentStatusResponse(net.petafuel.styx.api.v1.consent.entity.GetConsentStatusResponse) InputStream(java.io.InputStream) POSTConsentResponse(net.petafuel.styx.api.v1.consent.entity.POSTConsentResponse) Category(org.junit.experimental.categories.Category) IntegrationTest(net.petafuel.styx.api.IntegrationTest) Test(org.junit.Test)

Example 3 with POSTConsentResponse

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

the class ConsentResourcesFiduciaTest method A_createConsentTest.

@Override
@Test
@Category(IntegrationTest.class)
public void A_createConsentTest() throws IOException {
    Response response = createConsentEndpoint();
    Assertions.assertEquals(201, response.getStatus());
    POSTConsentResponse consentResponse = jsonb.fromJson(IOUtils.toString((InputStream) response.getEntity(), StandardCharsets.UTF_8), POSTConsentResponse.class);
    Assertions.assertNotNull(consentResponse.getConsentId());
    Assertions.assertNotNull(consentResponse.getAspspScaApproach());
    Assertions.assertNotNull(consentResponse.getLinks());
    consentId = consentResponse.getConsentId();
}
Also used : Response(javax.ws.rs.core.Response) GetConsentResponse(net.petafuel.styx.api.v1.consent.entity.GetConsentResponse) POSTConsentResponse(net.petafuel.styx.api.v1.consent.entity.POSTConsentResponse) GetConsentStatusResponse(net.petafuel.styx.api.v1.consent.entity.GetConsentStatusResponse) AuthorisationStatusResponse(net.petafuel.styx.api.v1.payment.entity.AuthorisationStatusResponse) InputStream(java.io.InputStream) POSTConsentResponse(net.petafuel.styx.api.v1.consent.entity.POSTConsentResponse) Category(org.junit.experimental.categories.Category) IntegrationTest(net.petafuel.styx.api.IntegrationTest) Test(org.junit.Test)

Example 4 with POSTConsentResponse

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

the class ConsentResourcesTargoTest method A_createConsentTest.

@Override
@Test
@Category(IntegrationTest.class)
public void A_createConsentTest() throws IOException {
    Response response = createConsentEndpoint();
    Assertions.assertEquals(201, response.getStatus());
    POSTConsentResponse consentResponse = jsonb.fromJson(IOUtils.toString((InputStream) response.getEntity(), StandardCharsets.UTF_8), POSTConsentResponse.class);
    Assertions.assertNotNull(consentResponse.getConsentId());
    Assertions.assertNotNull(consentResponse.getAspspScaApproach());
    Assertions.assertNotNull(consentResponse.getLinks());
    consentId = consentResponse.getConsentId();
}
Also used : Response(javax.ws.rs.core.Response) GetConsentResponse(net.petafuel.styx.api.v1.consent.entity.GetConsentResponse) POSTConsentResponse(net.petafuel.styx.api.v1.consent.entity.POSTConsentResponse) GetConsentStatusResponse(net.petafuel.styx.api.v1.consent.entity.GetConsentStatusResponse) AuthorisationStatusResponse(net.petafuel.styx.api.v1.payment.entity.AuthorisationStatusResponse) InputStream(java.io.InputStream) POSTConsentResponse(net.petafuel.styx.api.v1.consent.entity.POSTConsentResponse) Category(org.junit.experimental.categories.Category) IntegrationTest(net.petafuel.styx.api.IntegrationTest) Test(org.junit.Test)

Example 5 with POSTConsentResponse

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

the class ConsentResourcesSparkasseTest method A_createConsentTest.

@Override
@Test
@Category(IntegrationTest.class)
public void A_createConsentTest() throws IOException {
    Response response = createConsentEndpoint();
    Assertions.assertEquals(201, response.getStatus());
    POSTConsentResponse consentResponse = jsonb.fromJson(IOUtils.toString((InputStream) response.getEntity(), StandardCharsets.UTF_8), POSTConsentResponse.class);
    Assertions.assertNotNull(consentResponse.getConsentId());
    Assertions.assertNotNull(consentResponse.getAspspScaApproach());
    Assertions.assertNotNull(consentResponse.getLinks());
    consentId = consentResponse.getConsentId();
}
Also used : Response(javax.ws.rs.core.Response) GetConsentResponse(net.petafuel.styx.api.v1.consent.entity.GetConsentResponse) POSTConsentResponse(net.petafuel.styx.api.v1.consent.entity.POSTConsentResponse) GetConsentStatusResponse(net.petafuel.styx.api.v1.consent.entity.GetConsentStatusResponse) InputStream(java.io.InputStream) POSTConsentResponse(net.petafuel.styx.api.v1.consent.entity.POSTConsentResponse) Category(org.junit.experimental.categories.Category) IntegrationTest(net.petafuel.styx.api.IntegrationTest) Test(org.junit.Test)

Aggregations

POSTConsentResponse (net.petafuel.styx.api.v1.consent.entity.POSTConsentResponse)5 InputStream (java.io.InputStream)4 Response (javax.ws.rs.core.Response)4 IntegrationTest (net.petafuel.styx.api.IntegrationTest)4 GetConsentResponse (net.petafuel.styx.api.v1.consent.entity.GetConsentResponse)4 GetConsentStatusResponse (net.petafuel.styx.api.v1.consent.entity.GetConsentStatusResponse)4 Test (org.junit.Test)4 Category (org.junit.experimental.categories.Category)4 AuthorisationStatusResponse (net.petafuel.styx.api.v1.payment.entity.AuthorisationStatusResponse)2 ApplicationPath (javax.ws.rs.ApplicationPath)1 POST (javax.ws.rs.POST)1 Path (javax.ws.rs.Path)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 IOProcessor (net.petafuel.styx.core.ioprocessing.IOProcessor)1 AISRequest (net.petafuel.styx.core.xs2a.contracts.AISRequest)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