Search in sources :

Example 11 with Consent

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

the class PersistentConsentIntegrationTest method getConsent.

@Test
@Order(3)
void getConsent() {
    Consent fromDatabase = new PersistentConsent().get(consent);
    Assert.assertNotNull(fromDatabase.getId());
    Assert.assertEquals(ConsentStatus.RECEIVED, fromDatabase.getState());
    Assert.assertEquals(SCA.Approach.REDIRECT, fromDatabase.getSca().getApproach());
    Assert.assertEquals("PSU-ID-33241", fromDatabase.getPsu().getId());
}
Also used : PersistentConsent(net.petafuel.styx.core.persistence.layers.PersistentConsent) Consent(net.petafuel.styx.core.xs2a.entities.Consent) PersistentConsent(net.petafuel.styx.core.persistence.layers.PersistentConsent) TestMethodOrder(org.junit.jupiter.api.TestMethodOrder) Order(org.junit.jupiter.api.Order) Test(org.junit.jupiter.api.Test)

Example 12 with Consent

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

the class PersistentConsentIntegrationTest method setup.

@BeforeAll
public void setup() {
    AccountReference IngoZebadich = new AccountReference("DE48500105171271124579", AccountReference.Type.IBAN);
    AccountReference MiaDochegal = new AccountReference("4253614013", AccountReference.Type.BBAN);
    AccountReference KlaraFall = new AccountReference("AAAPL1234C", AccountReference.Type.PAN);
    AccountReference JohannesBeer = new AccountReference("460323255272", AccountReference.Type.MSISDN);
    consent = new Consent();
    consent.setId(String.valueOf(UUID.randomUUID()));
    consent.setState(ConsentStatus.RECEIVED);
    consent.getAccess().setTransactions(Arrays.asList(KlaraFall, JohannesBeer));
    consent.getAccess().setBalances(Arrays.asList(IngoZebadich, MiaDochegal));
    consent.setRecurringIndicator(false);
    consent.setFrequencyPerDay(4);
    consent.getSca().setApproach(SCA.Approach.REDIRECT);
    consent.setCombinedServiceIndicator(false);
    PSU psu = new PSU("PSU-ID-33241");
    psu.setIdType("PSU-ID-TYPE-33241");
    psu.setIp("127.0.0.1");
    psu.setPort(9999);
    psu.setCorporateIdType("PSU-CO-ID-TYPE-33242");
    psu.setCorporateId("PSU-CO-ID-33242");
    psu.setGeoLocation("48.3938:11.7331");
    psu.setUserAgent("VIMpay 1.2.3");
    consent.setPsu(psu);
    consent.setxRequestId(UUID.randomUUID());
}
Also used : PSU(net.petafuel.styx.core.xs2a.entities.PSU) PersistentConsent(net.petafuel.styx.core.persistence.layers.PersistentConsent) Consent(net.petafuel.styx.core.xs2a.entities.Consent) AccountReference(net.petafuel.styx.core.xs2a.entities.AccountReference) BeforeAll(org.junit.jupiter.api.BeforeAll)

Example 13 with Consent

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

the class PersistentConsentIntegrationTest method updateConsentState.

@Test
@Order(5)
void updateConsentState() {
    Consent updatedConsent = new PersistentConsent().updateState(consent, ConsentStatus.TERMINATED_BY_TPP);
    Assert.assertEquals(consent.getId(), updatedConsent.getId());
    Assert.assertEquals(ConsentStatus.TERMINATED_BY_TPP, updatedConsent.getState());
}
Also used : PersistentConsent(net.petafuel.styx.core.persistence.layers.PersistentConsent) Consent(net.petafuel.styx.core.xs2a.entities.Consent) PersistentConsent(net.petafuel.styx.core.persistence.layers.PersistentConsent) TestMethodOrder(org.junit.jupiter.api.TestMethodOrder) Order(org.junit.jupiter.api.Order) Test(org.junit.jupiter.api.Test)

Example 14 with Consent

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

the class PersistentConsent method dbToModel.

/**
 * Maps the query ResultSet to a consent model
 *
 * @param resultSet Result set of a selecting database function
 * @return Mapped Consent from the database columns
 * @throws SQLException If the expected database column is not available
 */
private Consent dbToModel(ResultSet resultSet) throws SQLException {
    Consent consent = new Consent();
    consent.setId(resultSet.getString("id"));
    try (Jsonb jsonb = JsonbBuilder.create()) {
        AccountAccess consentAccess = jsonb.fromJson(resultSet.getString("access"), AccountAccess.class);
        consent.setAccess(consentAccess);
    } catch (Exception e) {
        throw new SerializerException(e.getMessage(), e);
    }
    consent.setRecurringIndicator(resultSet.getBoolean("recurring_indicator"));
    consent.setLastAction(getDateFromTimestamp(resultSet.getTimestamp("last_action")));
    consent.setValidUntil(getDateFromTimestamp(resultSet.getTimestamp("valid_until")));
    consent.setLastUpdated(getDateFromTimestamp(resultSet.getTimestamp("last_updated")));
    consent.setCreatedAt(getDateFromTimestamp(resultSet.getTimestamp("created_at")));
    consent.setFrequencyPerDay(resultSet.getInt("frequency_per_day"));
    consent.setState(ConsentStatus.getByString(resultSet.getString("state")));
    consent.getSca().setApproach(SCA.Approach.valueOf(resultSet.getString("chosen_sca_method")));
    consent.setCombinedServiceIndicator(resultSet.getBoolean("combined_service_indicator"));
    consent.setxRequestId(UUID.fromString(resultSet.getString("x_request_id")));
    PSU psu = new PSU(resultSet.getString("psu_id"));
    psu.setIdType(resultSet.getString("psu_id_type"));
    psu.setIp(resultSet.getString("psu_ip_address"));
    psu.setPort(resultSet.getInt("psu_ip_port"));
    psu.setUserAgent(resultSet.getString("psu_user_agent"));
    psu.setGeoLocation(resultSet.getString("psu_geo_location"));
    psu.setCorporateId(resultSet.getString("psu_corporate_id"));
    psu.setCorporateIdType(resultSet.getString("psu_corporate_id_type"));
    consent.setPsu(psu);
    return consent;
}
Also used : Jsonb(javax.json.bind.Jsonb) PSU(net.petafuel.styx.core.xs2a.entities.PSU) Consent(net.petafuel.styx.core.xs2a.entities.Consent) AccountAccess(net.petafuel.styx.core.xs2a.entities.AccountAccess) SerializerException(net.petafuel.styx.core.xs2a.exceptions.SerializerException) SerializerException(net.petafuel.styx.core.xs2a.exceptions.SerializerException) PersistenceException(net.petafuel.styx.core.persistence.PersistenceException) SQLException(java.sql.SQLException)

Example 15 with Consent

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

the class SCAHandler method decision.

public static SCAApproach decision(StrongAuthenticatableResource strongAuthenticatableResource) {
    SCA sca;
    SCAApproach scaMethod = null;
    String scope;
    ServiceRealm serviceRealm;
    if (strongAuthenticatableResource instanceof Consent) {
        Consent consent = (Consent) strongAuthenticatableResource;
        sca = consent.getSca();
        scope = "AIS: " + consent.getId();
        serviceRealm = ServiceRealm.CONSENT;
    } else if (strongAuthenticatableResource instanceof InitiatedPayment) {
        InitiatedPayment payment = (InitiatedPayment) strongAuthenticatableResource;
        sca = payment.getSca();
        scope = "PIS:" + payment.getPaymentId();
        serviceRealm = ServiceRealm.PAYMENT;
    } else {
        return null;
    }
    switch(sca.getApproach()) {
        case DECOUPLED:
            break;
        case EMBEDDED:
            break;
        case OAUTH2:
            String link;
            if (isLinkBuilt(strongAuthenticatableResource.getLinks().getScaOAuth())) {
                link = strongAuthenticatableResource.getLinks().getScaOAuth().getUrl();
            } else {
                OAuthSession session = OAuthService.startSession(strongAuthenticatableResource, scope);
                link = OAuthService.buildLink(session.getState(), strongAuthenticatableResource.getxRequestId(), serviceRealm);
            }
            scaMethod = new OAuth2(link);
            break;
        case REDIRECT:
            scaMethod = new Redirect(strongAuthenticatableResource.getLinks().getScaRedirect().getUrl());
            break;
        case REQUIRE_AUTHORISATION_RESOURCE:
            // Do nothing
            break;
        default:
            throw new InvalidSCAMethodException("Found SCA Method is unsupported");
    }
    return scaMethod;
}
Also used : SCA(net.petafuel.styx.core.xs2a.entities.SCA) InvalidSCAMethodException(net.petafuel.styx.core.xs2a.exceptions.InvalidSCAMethodException) Consent(net.petafuel.styx.core.xs2a.entities.Consent) OAuthSession(net.petafuel.styx.core.xs2a.oauth.entities.OAuthSession) InitiatedPayment(net.petafuel.styx.core.xs2a.entities.InitiatedPayment) ServiceRealm(net.petafuel.styx.core.xs2a.callback.entity.ServiceRealm)

Aggregations

Consent (net.petafuel.styx.core.xs2a.entities.Consent)17 PersistentConsent (net.petafuel.styx.core.persistence.layers.PersistentConsent)12 Test (org.junit.jupiter.api.Test)6 BankRequestFailedException (net.petafuel.styx.core.xs2a.exceptions.BankRequestFailedException)5 Order (org.junit.jupiter.api.Order)5 TestMethodOrder (org.junit.jupiter.api.TestMethodOrder)5 IOException (java.io.IOException)4 Jsonb (javax.json.bind.Jsonb)4 Response (okhttp3.Response)4 AISRequest (net.petafuel.styx.core.xs2a.contracts.AISRequest)3 ApplicationPath (javax.ws.rs.ApplicationPath)2 Path (javax.ws.rs.Path)2 AcceptsPreStepAuth (net.petafuel.styx.api.filter.authentication.boundary.AcceptsPreStepAuth)2 IOProcessor (net.petafuel.styx.core.ioprocessing.IOProcessor)2 PSU (net.petafuel.styx.core.xs2a.entities.PSU)2 AISRequestFactory (net.petafuel.styx.core.xs2a.factory.AISRequestFactory)2 XS2AFactoryInput (net.petafuel.styx.core.xs2a.factory.XS2AFactoryInput)2 SQLException (java.sql.SQLException)1 UUID (java.util.UUID)1 JsonbConfig (javax.json.bind.JsonbConfig)1