Search in sources :

Example 1 with ImplementerOption

use of net.petafuel.styx.core.banklookup.sad.entities.ImplementerOption 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 ImplementerOption

use of net.petafuel.styx.core.banklookup.sad.entities.ImplementerOption in project styx by petafuel.

the class SADResourceTest method GetAspspDataSuccessTest.

@Test
@Category(IntegrationTest.class)
public void GetAspspDataSuccessTest() throws BankLookupFailedException, BankNotFoundException {
    Aspsp aspsp = getAspspByBic(BIC);
    Map<String, ImplementerOption> implementerOptions = aspsp.getConfig().getImplementerOptions();
    Invocation.Builder invocationBuilder = target("/v1/aspsp/" + BIC).request();
    invocationBuilder.header("token", pisAccessToken);
    invocationBuilder.header("Content-Type", "application/json");
    Invocation invocation = invocationBuilder.buildGet();
    Response response = invocation.invoke(Response.class);
    Assertions.assertEquals(200, response.getStatus());
    JsonObject jsonResponse = response.readEntity(JsonObject.class);
    JsonObject jsonScaApproaches = (JsonObject) jsonResponse.get("scaApproaches");
    JsonObject jsonSupportedServices = (JsonObject) jsonResponse.get("supportedServices");
    JsonObject jsonSupportedServicesAis = (JsonObject) jsonSupportedServices.get("ais");
    JsonObject jsonSupportedServicesCof = (JsonObject) jsonSupportedServices.get("cof");
    JsonObject jsonSupportedServicesPis = (JsonObject) jsonSupportedServices.get("pis");
    Assertions.assertEquals(aspsp.isActive(), jsonResponse.getBoolean("active"));
    Assertions.assertEquals(aspsp.getName(), jsonResponse.getString("name"));
    Assertions.assertFalse(jsonResponse.getBoolean("multicurrencyAccountsSupported"));
    Assertions.assertFalse(jsonResponse.getBoolean("prestepRequired"));
    Assertions.assertTrue(jsonResponse.containsKey("scaApproaches"));
    Assertions.assertEquals(implementerOptions.get("IO5").getOptions().get("decoupled"), jsonScaApproaches.getBoolean("decoupled"));
    Assertions.assertEquals(implementerOptions.get("IO5").getOptions().get("embedded"), jsonScaApproaches.getBoolean("embedded"));
    Assertions.assertEquals(implementerOptions.get("IO5").getOptions().get("oauth"), jsonScaApproaches.getBoolean("oAuth"));
    Assertions.assertEquals(implementerOptions.get("IO5").getOptions().get("redirect"), jsonScaApproaches.getBoolean("redirect"));
    Assertions.assertTrue(jsonResponse.containsKey("supportedServices"));
    Assertions.assertTrue(jsonSupportedServices.containsKey("ais"));
    Assertions.assertTrue(jsonSupportedServicesAis.getBoolean("accountDetails"));
    Assertions.assertTrue(jsonSupportedServicesAis.getBoolean("accountList"));
    Assertions.assertFalse(jsonSupportedServicesAis.getBoolean("accountsAccountIdTransactionsResourceId"));
    Assertions.assertFalse(jsonSupportedServicesAis.getBoolean("accountsAccountIdTransactionsWithBalance"));
    Assertions.assertFalse(jsonSupportedServicesAis.getBoolean("accountsAccountIdWithBalance"));
    Assertions.assertFalse(jsonSupportedServicesAis.getBoolean("accountsWithBalance"));
    Assertions.assertTrue(jsonSupportedServices.containsKey("cof"));
    Assertions.assertTrue(jsonSupportedServicesCof.containsKey("fundsConfirmation"));
    Assertions.assertTrue(jsonSupportedServices.containsKey("pis"));
    Assertions.assertTrue(jsonSupportedServicesPis.getBoolean("bulkPayments"));
    Assertions.assertTrue(jsonSupportedServicesPis.getBoolean("futureDatedPayments"));
    Assertions.assertTrue(jsonSupportedServicesPis.getBoolean("periodicPayments"));
    Assertions.assertTrue(jsonSupportedServicesPis.getBoolean("singlePayments"));
    Response response2 = invocation.invoke(Response.class);
    Assertions.assertEquals(200, response2.getStatus());
}
Also used : Response(javax.ws.rs.core.Response) Aspsp(net.petafuel.styx.core.banklookup.sad.entities.Aspsp) Invocation(javax.ws.rs.client.Invocation) JsonObject(javax.json.JsonObject) ImplementerOption(net.petafuel.styx.core.banklookup.sad.entities.ImplementerOption) ResponseCategory(net.petafuel.styx.api.exception.ResponseCategory) Category(org.junit.experimental.categories.Category) IntegrationTest(net.petafuel.styx.api.IntegrationTest) Test(org.junit.Test) StyxRESTTest(net.petafuel.styx.api.StyxRESTTest)

Example 3 with ImplementerOption

use of net.petafuel.styx.core.banklookup.sad.entities.ImplementerOption in project styx by petafuel.

the class SAD method parseImplementerOptions.

/**
 * Parsing the implementer options json and mapping to ImplementerOption List
 * within the aspsp
 *
 * @param aspsp Aspsp object that should be used and should be modified with the
 *              parsed implementer options
 */
private void parseImplementerOptions(Aspsp aspsp) {
    String rawDefaultConfig;
    // template if not present for aspsp
    if ((rawDefaultConfig = aspsp.getConfig().getConfiguration()) == null) {
        rawDefaultConfig = aspsp.getConfig().getStandard().getConfigTemplate();
    }
    JsonObject defaultConfig = null;
    try (Jsonb jsonb = JsonbBuilder.create()) {
        defaultConfig = jsonb.fromJson(rawDefaultConfig, JsonObject.class);
    } catch (Exception e) {
        throw new SerializerException("unable to deserialize implementer-options json on SAD Service usage", e);
    }
    // Check if there is a styx config on aspsp level
    // If not present on aspsp level use styx config template of related standard
    String rawStyxConfig;
    if ((rawStyxConfig = aspsp.getConfig().getStyxConfiguration()) == null) {
        rawStyxConfig = aspsp.getConfig().getStandard().getStyxConfigTemplate();
    }
    // Merge the styx config options into the defaultConfig
    JsonObject styxConfig = null;
    try (Jsonb jsonb = JsonbBuilder.create()) {
        styxConfig = jsonb.fromJson(rawStyxConfig, JsonObject.class);
    } catch (Exception e) {
        throw new SerializerException("unable to deserialize styx-options json on SAD Service usage", e);
    }
    JsonObjectBuilder defaultConfigJsonBuilder = Json.createObjectBuilder(defaultConfig);
    defaultConfigJsonBuilder.addAll(Json.createObjectBuilder(styxConfig));
    defaultConfig = defaultConfigJsonBuilder.build();
    defaultConfig.entrySet().stream().forEach(entry -> {
        JsonObject currentOption = entry.getValue().asJsonObject();
        ImplementerOption implementerOption = new ImplementerOption();
        implementerOption.setId(entry.getKey());
        implementerOption.setDescription(currentOption.getString("description", "default"));
        currentOption.get("options").asJsonObject().entrySet().stream().forEach(option -> implementerOption.addOption(option.getKey(), Boolean.valueOf(option.getValue().toString())));
        aspsp.getConfig().getImplementerOptions().put(implementerOption.getId(), implementerOption);
    });
}
Also used : Jsonb(javax.json.bind.Jsonb) JsonObject(javax.json.JsonObject) JsonObjectBuilder(javax.json.JsonObjectBuilder) SerializerException(net.petafuel.styx.core.xs2a.exceptions.SerializerException) ImplementerOption(net.petafuel.styx.core.banklookup.sad.entities.ImplementerOption) SerializerException(net.petafuel.styx.core.xs2a.exceptions.SerializerException) BankNotFoundException(net.petafuel.styx.core.banklookup.exceptions.BankNotFoundException) SADException(net.petafuel.styx.core.xs2a.exceptions.SADException) InvocationTargetException(java.lang.reflect.InvocationTargetException) BankLookupFailedException(net.petafuel.styx.core.banklookup.exceptions.BankLookupFailedException)

Example 4 with ImplementerOption

use of net.petafuel.styx.core.banklookup.sad.entities.ImplementerOption in project styx by petafuel.

the class STYX09IntegrationTest method configure.

@Override
protected Application configure() {
    styx09Option = new ImplementerOption();
    styx09Option.setId("STYX09");
    ing = new Aspsp();
    ing.setConfig(new Config());
    ing.setBic(TEST_BIC);
    Url url = new Url();
    url.setCommonUrl("https://api.sandbox.ing.com");
    ing.setSandboxUrl(url);
    ResourceConfig config = setupFiltersAndErrorHandlers();
    if (pisAccessToken == null || Objects.equals(pisAccessToken, "")) {
        Assertions.fail("test.token.access.pis not set in test properties");
    }
    return config.register(AuthenticationResource.class).register(PaymentInitiationResource.class);
}
Also used : Aspsp(net.petafuel.styx.core.banklookup.sad.entities.Aspsp) Config(net.petafuel.styx.core.banklookup.sad.entities.Config) ResourceConfig(org.glassfish.jersey.server.ResourceConfig) ResourceConfig(org.glassfish.jersey.server.ResourceConfig) ImplementerOption(net.petafuel.styx.core.banklookup.sad.entities.ImplementerOption) Url(net.petafuel.styx.core.banklookup.sad.entities.Url) AuthenticationResource(net.petafuel.styx.api.v1.authentication.boundary.AuthenticationResource)

Example 5 with ImplementerOption

use of net.petafuel.styx.core.banklookup.sad.entities.ImplementerOption in project styx by petafuel.

the class STYX10UnitTest method setup.

@BeforeAll
static void setup() {
    styx10Option = new ImplementerOption();
    styx10Option.setId("STYX10");
    uniCredit = new Aspsp();
    uniCredit.setConfig(new Config());
}
Also used : Aspsp(net.petafuel.styx.core.banklookup.sad.entities.Aspsp) Config(net.petafuel.styx.core.banklookup.sad.entities.Config) ImplementerOption(net.petafuel.styx.core.banklookup.sad.entities.ImplementerOption) BeforeAll(org.junit.jupiter.api.BeforeAll)

Aggregations

ImplementerOption (net.petafuel.styx.core.banklookup.sad.entities.ImplementerOption)15 Aspsp (net.petafuel.styx.core.banklookup.sad.entities.Aspsp)10 Config (net.petafuel.styx.core.banklookup.sad.entities.Config)8 BeforeAll (org.junit.jupiter.api.BeforeAll)6 JsonObject (javax.json.JsonObject)2 BankLookupFailedException (net.petafuel.styx.core.banklookup.exceptions.BankLookupFailedException)2 BankNotFoundException (net.petafuel.styx.core.banklookup.exceptions.BankNotFoundException)2 IOParser (net.petafuel.styx.core.ioprocessing.IOParser)2 Test (org.junit.jupiter.api.Test)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 Date (java.util.Date)1 HashMap (java.util.HashMap)1 UUID (java.util.UUID)1 JsonObjectBuilder (javax.json.JsonObjectBuilder)1 Jsonb (javax.json.bind.Jsonb)1 Invocation (javax.ws.rs.client.Invocation)1 Response (javax.ws.rs.core.Response)1 IntegrationTest (net.petafuel.styx.api.IntegrationTest)1 StyxRESTTest (net.petafuel.styx.api.StyxRESTTest)1 ResponseCategory (net.petafuel.styx.api.exception.ResponseCategory)1