use of net.petafuel.styx.core.banklookup.exceptions.BankLookupFailedException in project styx by petafuel.
the class SADTest method testXS2AStandardInitialisationProduction.
@ParameterizedTest
@MethodSource("BICProvider")
@DisplayName("testXS2AStandardInitialisationProduction() -> Check if PRODUCTION XS2AStandards can be created for all available BICs in SAD")
public void testXS2AStandardInitialisationProduction(String bic) throws BankNotFoundException, BankLookupFailedException {
SAD sad = new SAD();
Aspsp bank = PersistentSAD.getByBIC(bic);
XS2AStandard xs2AStandard = sad.getBankByBIC(bic);
try {
Assertions.assertAll(() -> {
if (bank.getProductionUrl().getCommonUrl() == null) {
if (bank.getProductionUrl().getAisUrl() != null) {
Assert.assertTrue("AIS Url was specified but no Consent Service was initialized", xs2AStandard.isCSImplemented());
Assert.assertTrue("AIS Url was specified but no related Service was initialized", xs2AStandard.isAISImplemented());
}
if (bank.getProductionUrl().getPisUrl() != null) {
Assert.assertTrue("PIS Url was specified but no related Service was initialized", xs2AStandard.isPISImplemented());
}
if (bank.getProductionUrl().getPiisUrl() != null) {
Assert.assertTrue("PIIS Url was specified but no related Service was initialized", xs2AStandard.isPIISImplemented());
}
} else {
boolean atLeastOneServiceImplemented = false;
if ((xs2AStandard.isAISImplemented() && xs2AStandard.isCSImplemented()) || xs2AStandard.isPIISImplemented() || xs2AStandard.isPISImplemented()) {
atLeastOneServiceImplemented = true;
}
Assert.assertTrue("General Url was specified but no related Service was initialized", atLeastOneServiceImplemented);
}
});
} catch (MultipleFailuresError e) {
if (!bank.isActive()) {
System.err.println("Test failed for bic=" + bic + " but bank is deactivated in styx: ");
e.getFailures().forEach(throwable -> System.err.println(throwable.getMessage()));
Assert.assertTrue(true);
} else {
System.err.println("Test failed for bic=" + bic + ": " + e.getMessage());
e.getFailures().forEach(throwable -> System.err.println(throwable.getMessage()));
Assert.fail();
}
}
}
use of net.petafuel.styx.core.banklookup.exceptions.BankLookupFailedException in project styx by petafuel.
the class SADTest method testXS2AStandardInitialisationSandbox.
@ParameterizedTest
@MethodSource("BICProvider")
@DisplayName("testXS2AStandardInitialisationSandbox() -> Check if SANDBOX XS2AStandards can be created for all available BICs in SAD")
public void testXS2AStandardInitialisationSandbox(String bic) throws BankNotFoundException, BankLookupFailedException {
SAD sad = new SAD();
Aspsp bank = PersistentSAD.getByBIC(bic);
XS2AStandard xs2AStandard = sad.getBankByBIC(bic, true);
try {
Assertions.assertAll(() -> {
if (bank.getSandboxUrl().getCommonUrl() == null) {
if (bank.getSandboxUrl().getAisUrl() != null) {
Assert.assertTrue("AIS Url was specified but no Consent Service was initialized", xs2AStandard.isCSImplemented());
Assert.assertTrue("AIS Url was specified but no related Service was initialized", xs2AStandard.isAISImplemented());
}
if (bank.getSandboxUrl().getPisUrl() != null) {
Assert.assertTrue("PIS Url was specified but no related Service was initialized", xs2AStandard.isPISImplemented());
}
if (bank.getSandboxUrl().getPiisUrl() != null) {
Assert.assertTrue("PIIS Url was specified but no related Service was initialized", xs2AStandard.isPIISImplemented());
}
} else {
boolean atLeastOneServiceImplemented = false;
if ((xs2AStandard.isAISImplemented() && xs2AStandard.isCSImplemented()) || xs2AStandard.isPIISImplemented() || xs2AStandard.isPISImplemented()) {
atLeastOneServiceImplemented = true;
}
Assert.assertTrue("General Url was specified but no related Service was initialized", atLeastOneServiceImplemented);
}
});
} catch (MultipleFailuresError e) {
if (!bank.isActive()) {
System.err.println("Test failed for bic=" + bic + " but bank is deactivated in styx: ");
e.getFailures().forEach(throwable -> System.err.println(throwable.getMessage()));
Assert.assertTrue(true);
} else {
System.err.println("Test failed for bic=" + bic + ": " + e.getMessage());
e.getFailures().forEach(throwable -> System.err.println(throwable.getMessage()));
Assert.fail();
}
}
}
use of net.petafuel.styx.core.banklookup.exceptions.BankLookupFailedException in project styx by petafuel.
the class SAD method getBankByBIC.
/**
* Returns a fully initialized XS2AStandard including instances of the service
* classes if available/implemented for bank standard
* If there is no entry found for the bic, a BankNotFoundException is thrown
*
* @param bic The bic which should be searched for in SAD
* @param isSandbox Should the service classes be initialized using the xs2a
* sandbox environment or production environment of the bank
* @return returns a XS2AStandard object which should contain fully initialized
* service objects for all service types if applicable/implemented
* @throws BankNotFoundException the bic was not found in the SAD Database
* @throws BankLookupFailedException there was an error initializing a service
* which is necessary for
*/
public XS2AStandard getBankByBIC(String bic, boolean isSandbox) throws BankLookupFailedException, BankNotFoundException {
this.bic = bic;
// Read aspsp data from SAD database into Aspsp.class model
Aspsp aspsp = PersistentSAD.getByBIC(bic);
if (aspsp == null) {
LOG.error("The requested bank for bic={} is not avaiable in SAD {}", bic, SAD_BANK_NOT_FOUND);
throw new BankNotFoundException("The requested aspsp for bic " + bic + " is not available in SAD");
}
XS2AStandard xs2AStandard = new XS2AStandard();
// parse the implementer options into the implementerOptions List of the aspsp
// object
parseImplementerOptions(aspsp);
xs2AStandard.setAspsp(aspsp);
String standardClassName = aspsp.getConfig().getStandard().getName();
String standardPackage = standardClassName.toLowerCase();
Version version = new Version(aspsp.getConfig().getStandard().getVersion());
String interfaceVersion = ".v" + version.getMajor() + "_" + version.getMinor();
// build a full qualified class name without service type suffix
xs2aClassPrefix = SERVICES_PACKAGE_PATH + standardPackage + interfaceVersion + "." + standardClassName;
// Check if requesting sandbox or production urls
if (isSandbox) {
LOG.warn("SAD is using sandbox environment bic={}", bic);
mapASPSPUrlSetup(aspsp.getSandboxUrl());
} else {
mapASPSPUrlSetup(aspsp.getProductionUrl());
}
// HttpSigner will be used in all following service initialisations and is
// therefore initialized first
// Signer might be null if the target standard does not require or did not
// implement the class in its package
Class<?> httpSignerClazz = getServiceClass(xs2aClassPrefix + XS2AServices.HTTP_SIGNER.getValue());
try {
IXS2AHttpSigner httpSignerInstance = null;
if (httpSignerClazz != null && shouldSign(xs2AStandard)) {
httpSignerInstance = (IXS2AHttpSigner) httpSignerClazz.getConstructor().newInstance();
}
// initializing all service classes per service type and setting them into the
// xs2aStandard
CSInterface csServiceInstance = (CSInterface) reflectServiceInstance(httpSignerInstance, XS2AServices.CS);
xs2AStandard.setCs(csServiceInstance);
AISInterface aisServiceInstance = (AISInterface) reflectServiceInstance(httpSignerInstance, XS2AServices.AIS);
xs2AStandard.setAis(aisServiceInstance);
PISInterface pisServiceInstance = (PISInterface) reflectServiceInstance(httpSignerInstance, XS2AServices.PIS);
xs2AStandard.setPis(pisServiceInstance);
PIISInterface piisServiceInstance = (PIISInterface) reflectServiceInstance(httpSignerInstance, XS2AServices.PIIS);
xs2AStandard.setPiis(piisServiceInstance);
Class<?> requestClassProviderClazz = getServiceClass(xs2aClassPrefix + XS2AServices.REQUEST_CLASS_PROVIDER.getValue());
if (requestClassProviderClazz == null) {
throw new SADException("RequestClassProvider was not found for the requested XS2A Standard but is required");
}
XS2ARequestClassProvider requestClassProviderInstance;
requestClassProviderInstance = (XS2ARequestClassProvider) requestClassProviderClazz.getConstructor().newInstance();
xs2AStandard.setRequestClassProvider(requestClassProviderInstance);
} catch (InstantiationException | IllegalAccessException e) {
LOG.error("Error initialising service class through SAD: {}", e.getMessage(), e);
throw new BankLookupFailedException(e.getMessage(), e);
} catch (InvocationTargetException e) {
LOG.error("Error calling service class constructor through SAD: {}", e.getMessage(), e);
throw new BankLookupFailedException(e.getMessage(), e);
} catch (NoSuchMethodException e) {
LOG.error("The service class has no matching constructor for initialisation through SAD: {}", e.getMessage(), e);
throw new BankLookupFailedException(e.getMessage(), e);
}
return xs2AStandard;
}
use of net.petafuel.styx.core.banklookup.exceptions.BankLookupFailedException in project styx by petafuel.
the class SADInitialisationFilter method filter.
@Override
public void filter(ContainerRequestContext containerRequestContext) throws IOException {
if (containerRequestContext.getProperty(BICFilter.class.getName()) == null) {
LOG.info("XS2AStandard was not initialized as there was no BICFilter in place for the requested Resource");
return;
}
String bic = (String) containerRequestContext.getProperty(BICFilter.class.getName());
XS2AStandard xs2AStandard;
try {
xs2AStandard = new SAD().getBankByBIC(bic, WebServer.isSandbox());
if (Boolean.FALSE.equals(xs2AStandard.getAspsp().isActive())) {
throw new StyxException(new ResponseEntity("ASPSP with bic=" + xs2AStandard.getAspsp().getBic() + " is inactive", ResponseConstant.SAD_ASPSP_INACTIVE, ResponseCategory.ERROR, ResponseOrigin.STYX));
}
LOG.info("XS2AStandard successfully initialized. bic={}, aspspName={}, aspspId={}, aspspGroup={}, aspspGroupId={}, standard={}, standardVersion={}, ais={}, cs={}, pis={}, piis={}, availableOptions={}", xs2AStandard.getAspsp().getBic(), xs2AStandard.getAspsp().getName(), xs2AStandard.getAspsp().getId(), xs2AStandard.getAspsp().getAspspGroup().getName(), xs2AStandard.getAspsp().getAspspGroup().getId(), xs2AStandard.getAspsp().getConfig().getStandard().getName(), xs2AStandard.getAspsp().getConfig().getStandard().getVersion(), xs2AStandard.getAis(), xs2AStandard.getCs(), xs2AStandard.getPis(), xs2AStandard.getPiis(), xs2AStandard.getAspsp().getConfig().getImplementerOptions() != null ? xs2AStandard.getAspsp().getConfig().getImplementerOptions().size() : 0);
} catch (BankNotFoundException bicNotFound) {
throw new StyxException(new ResponseEntity(bicNotFound.getMessage(), ResponseConstant.SAD_ASPSP_NOT_FOUND, ResponseCategory.ERROR, ResponseOrigin.STYX));
} catch (BankLookupFailedException internalSADError) {
throw new StyxException(new ResponseEntity("SAD was unable to initialize required Services", ResponseConstant.INTERNAL_SERVER_ERROR, ResponseCategory.ERROR, ResponseOrigin.STYX), internalSADError);
}
containerRequestContext.setProperty(XS2AStandard.class.getName(), xs2AStandard);
}
use of net.petafuel.styx.core.banklookup.exceptions.BankLookupFailedException in project styx by petafuel.
the class ASPSPProcessor method process.
/**
* @param bic - BIC provided by the client
* @return ASPSPResponse | null
*/
public static ASPSPResponse process(String bic) {
try {
Aspsp aspsp = getAspspByBic(bic);
if (Objects.nonNull(aspsp)) {
ASPSPResponse aspspResponse = new ASPSPResponse();
Map<String, ImplementerOption> implementerOptions = aspsp.getConfig().getImplementerOptions();
SupportedServicesPIS supportedServicesPIS = processSupportedServicesPis(implementerOptions);
SupportedServicesAIS supportedServicesAIS = processSupportedServicesAis(implementerOptions);
SupportedServicesCOF supportedServicesCOF = processSupportedServicesCof();
SupportedServices supportedServices = new SupportedServices(supportedServicesPIS, supportedServicesAIS, supportedServicesCOF);
aspspResponse.setName(aspsp.getName());
aspspResponse.setActive(aspsp.isActive());
aspspResponse.setScaApproaches(processScaApproaches(implementerOptions));
aspspResponse.setSupportedServices(supportedServices);
aspspResponse.setPrestepRequired(processPrestepRequired(implementerOptions));
aspspResponse.setMulticurrencyAccountsSupported(proccessMulticurrencyAccountsSupported(implementerOptions));
return aspspResponse;
} else {
return null;
}
} catch (BankNotFoundException | BankLookupFailedException bankNotFoundException) {
LOG.error("Bank not found for bic={} in SAD", bic);
return null;
}
}
Aggregations