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