use of net.petafuel.styx.core.ioprocessing.IOParser in project styx by petafuel.
the class PreAuthAccessFilter method filter.
/**
* Supressing java:S3776 -> need to rework logic to reduce code complexity
*
* @param containerRequestContext
*/
@Override
@SuppressWarnings("java:S3776")
public void filter(ContainerRequestContext containerRequestContext) {
XS2AStandard xs2AStandard = (XS2AStandard) containerRequestContext.getProperty(XS2AStandard.class.getName());
IOParser ioParser = new IOParser(xs2AStandard.getAspsp());
ImplementerOption ioPreAuthRequired = ioParser.get("IO6");
if (ioPreAuthRequired != null && ioPreAuthRequired.getOptions().get(IOParser.Option.REQUIRED)) {
LOG.info("ASPSP bic={} requires pre-auth", xs2AStandard.getAspsp().getBic());
// preauth is available and required for this bank -> check if preauth id is present
String preAuthIdString = containerRequestContext.getHeaderString(PRE_AUTH_ID);
if (preAuthIdString == null || "".equals(preAuthIdString)) {
throw new StyxException(new ResponseEntity("The requested aspsps requires a pre-step authorisation, preAuthId Header is missing", ResponseConstant.STYX_PREAUTH_HEADER_REQUIRED, ResponseCategory.ERROR, ResponseOrigin.CLIENT));
}
try {
UUID preAuthId = UUID.fromString(preAuthIdString);
OAuthSession oAuthSession = PersistentOAuthSession.getById(preAuthId);
LOG.info("Loaded state={} oauth_session", oAuthSession.getState());
STYX03.setPreauthId(preAuthId);
if (oAuthSession.getAccessToken() == null || oAuthSession.getAccessTokenExpiresAt() == null) {
throw new PersistenceEmptyResultSetException("The access_token data should be set");
}
if (oAuthSession.getAccessTokenExpiresAt().before(new Date())) {
if (oAuthSession.getRefreshTokenExpiresAt().after(new Date())) {
oAuthSession = refreshToken(oAuthSession);
} else {
throw new OAuthTokenExpiredException(OAuthTokenExpiredException.MESSAGE);
}
}
// Add the Authorization: <type> <credentials> header to the request context so we can use it later on demand
Map<String, String> additionalHeaders = new HashMap<>();
additionalHeaders.put(XS2AHeader.AUTHORIZATION, oAuthSession.getTokenType() + " " + oAuthSession.getAccessToken());
containerRequestContext.setProperty(PreAuthAccessFilter.class.getName(), additionalHeaders);
LOG.info("Successfully attached pre-auth from oAuthSessionState={}", oAuthSession.getState());
} catch (PersistenceEmptyResultSetException noOauthSessionFound) {
throw new StyxException(new ResponseEntity("There was no valid pre-step authorisation found for the specified preAuthId", ResponseConstant.STYX_PREAUTH_NOT_AVAILABLE, ResponseCategory.ERROR, ResponseOrigin.CLIENT));
} catch (OAuthTokenExpiredException tokenExpired) {
throw new StyxException(new ResponseEntity(tokenExpired.getMessage(), ResponseConstant.STYX_PREAUTH_EXPIRED, ResponseCategory.ERROR, ResponseOrigin.CLIENT));
}
}
}
use of net.petafuel.styx.core.ioprocessing.IOParser in project styx by petafuel.
the class STYX09IntegrationTest method testStyx09.
@Test
@Category(IntegrationTest.class)
public void testStyx09() throws ImplementerOptionException {
Assume.assumeNotNull(ing);
Assume.assumeNotNull(styx09Option);
styx09Option.setOptions(Collections.singletonMap("required", true));
ing.getConfig().setImplementerOptions(Collections.singletonMap("STYX09", styx09Option));
IOParser ioParser = new IOParser(ing);
STYX09 styx09 = new STYX09(ioParser);
Assertions.assertEquals(IOOrder.POST_CREATION, styx09.order());
XS2ARequest xs2ARequest = new XS2ARequest() {
@Override
public Optional<String> getRawBody() {
return Optional.empty();
}
@Override
public BasicService.RequestType getHttpMethod() {
return BasicService.RequestType.POST;
}
@Override
public String getServicePath() {
return "";
}
};
Assertions.assertTrue(styx09.apply(null, xs2ARequest, null));
Assertions.assertNotNull(xs2ARequest.getHeaders().get(XS2AHeader.AUTHORIZATION));
Assertions.assertNotNull(xs2ARequest.getHeaders().get(INGSigner.ING_CLIENT_ID));
Assertions.assertNotNull(xs2ARequest.getHeaders().get(INGSigner.REQUEST_TARGET));
Assertions.assertEquals(ingClientId, xs2ARequest.getHeaders().get(INGSigner.ING_CLIENT_ID));
Assertions.assertNotEquals("post /oauth2/token", xs2ARequest.getHeaders().get(INGSigner.REQUEST_TARGET));
}
use of net.petafuel.styx.core.ioprocessing.IOParser 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.ioprocessing.IOParser 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.ioprocessing.IOParser 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