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));
}
}
}
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());
}
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);
});
}
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);
}
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());
}
Aggregations