Search in sources :

Example 1 with XS2AStandard

use of net.petafuel.styx.core.banklookup.XS2AStandard in project styx by petafuel.

the class PreAuthAccessFilter method filter.

/**
 * Supressing java:S3776 -> need to rework logic to reduce code complexity
 *
 * @param containerRequestContext
 */
@Override
@SuppressWarnings("java:S3776")
public void filter(ContainerRequestContext containerRequestContext) {
    XS2AStandard xs2AStandard = (XS2AStandard) containerRequestContext.getProperty(XS2AStandard.class.getName());
    IOParser ioParser = new IOParser(xs2AStandard.getAspsp());
    ImplementerOption ioPreAuthRequired = ioParser.get("IO6");
    if (ioPreAuthRequired != null && ioPreAuthRequired.getOptions().get(IOParser.Option.REQUIRED)) {
        LOG.info("ASPSP bic={} requires pre-auth", xs2AStandard.getAspsp().getBic());
        // preauth is available and required for this bank -> check if preauth id is present
        String preAuthIdString = containerRequestContext.getHeaderString(PRE_AUTH_ID);
        if (preAuthIdString == null || "".equals(preAuthIdString)) {
            throw new StyxException(new ResponseEntity("The requested aspsps requires a pre-step authorisation, preAuthId Header is missing", ResponseConstant.STYX_PREAUTH_HEADER_REQUIRED, ResponseCategory.ERROR, ResponseOrigin.CLIENT));
        }
        try {
            UUID preAuthId = UUID.fromString(preAuthIdString);
            OAuthSession oAuthSession = PersistentOAuthSession.getById(preAuthId);
            LOG.info("Loaded state={} oauth_session", oAuthSession.getState());
            STYX03.setPreauthId(preAuthId);
            if (oAuthSession.getAccessToken() == null || oAuthSession.getAccessTokenExpiresAt() == null) {
                throw new PersistenceEmptyResultSetException("The access_token data should be set");
            }
            if (oAuthSession.getAccessTokenExpiresAt().before(new Date())) {
                if (oAuthSession.getRefreshTokenExpiresAt().after(new Date())) {
                    oAuthSession = refreshToken(oAuthSession);
                } else {
                    throw new OAuthTokenExpiredException(OAuthTokenExpiredException.MESSAGE);
                }
            }
            // Add the Authorization: <type> <credentials> header to the request context so we can use it later on demand
            Map<String, String> additionalHeaders = new HashMap<>();
            additionalHeaders.put(XS2AHeader.AUTHORIZATION, oAuthSession.getTokenType() + " " + oAuthSession.getAccessToken());
            containerRequestContext.setProperty(PreAuthAccessFilter.class.getName(), additionalHeaders);
            LOG.info("Successfully attached pre-auth from oAuthSessionState={}", oAuthSession.getState());
        } catch (PersistenceEmptyResultSetException noOauthSessionFound) {
            throw new StyxException(new ResponseEntity("There was no valid pre-step authorisation found for the specified preAuthId", ResponseConstant.STYX_PREAUTH_NOT_AVAILABLE, ResponseCategory.ERROR, ResponseOrigin.CLIENT));
        } catch (OAuthTokenExpiredException tokenExpired) {
            throw new StyxException(new ResponseEntity(tokenExpired.getMessage(), ResponseConstant.STYX_PREAUTH_EXPIRED, ResponseCategory.ERROR, ResponseOrigin.CLIENT));
        }
    }
}
Also used : XS2AStandard(net.petafuel.styx.core.banklookup.XS2AStandard) OAuthTokenExpiredException(net.petafuel.styx.core.xs2a.exceptions.OAuthTokenExpiredException) HashMap(java.util.HashMap) PersistentOAuthSession(net.petafuel.styx.core.persistence.layers.PersistentOAuthSession) OAuthSession(net.petafuel.styx.core.xs2a.oauth.entities.OAuthSession) PersistenceEmptyResultSetException(net.petafuel.styx.core.persistence.PersistenceEmptyResultSetException) ImplementerOption(net.petafuel.styx.core.banklookup.sad.entities.ImplementerOption) StyxException(net.petafuel.styx.api.exception.StyxException) Date(java.util.Date) ResponseEntity(net.petafuel.styx.api.exception.ResponseEntity) IOParser(net.petafuel.styx.core.ioprocessing.IOParser) UUID(java.util.UUID)

Example 2 with XS2AStandard

use of net.petafuel.styx.core.banklookup.XS2AStandard in project styx by petafuel.

the class ConsorsAISTest method testTransactions.

@Test
@Order(4)
public void testTransactions() throws BankLookupFailedException, BankNotFoundException, ParseException, BankRequestFailedException {
    XS2AStandard standard = (new SAD()).getBankByBIC(BIC, true);
    SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
    Date from = format.parse("2019-03-03");
    Date to = new Date();
    XS2AFactoryInput xs2AFactoryInput = new XS2AFactoryInput();
    xs2AFactoryInput.setAccountId(ACCOUNT_ID);
    xs2AFactoryInput.setConsentId(CONSENT);
    xs2AFactoryInput.setBookingStatus("booked");
    xs2AFactoryInput.setDateFrom(from);
    xs2AFactoryInput.setDateTo(to);
    AISRequest aisRequest = new AISRequestFactory().create(standard.getRequestClassProvider().accountTransactionList(), xs2AFactoryInput);
    TransactionContainer result = standard.getAis().getTransactionsByAccount(aisRequest);
    Assertions.assertNotNull(result);
    Assertions.assertNotNull(result.getTransactions());
}
Also used : XS2AStandard(net.petafuel.styx.core.banklookup.XS2AStandard) AISRequest(net.petafuel.styx.core.xs2a.contracts.AISRequest) SAD(net.petafuel.styx.core.banklookup.sad.SAD) XS2AFactoryInput(net.petafuel.styx.core.xs2a.factory.XS2AFactoryInput) TransactionContainer(net.petafuel.styx.core.xs2a.entities.TransactionContainer) AISRequestFactory(net.petafuel.styx.core.xs2a.factory.AISRequestFactory) SimpleDateFormat(java.text.SimpleDateFormat) Date(java.util.Date) TestMethodOrder(org.junit.jupiter.api.TestMethodOrder) Order(org.junit.jupiter.api.Order) Test(org.junit.jupiter.api.Test)

Example 3 with XS2AStandard

use of net.petafuel.styx.core.banklookup.XS2AStandard in project styx by petafuel.

the class ConsorsAISTest method testBalances.

@Test
@Order(3)
public void testBalances() throws BankRequestFailedException, BankLookupFailedException, BankNotFoundException {
    XS2AStandard standard = (new SAD()).getBankByBIC(BIC, true);
    XS2AFactoryInput xs2AFactoryInput = new XS2AFactoryInput();
    xs2AFactoryInput.setAccountId(ACCOUNT_ID);
    xs2AFactoryInput.setConsentId(CONSENT);
    AISRequest aisRequest = new AISRequestFactory().create(standard.getRequestClassProvider().accountBalances(), xs2AFactoryInput);
    BalanceContainer result = standard.getAis().getBalancesByAccount(aisRequest);
    Assertions.assertNotNull(result);
    Assertions.assertTrue(result.getBalances().size() >= 1);
}
Also used : XS2AStandard(net.petafuel.styx.core.banklookup.XS2AStandard) AISRequest(net.petafuel.styx.core.xs2a.contracts.AISRequest) SAD(net.petafuel.styx.core.banklookup.sad.SAD) XS2AFactoryInput(net.petafuel.styx.core.xs2a.factory.XS2AFactoryInput) AISRequestFactory(net.petafuel.styx.core.xs2a.factory.AISRequestFactory) BalanceContainer(net.petafuel.styx.core.xs2a.entities.BalanceContainer) TestMethodOrder(org.junit.jupiter.api.TestMethodOrder) Order(org.junit.jupiter.api.Order) Test(org.junit.jupiter.api.Test)

Example 4 with XS2AStandard

use of net.petafuel.styx.core.banklookup.XS2AStandard in project styx by petafuel.

the class ConsorsAISTest method testAccountList.

@Test
@Order(1)
public void testAccountList() throws BankRequestFailedException, BankLookupFailedException, BankNotFoundException {
    XS2AStandard standard = (new SAD()).getBankByBIC(BIC, true);
    XS2AFactoryInput xs2AFactoryInput = new XS2AFactoryInput();
    xs2AFactoryInput.setConsentId(CONSENT);
    AISRequest aisRequest = new AISRequestFactory().create(standard.getRequestClassProvider().accountList(), xs2AFactoryInput);
    aisRequest.setWithBalance(true);
    List<AccountDetails> list = standard.getAis().getAccountList(aisRequest);
    Assertions.assertTrue(list.size() >= 1);
}
Also used : XS2AStandard(net.petafuel.styx.core.banklookup.XS2AStandard) AISRequest(net.petafuel.styx.core.xs2a.contracts.AISRequest) SAD(net.petafuel.styx.core.banklookup.sad.SAD) XS2AFactoryInput(net.petafuel.styx.core.xs2a.factory.XS2AFactoryInput) AISRequestFactory(net.petafuel.styx.core.xs2a.factory.AISRequestFactory) AccountDetails(net.petafuel.styx.core.xs2a.entities.AccountDetails) TestMethodOrder(org.junit.jupiter.api.TestMethodOrder) Order(org.junit.jupiter.api.Order) Test(org.junit.jupiter.api.Test)

Example 5 with XS2AStandard

use of net.petafuel.styx.core.banklookup.XS2AStandard in project styx by petafuel.

the class ConsorsAISTest method testTransactionDetails.

@Test
@Order(5)
public void testTransactionDetails() throws BankRequestFailedException, BankLookupFailedException, BankNotFoundException {
    XS2AStandard standard = (new SAD()).getBankByBIC(BIC, true);
    XS2AFactoryInput xs2AFactoryInput = new XS2AFactoryInput();
    xs2AFactoryInput.setAccountId(ACCOUNT_ID);
    xs2AFactoryInput.setTransactionId(TRANSACTION_ID);
    xs2AFactoryInput.setConsentId(CONSENT);
    AISRequest aisRequest = new AISRequestFactory().create(standard.getRequestClassProvider().accountTransactionDetails(), xs2AFactoryInput);
    Transaction result = standard.getAis().getTransaction(aisRequest);
    Assertions.assertNotNull(result);
    Assertions.assertNotNull(result.getDebtorAccount());
}
Also used : XS2AStandard(net.petafuel.styx.core.banklookup.XS2AStandard) Transaction(net.petafuel.styx.core.xs2a.entities.Transaction) AISRequest(net.petafuel.styx.core.xs2a.contracts.AISRequest) SAD(net.petafuel.styx.core.banklookup.sad.SAD) XS2AFactoryInput(net.petafuel.styx.core.xs2a.factory.XS2AFactoryInput) AISRequestFactory(net.petafuel.styx.core.xs2a.factory.AISRequestFactory) TestMethodOrder(org.junit.jupiter.api.TestMethodOrder) Order(org.junit.jupiter.api.Order) Test(org.junit.jupiter.api.Test)

Aggregations

XS2AStandard (net.petafuel.styx.core.banklookup.XS2AStandard)9 SAD (net.petafuel.styx.core.banklookup.sad.SAD)7 XS2AFactoryInput (net.petafuel.styx.core.xs2a.factory.XS2AFactoryInput)6 AISRequest (net.petafuel.styx.core.xs2a.contracts.AISRequest)5 AISRequestFactory (net.petafuel.styx.core.xs2a.factory.AISRequestFactory)5 Order (org.junit.jupiter.api.Order)5 Test (org.junit.jupiter.api.Test)5 TestMethodOrder (org.junit.jupiter.api.TestMethodOrder)5 BankLookupFailedException (net.petafuel.styx.core.banklookup.exceptions.BankLookupFailedException)3 BankNotFoundException (net.petafuel.styx.core.banklookup.exceptions.BankNotFoundException)3 Date (java.util.Date)2 ResponseEntity (net.petafuel.styx.api.exception.ResponseEntity)2 StyxException (net.petafuel.styx.api.exception.StyxException)2 AccountDetails (net.petafuel.styx.core.xs2a.entities.AccountDetails)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 SimpleDateFormat (java.text.SimpleDateFormat)1 HashMap (java.util.HashMap)1 UUID (java.util.UUID)1 RedirectStatus (net.petafuel.styx.api.v1.status.entity.RedirectStatus)1 Aspsp (net.petafuel.styx.core.banklookup.sad.entities.Aspsp)1