use of net.petafuel.styx.core.banklookup.XS2AStandard in project styx by petafuel.
the class ConsorsAISTest method testAccountDetails.
@Test
@Order(2)
public void testAccountDetails() throws BankRequestFailedException, BankLookupFailedException, BankNotFoundException {
XS2AStandard standard = (new SAD()).getBankByBIC(BIC, true);
XS2AFactoryInput xs2AFactoryInput = new XS2AFactoryInput();
xs2AFactoryInput.setAccountId(ACCOUNT_ID);
xs2AFactoryInput.setConsentId(CONSENT);
xs2AFactoryInput.setWithBalance(true);
AISRequest aisRequest = new AISRequestFactory().create(standard.getRequestClassProvider().accountDetails(), xs2AFactoryInput);
AccountDetails result = standard.getAis().getAccount(aisRequest);
Assertions.assertNotNull(result);
Assertions.assertNotNull(result.getIban());
}
use of net.petafuel.styx.core.banklookup.XS2AStandard 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.XS2AStandard 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.XS2AStandard in project styx by petafuel.
the class OAuthCallbackProcessor method handlePaymentRealm.
private static RedirectStatus handlePaymentRealm(ServiceRealm serviceRealm, RealmParameter realmParameter, String identifier, OAuthCallback oAuthCallback) {
String path = String.format("%s/%s/%s", serviceRealm.name().toLowerCase(), realmParameter.name().toLowerCase(), identifier);
if (oAuthCallback.getError() == null && handleSuccessfulOAuth2(oAuthCallback.getCode(), oAuthCallback.getState(), path)) {
PaymentEntry paymentEntry = PersistentPayment.getById(identifier);
XS2AStandard xs2AStandard;
try {
xs2AStandard = (new SAD()).getBankByBIC(paymentEntry.getBic());
} catch (BankNotFoundException | BankLookupFailedException e) {
LOG.error("OAuth Callback on serviceRealm={}, identifier={}, realmParameter={} failed due to SAD not being able to initialize the aspsp connected to the payment SCA", serviceRealm, identifier, realmParameter, e);
return new RedirectStatus(StatusType.ERROR, identifier);
}
// In case of oauth we will not schedule the task during payment initiation but here after we received a callback
XS2AFactoryInput xs2AFactoryInput = new XS2AFactoryInput();
xs2AFactoryInput.setPaymentId(paymentEntry.getPaymentId());
xs2AFactoryInput.setPaymentService(paymentEntry.getPaymentService());
xs2AFactoryInput.setPaymentProduct(paymentEntry.getPaymentProduct());
ThreadManager.getInstance().queueTask(new PaymentStatusPoll(xs2AFactoryInput, xs2AStandard.getAspsp().getBic(), UUID.fromString(paymentEntry.getId())));
return new RedirectStatus(StatusType.SUCCESS, oAuthCallback.getState());
} else {
LOG.error(FAILED_OAUTH2, oAuthCallback.getError(), oAuthCallback.getErrorDescription(), oAuthCallback.getState());
return new RedirectStatus(StatusType.ERROR, oAuthCallback.getState());
}
}
Aggregations