Search in sources :

Example 1 with PSU

use of net.petafuel.styx.core.xs2a.entities.PSU in project styx by petafuel.

the class PSUFilter method filter.

@Override
public void filter(ContainerRequestContext containerRequestContext) {
    String id = containerRequestContext.getHeaderString(XS2AHeader.PSU_ID);
    if (id == null || "".equals(id)) {
        throw new StyxException(new ResponseEntity("PSU-ID is not provided or empty", ResponseConstant.BAD_REQUEST, ResponseCategory.ERROR, ResponseOrigin.CLIENT));
    }
    PSU psu = new PSU(id);
    psu.setIdType(containerRequestContext.getHeaderString(XS2AHeader.PSU_ID_TYPE));
    psu.setCorporateId(containerRequestContext.getHeaderString(XS2AHeader.PSU_CORPORATE_ID));
    psu.setCorporateIdType(containerRequestContext.getHeaderString(XS2AHeader.PSU_CORPORATE_ID_TYPE));
    if (Boolean.getBoolean(ApiProperties.STYX_PROXY_ENABLED)) {
        String forwardedIps = containerRequestContext.getHeaderString(XS2AHeader.X_FORWARDED_FOR);
        psu.setIp(Sanitizer.parseClientIpFromForwardedIPs(forwardedIps));
    } else {
        psu.setIp(httpServletRequest.getRemoteAddr());
    }
    String psuPort = containerRequestContext.getHeaderString(XS2AHeader.PSU_IP_PORT);
    try {
        Integer intVal = psuPort != null ? Integer.valueOf(psuPort) : null;
        psu.setPort(intVal);
    } catch (NumberFormatException invalidDataType) {
        LOG.warn("PSU-PORT header was bigger than integer MAX_VALUE, not accepting header value");
    }
    psu.setUserAgent(containerRequestContext.getHeaderString(XS2AHeader.PSU_USER_AGENT));
    psu.setGeoLocation(containerRequestContext.getHeaderString(XS2AHeader.PSU_GEO_LOCATION));
    containerRequestContext.setProperty(PSU.class.getName(), psu);
}
Also used : ResponseEntity(net.petafuel.styx.api.exception.ResponseEntity) RequiresPSU(net.petafuel.styx.api.filter.input.boundary.RequiresPSU) PSU(net.petafuel.styx.core.xs2a.entities.PSU) StyxException(net.petafuel.styx.api.exception.StyxException)

Example 2 with PSU

use of net.petafuel.styx.core.xs2a.entities.PSU in project styx by petafuel.

the class STYX02 method apply.

@Override
public boolean apply(XS2AFactoryInput ioInput, XS2ARequest xs2ARequest, XS2AResponse xs2AResponse) throws ImplementerOptionException {
    if (Boolean.FALSE.equals(ioParser.getOption("IO6", IOParser.Option.REQUIRED)) || Boolean.FALSE.equals(ioParser.getOption(IO, IOParser.Option.REQUIRED))) {
        // do not apply if not required
        return false;
    }
    // check if ais or pis
    // extract PSU-ID from authorisation header
    // set the extracted psu id to the current psu within the xs2a request
    // override the iocontainer request with the modified request
    String psuId = extractPsuId(xs2ARequest.getHeaders().get(XS2AHeader.AUTHORIZATION));
    if (psuId == null) {
        throw new ImplementerOptionException("Unable to extract psu id from access token");
    }
    if (ioInput.getPsu() != null) {
        xs2ARequest.setPsu(ioInput.getPsu());
    } else {
        xs2ARequest.setPsu(new PSU());
    }
    xs2ARequest.getPsu().setId(psuId);
    return true;
}
Also used : PSU(net.petafuel.styx.core.xs2a.entities.PSU) ImplementerOptionException(net.petafuel.styx.core.ioprocessing.ImplementerOptionException)

Example 3 with PSU

use of net.petafuel.styx.core.xs2a.entities.PSU in project styx by petafuel.

the class STYX10UnitTest method test_STYX10_with_uk_bank.

@Test
void test_STYX10_with_uk_bank() throws ImplementerOptionException {
    uniCredit.setBic(TEST_BIC_UK);
    Assume.assumeNotNull(uniCredit);
    Assume.assumeNotNull(styx10Option);
    styx10Option.setOptions(Collections.singletonMap("required", true));
    uniCredit.getConfig().setImplementerOptions(Collections.singletonMap("STYX10", styx10Option));
    IOParser ioParser = new IOParser(uniCredit);
    STYX10 styx10 = new STYX10(ioParser);
    Assertions.assertEquals(IOOrder.POST_CREATION, styx10.order());
    Assertions.assertFalse(styx10.apply(null, null, null));
    XS2ARequest xs2ARequest = new XS2ARequest() {

        @Override
        public Optional<String> getRawBody() {
            return Optional.empty();
        }

        @Override
        public BasicService.RequestType getHttpMethod() {
            return BasicService.RequestType.GET;
        }

        @Override
        public String getServicePath() {
            return "";
        }
    };
    PSU psu = new PSU("bgdemo");
    XS2AFactoryInput xs2AFactoryInput = new XS2AFactoryInput();
    xs2AFactoryInput.setPsu(psu);
    Assertions.assertFalse(styx10.apply(xs2AFactoryInput, xs2ARequest, null));
}
Also used : BasicService(net.petafuel.styx.core.xs2a.contracts.BasicService) PSU(net.petafuel.styx.core.xs2a.entities.PSU) IOParser(net.petafuel.styx.core.ioprocessing.IOParser) XS2AFactoryInput(net.petafuel.styx.core.xs2a.factory.XS2AFactoryInput) XS2ARequest(net.petafuel.styx.core.xs2a.contracts.XS2ARequest) Test(org.junit.jupiter.api.Test)

Example 4 with PSU

use of net.petafuel.styx.core.xs2a.entities.PSU in project styx by petafuel.

the class STYX10UnitTest method test_STYX10_with_invalid_bic.

@Test
void test_STYX10_with_invalid_bic() throws ImplementerOptionException {
    uniCredit.setBic(TEST_BIC_INVALID);
    Assume.assumeNotNull(uniCredit);
    Assume.assumeNotNull(styx10Option);
    styx10Option.setOptions(Collections.singletonMap("required", true));
    uniCredit.getConfig().setImplementerOptions(Collections.singletonMap("STYX10", styx10Option));
    IOParser ioParser = new IOParser(uniCredit);
    STYX10 styx10 = new STYX10(ioParser);
    Assertions.assertEquals(IOOrder.POST_CREATION, styx10.order());
    Assertions.assertFalse(styx10.apply(null, null, null));
    XS2ARequest xs2ARequest = new XS2ARequest() {

        @Override
        public Optional<String> getRawBody() {
            return Optional.empty();
        }

        @Override
        public BasicService.RequestType getHttpMethod() {
            return BasicService.RequestType.GET;
        }

        @Override
        public String getServicePath() {
            return "";
        }
    };
    PSU psu = new PSU("bgdemo");
    XS2AFactoryInput xs2AFactoryInput = new XS2AFactoryInput();
    xs2AFactoryInput.setPsu(psu);
    Assertions.assertThrows(ImplementerOptionException.class, () -> styx10.apply(xs2AFactoryInput, xs2ARequest, null));
}
Also used : BasicService(net.petafuel.styx.core.xs2a.contracts.BasicService) PSU(net.petafuel.styx.core.xs2a.entities.PSU) IOParser(net.petafuel.styx.core.ioprocessing.IOParser) XS2AFactoryInput(net.petafuel.styx.core.xs2a.factory.XS2AFactoryInput) XS2ARequest(net.petafuel.styx.core.xs2a.contracts.XS2ARequest) Test(org.junit.jupiter.api.Test)

Example 5 with PSU

use of net.petafuel.styx.core.xs2a.entities.PSU in project styx by petafuel.

the class STYX10UnitTest method test_STYX10_with_german_bank.

@Test
void test_STYX10_with_german_bank() throws ImplementerOptionException {
    uniCredit.setBic(TEST_BIC_DE);
    Assume.assumeNotNull(uniCredit);
    Assume.assumeNotNull(styx10Option);
    styx10Option.setOptions(Collections.singletonMap("required", true));
    uniCredit.getConfig().setImplementerOptions(Collections.singletonMap("STYX10", styx10Option));
    IOParser ioParser = new IOParser(uniCredit);
    STYX10 styx10 = new STYX10(ioParser);
    Assertions.assertEquals(IOOrder.POST_CREATION, styx10.order());
    Assertions.assertFalse(styx10.apply(null, null, null));
    XS2ARequest xs2ARequest = new XS2ARequest() {

        @Override
        public Optional<String> getRawBody() {
            return Optional.empty();
        }

        @Override
        public BasicService.RequestType getHttpMethod() {
            return BasicService.RequestType.GET;
        }

        @Override
        public String getServicePath() {
            return "";
        }
    };
    PSU psu = new PSU("bgdemo");
    XS2AFactoryInput xs2AFactoryInput = new XS2AFactoryInput();
    xs2AFactoryInput.setPsu(psu);
    Assertions.assertTrue(styx10.apply(xs2AFactoryInput, xs2ARequest, null));
    Assertions.assertNotNull(xs2ARequest.getHeaders().get(XS2AHeader.PSU_ID_TYPE));
    Assertions.assertEquals("HVB_ONLINEBANKING", xs2ARequest.getHeaders().get(XS2AHeader.PSU_ID_TYPE));
}
Also used : BasicService(net.petafuel.styx.core.xs2a.contracts.BasicService) PSU(net.petafuel.styx.core.xs2a.entities.PSU) IOParser(net.petafuel.styx.core.ioprocessing.IOParser) XS2AFactoryInput(net.petafuel.styx.core.xs2a.factory.XS2AFactoryInput) XS2ARequest(net.petafuel.styx.core.xs2a.contracts.XS2ARequest) Test(org.junit.jupiter.api.Test)

Aggregations

PSU (net.petafuel.styx.core.xs2a.entities.PSU)10 XS2AFactoryInput (net.petafuel.styx.core.xs2a.factory.XS2AFactoryInput)6 IOParser (net.petafuel.styx.core.ioprocessing.IOParser)5 BasicService (net.petafuel.styx.core.xs2a.contracts.BasicService)5 XS2ARequest (net.petafuel.styx.core.xs2a.contracts.XS2ARequest)5 Test (org.junit.jupiter.api.Test)5 Consent (net.petafuel.styx.core.xs2a.entities.Consent)2 SQLException (java.sql.SQLException)1 Jsonb (javax.json.bind.Jsonb)1 ResponseEntity (net.petafuel.styx.api.exception.ResponseEntity)1 StyxException (net.petafuel.styx.api.exception.StyxException)1 RequiresPSU (net.petafuel.styx.api.filter.input.boundary.RequiresPSU)1 ImplementerOptionException (net.petafuel.styx.core.ioprocessing.ImplementerOptionException)1 PersistenceException (net.petafuel.styx.core.persistence.PersistenceException)1 PersistentConsent (net.petafuel.styx.core.persistence.layers.PersistentConsent)1 AccountAccess (net.petafuel.styx.core.xs2a.entities.AccountAccess)1 AccountReference (net.petafuel.styx.core.xs2a.entities.AccountReference)1 SerializerException (net.petafuel.styx.core.xs2a.exceptions.SerializerException)1 BeforeAll (org.junit.jupiter.api.BeforeAll)1