Search in sources :

Example 1 with SCA

use of net.petafuel.styx.core.xs2a.entities.SCA in project styx by petafuel.

the class BasicAuthorisationService method startAuthorisation.

protected SCA startAuthorisation(StartAuthorisationRequest request) throws BankRequestFailedException {
    this.setUrl(this.url + request.getServicePath());
    this.createBody(RequestType.POST, JSON, request);
    this.createHeaders(request);
    try (Response response = this.execute();
        Jsonb jsonb = JsonbBuilder.create()) {
        String responseBody = extractResponseBody(response, 201);
        SCA sca = jsonb.fromJson(responseBody, SCA.class);
        SCAUtils.parseSCAApproach(sca, response);
        return sca;
    } catch (Exception e) {
        throw new BankRequestFailedException(e.getMessage(), e);
    }
}
Also used : GetAuthorisationResponse(net.petafuel.styx.core.xs2a.standards.berlingroup.v1_3.http.GetAuthorisationResponse) GetSCAStatusResponse(net.petafuel.styx.core.xs2a.standards.berlingroup.v1_3.http.GetSCAStatusResponse) Response(okhttp3.Response) SCA(net.petafuel.styx.core.xs2a.entities.SCA) Jsonb(javax.json.bind.Jsonb) BankRequestFailedException(net.petafuel.styx.core.xs2a.exceptions.BankRequestFailedException) BankRequestFailedException(net.petafuel.styx.core.xs2a.exceptions.BankRequestFailedException)

Example 2 with SCA

use of net.petafuel.styx.core.xs2a.entities.SCA in project styx by petafuel.

the class BasicAuthorisationService method selectAuthenticationMethod.

protected SCA selectAuthenticationMethod(SelectAuthenticationMethodRequest selectAuthenticationMethodRequest) throws BankRequestFailedException {
    this.setUrl(this.url + selectAuthenticationMethodRequest.getServicePath());
    this.createBody(RequestType.PUT, JSON, selectAuthenticationMethodRequest);
    this.createHeaders(selectAuthenticationMethodRequest);
    try (Response response = this.execute();
        Jsonb jsonb = JsonbBuilder.create()) {
        String responseBody = extractResponseBody(response, 200);
        SCA sca = jsonb.fromJson(responseBody, SCA.class);
        SCAUtils.parseSCAApproach(sca, response);
        return sca;
    } catch (Exception e) {
        throw new BankRequestFailedException(e.getMessage(), e);
    }
}
Also used : GetAuthorisationResponse(net.petafuel.styx.core.xs2a.standards.berlingroup.v1_3.http.GetAuthorisationResponse) GetSCAStatusResponse(net.petafuel.styx.core.xs2a.standards.berlingroup.v1_3.http.GetSCAStatusResponse) Response(okhttp3.Response) SCA(net.petafuel.styx.core.xs2a.entities.SCA) Jsonb(javax.json.bind.Jsonb) BankRequestFailedException(net.petafuel.styx.core.xs2a.exceptions.BankRequestFailedException) BankRequestFailedException(net.petafuel.styx.core.xs2a.exceptions.BankRequestFailedException)

Example 3 with SCA

use of net.petafuel.styx.core.xs2a.entities.SCA in project styx by petafuel.

the class BasicAuthorisationService method updatePSUIdentification.

protected SCA updatePSUIdentification(UpdatePSUIdentificationRequest updatePSUIdentificationRequest) throws BankRequestFailedException {
    this.setUrl(this.url + updatePSUIdentificationRequest.getServicePath());
    this.createBody(RequestType.PUT, JSON, updatePSUIdentificationRequest);
    this.createHeaders(updatePSUIdentificationRequest);
    try (Response response = this.execute();
        Jsonb jsonb = JsonbBuilder.create()) {
        String responseBody = extractResponseBody(response, 200);
        SCA sca = jsonb.fromJson(responseBody, SCA.class);
        SCAUtils.parseSCAApproach(sca, response);
        return sca;
    } catch (Exception e) {
        throw new BankRequestFailedException(e.getMessage(), e);
    }
}
Also used : GetAuthorisationResponse(net.petafuel.styx.core.xs2a.standards.berlingroup.v1_3.http.GetAuthorisationResponse) GetSCAStatusResponse(net.petafuel.styx.core.xs2a.standards.berlingroup.v1_3.http.GetSCAStatusResponse) Response(okhttp3.Response) SCA(net.petafuel.styx.core.xs2a.entities.SCA) Jsonb(javax.json.bind.Jsonb) BankRequestFailedException(net.petafuel.styx.core.xs2a.exceptions.BankRequestFailedException) BankRequestFailedException(net.petafuel.styx.core.xs2a.exceptions.BankRequestFailedException)

Example 4 with SCA

use of net.petafuel.styx.core.xs2a.entities.SCA in project styx by petafuel.

the class BerlinGroupPIS method startAuthorisation.

@Override
public /*
     * BerlinGroup 1.2: the authorisationId of an Authorisation Resource is not a json key in the start SCA Request
     * Therefore we take it out of an authorisation link that contains this id
     */
SCA startAuthorisation(SCARequest xs2ARequest) throws BankRequestFailedException {
    this.setUrl(this.url + xs2ARequest.getServicePath());
    this.createBody(RequestType.POST, JSON, xs2ARequest);
    this.createHeaders(xs2ARequest);
    try (Response response = this.execute();
        Jsonb jsonb = JsonbBuilder.create()) {
        String responseBody = extractResponseBody(response, 201);
        SCA sca = jsonb.fromJson(responseBody, SCA.class);
        SCAUtils.parseSCAApproach(sca, response);
        // extract the authorisation id out of an Href Object that contains the authorisations/... route
        for (Map.Entry<LinkType, Links.Href> entry : sca.getLinks().getUrlMapping().entrySet()) {
            if (entry.getValue().getUrl().contains("authorisations/")) {
                String[] routeParts = entry.getValue().getUrl().split("/");
                sca.setAuthorisationId(routeParts[routeParts.length - 1]);
                break;
            }
        }
        return sca;
    } catch (Exception e) {
        throw new BankRequestFailedException(e.getMessage(), e);
    }
}
Also used : Response(okhttp3.Response) SCA(net.petafuel.styx.core.xs2a.entities.SCA) Jsonb(javax.json.bind.Jsonb) LinkType(net.petafuel.styx.core.xs2a.entities.LinkType) Map(java.util.Map) BankRequestFailedException(net.petafuel.styx.core.xs2a.exceptions.BankRequestFailedException) BankRequestFailedException(net.petafuel.styx.core.xs2a.exceptions.BankRequestFailedException)

Example 5 with SCA

use of net.petafuel.styx.core.xs2a.entities.SCA in project styx by petafuel.

the class ConsentAuthorisationResource method startConsentAuthorisation.

/**
 * Starts a consent authorisation
 *
 * @param consentId of the target consent
 * @return a GetConsentResponse object
 * @throws BankRequestFailedException if something went wrong between the core service and the aspsp
 */
@AcceptsPreStepAuth
@POST
@RequiresPSU
@Path("/consents/{consentId}/authorisations")
public Response startConsentAuthorisation(@NotEmpty @NotBlank @PathParam("consentId") String consentId, @Valid AuthorisationRequest authorisationRequest) throws BankRequestFailedException {
    consentId = Sanitizer.replaceEscSeq(consentId);
    XS2AFactoryInput xs2AFactoryInput = new XS2AFactoryInput();
    xs2AFactoryInput.setConsentId(consentId);
    xs2AFactoryInput.setPsuData(authorisationRequest.getPsuData());
    IOProcessor ioProcessor = new IOProcessor(getXS2AStandard());
    ioProcessor.modifyInput(xs2AFactoryInput);
    SCARequest xs2AAuthorisationRequest = new SCARequestFactory().create(getXS2AStandard().getRequestClassProvider().scaStart(), xs2AFactoryInput);
    xs2AAuthorisationRequest.getHeaders().putAll(getAdditionalHeaders());
    if (getRedirectPreferred() != null) {
        xs2AAuthorisationRequest.setTppRedirectPreferred(getRedirectPreferred());
    }
    ioProcessor.modifyRequest(xs2AAuthorisationRequest, xs2AFactoryInput);
    SCA consentSCA = getXS2AStandard().getCs().startAuthorisation(xs2AAuthorisationRequest);
    AspspUrlMapper aspspUrlMapper = new AspspUrlMapper(consentId, consentSCA.getAuthorisationId());
    consentSCA.setLinks(aspspUrlMapper.map(consentSCA.getLinks()));
    LOG.info("Consent Authorisation started for consentId={} scaStatus={} scaApproach={}", consentId, consentSCA.getScaStatus(), consentSCA.getApproach());
    return Response.status(ResponseConstant.CREATED).entity(consentSCA).build();
}
Also used : SCA(net.petafuel.styx.core.xs2a.entities.SCA) SCARequest(net.petafuel.styx.core.xs2a.contracts.SCARequest) XS2AFactoryInput(net.petafuel.styx.core.xs2a.factory.XS2AFactoryInput) AspspUrlMapper(net.petafuel.styx.api.util.AspspUrlMapper) SCARequestFactory(net.petafuel.styx.core.xs2a.factory.SCARequestFactory) IOProcessor(net.petafuel.styx.core.ioprocessing.IOProcessor) AcceptsPreStepAuth(net.petafuel.styx.api.filter.authentication.boundary.AcceptsPreStepAuth) RequiresPSU(net.petafuel.styx.api.filter.input.boundary.RequiresPSU) Path(javax.ws.rs.Path) ApplicationPath(javax.ws.rs.ApplicationPath) POST(javax.ws.rs.POST)

Aggregations

SCA (net.petafuel.styx.core.xs2a.entities.SCA)28 IntegrationTest (net.petafuel.styx.api.IntegrationTest)15 Test (org.junit.Test)15 Category (org.junit.experimental.categories.Category)15 Invocation (javax.ws.rs.client.Invocation)9 StyxRESTTest (net.petafuel.styx.api.StyxRESTTest)9 AuthorisationRequest (net.petafuel.styx.api.v1.payment.entity.AuthorisationRequest)9 Jsonb (javax.json.bind.Jsonb)8 BankRequestFailedException (net.petafuel.styx.core.xs2a.exceptions.BankRequestFailedException)7 Response (okhttp3.Response)7 Path (javax.ws.rs.Path)5 AcceptsPreStepAuth (net.petafuel.styx.api.filter.authentication.boundary.AcceptsPreStepAuth)5 IOProcessor (net.petafuel.styx.core.ioprocessing.IOProcessor)5 SCARequest (net.petafuel.styx.core.xs2a.contracts.SCARequest)5 SCARequestFactory (net.petafuel.styx.core.xs2a.factory.SCARequestFactory)5 XS2AFactoryInput (net.petafuel.styx.core.xs2a.factory.XS2AFactoryInput)5 GetAuthorisationResponse (net.petafuel.styx.core.xs2a.standards.berlingroup.v1_3.http.GetAuthorisationResponse)5 GetSCAStatusResponse (net.petafuel.styx.core.xs2a.standards.berlingroup.v1_3.http.GetSCAStatusResponse)5 AspspUrlMapper (net.petafuel.styx.api.util.AspspUrlMapper)4 AuthorisationStatusResponse (net.petafuel.styx.api.v1.payment.entity.AuthorisationStatusResponse)3