Search in sources :

Example 1 with IXS2AHttpSigner

use of net.petafuel.styx.core.xs2a.contracts.IXS2AHttpSigner in project styx by petafuel.

the class ConsentPoll method buildFromRecovery.

@Override
// class names are generated and read from the styx database as trustet source
@SuppressWarnings("squid:S1523")
public WorkableTask buildFromRecovery(JsonObject goal) throws ClassNotFoundException, NoSuchMethodException, IllegalAccessException, InvocationTargetException, InstantiationException {
    String standardPackage = "net.petafuel.styx.core.xs2a.standards" + ("." + goal.getString("standard")) + ("." + goal.getString("version"));
    // TODO use SAD to initialize services based on the bic
    String csServiceClass = standardPackage + ("." + goal.getString("class"));
    String signerClass = standardPackage + ("." + goal.getString("signer"));
    String url = goal.getString("url");
    String consentId = goal.getString("consentId");
    Class<?> clazzCsInterface = Class.forName(csServiceClass);
    Class<?> clazzSigner = Class.forName(signerClass);
    IXS2AHttpSigner signer = (IXS2AHttpSigner) clazzSigner.getDeclaredConstructor().newInstance();
    CSInterface csInterfaceEx = (CSInterface) clazzCsInterface.getDeclaredConstructor(String.class, IXS2AHttpSigner.class).newInstance(url, signer);
    Consent getFromDB = new Consent();
    getFromDB.setId(consentId);
    return new ConsentPoll(new PersistentConsent().get(getFromDB), csInterfaceEx);
}
Also used : IXS2AHttpSigner(net.petafuel.styx.core.xs2a.contracts.IXS2AHttpSigner) PersistentConsent(net.petafuel.styx.core.persistence.layers.PersistentConsent) Consent(net.petafuel.styx.core.xs2a.entities.Consent) CSInterface(net.petafuel.styx.core.xs2a.contracts.CSInterface) PersistentConsent(net.petafuel.styx.core.persistence.layers.PersistentConsent)

Example 2 with IXS2AHttpSigner

use of net.petafuel.styx.core.xs2a.contracts.IXS2AHttpSigner 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;
}
Also used : XS2ARequestClassProvider(net.petafuel.styx.core.xs2a.factory.XS2ARequestClassProvider) XS2AStandard(net.petafuel.styx.core.banklookup.XS2AStandard) AISInterface(net.petafuel.styx.core.xs2a.contracts.AISInterface) PISInterface(net.petafuel.styx.core.xs2a.contracts.PISInterface) InvocationTargetException(java.lang.reflect.InvocationTargetException) IXS2AHttpSigner(net.petafuel.styx.core.xs2a.contracts.IXS2AHttpSigner) Aspsp(net.petafuel.styx.core.banklookup.sad.entities.Aspsp) SADException(net.petafuel.styx.core.xs2a.exceptions.SADException) Version(net.petafuel.styx.core.xs2a.utils.Version) BankLookupFailedException(net.petafuel.styx.core.banklookup.exceptions.BankLookupFailedException) CSInterface(net.petafuel.styx.core.xs2a.contracts.CSInterface) BankNotFoundException(net.petafuel.styx.core.banklookup.exceptions.BankNotFoundException) PIISInterface(net.petafuel.styx.core.xs2a.contracts.PIISInterface)

Aggregations

CSInterface (net.petafuel.styx.core.xs2a.contracts.CSInterface)2 IXS2AHttpSigner (net.petafuel.styx.core.xs2a.contracts.IXS2AHttpSigner)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 XS2AStandard (net.petafuel.styx.core.banklookup.XS2AStandard)1 BankLookupFailedException (net.petafuel.styx.core.banklookup.exceptions.BankLookupFailedException)1 BankNotFoundException (net.petafuel.styx.core.banklookup.exceptions.BankNotFoundException)1 Aspsp (net.petafuel.styx.core.banklookup.sad.entities.Aspsp)1 PersistentConsent (net.petafuel.styx.core.persistence.layers.PersistentConsent)1 AISInterface (net.petafuel.styx.core.xs2a.contracts.AISInterface)1 PIISInterface (net.petafuel.styx.core.xs2a.contracts.PIISInterface)1 PISInterface (net.petafuel.styx.core.xs2a.contracts.PISInterface)1 Consent (net.petafuel.styx.core.xs2a.entities.Consent)1 SADException (net.petafuel.styx.core.xs2a.exceptions.SADException)1 XS2ARequestClassProvider (net.petafuel.styx.core.xs2a.factory.XS2ARequestClassProvider)1 Version (net.petafuel.styx.core.xs2a.utils.Version)1