use of net.petafuel.styx.api.exception.StyxException in project styx by petafuel.
the class STYX09 method generateINGAccessToken.
public void generateINGAccessToken(String url) {
AccessTokenService service = new AccessTokenService();
AccessTokenRequest request = new AccessTokenRequest();
try {
AccessToken retrievedAccessToken = service.tokenRequest(url + "/oauth2/token", request);
// give a tolerance of 30 seconds to the expiry date in case of any software
// related delays
this.accessTokenValidUntil = Instant.now().plusSeconds((retrievedAccessToken.getExpiresIn() - 30));
this.accessToken = retrievedAccessToken;
} catch (BankRequestFailedException e) {
LOG.error("Error getting ing access token:", e);
ResponseEntity responseEntity = new ResponseEntity("Generating ING access token failed", ResponseConstant.INTERNAL_SERVER_ERROR, ResponseCategory.ERROR, ResponseOrigin.STYX);
throw new StyxException(responseEntity);
}
}
use of net.petafuel.styx.api.exception.StyxException in project styx by petafuel.
the class AccessTokenFilterUnitTest method testMasterTokenInvalidConfiguration.
@Test
void testMasterTokenInvalidConfiguration() {
MasterToken masterToken = prepareMasterToken("pis", null);
AccessTokenFilter accessTokenFilter = new AccessTokenFilter();
Assertions.assertThrows(StyxException.class, () -> accessTokenFilter.checkRestrictions(masterToken, "pis"));
try {
accessTokenFilter.checkRestrictions(masterToken, "pis");
} catch (StyxException exception) {
ResponseEntity response = exception.getResponseEntity();
Assertions.assertEquals(ResponseConstant.STYX_MASTER_TOKEN_RESTRICTED.getReasonPhrase(), response.getMessage());
Assertions.assertEquals(ResponseConstant.STYX_MASTER_TOKEN_RESTRICTED.getStatusCode(), response.getCode().getStatusCode());
Assertions.assertEquals(ResponseCategory.ERROR, response.getCategory());
Assertions.assertEquals(ResponseOrigin.STYX, response.getOrigin());
}
}
use of net.petafuel.styx.api.exception.StyxException in project styx by petafuel.
the class AccessTokenFilterUnitTest method testCheckMaxUsagesReached.
@Test
void testCheckMaxUsagesReached() {
AccessToken accessToken = new AccessToken();
accessToken.setServiceType("ais");
MasterToken masterToken = prepareMasterToken("ais", 2);
AccessTokenFilter accessTokenFilter = new AccessTokenFilter();
accessToken.setUsages(2);
Assertions.assertThrows(StyxException.class, () -> accessTokenFilter.checkMaxUsages(masterToken, accessToken));
try {
accessTokenFilter.checkMaxUsages(masterToken, accessToken);
} catch (StyxException exception) {
ResponseEntity response = exception.getResponseEntity();
Assertions.assertEquals(ResponseConstant.STYX_TOKEN_ACCESS_EXEEDED.getReasonPhrase(), response.getMessage());
Assertions.assertEquals(ResponseConstant.STYX_TOKEN_ACCESS_EXEEDED.getStatusCode(), response.getCode().getStatusCode());
Assertions.assertEquals(ResponseCategory.ERROR, response.getCategory());
Assertions.assertEquals(ResponseOrigin.CLIENT, response.getOrigin());
}
}
use of net.petafuel.styx.api.exception.StyxException in project styx by petafuel.
the class AbstractTokenFilter method filter.
@Override
public void filter(ContainerRequestContext context) {
String token = context.getHeaderString("token");
if (token == null || "".equals(token)) {
ResponseEntity responseEntity = new ResponseEntity(ResponseConstant.STYX_MISSING_CLIENT_TOKEN, ResponseCategory.ERROR, ResponseOrigin.CLIENT);
throw new StyxException(responseEntity);
}
// token is hashed, constant length of 64 characters
if (token.length() != 64) {
ResponseEntity responseEntity = new ResponseEntity(ResponseConstant.STYX_INVALID_TOKEN_FORMAT, ResponseCategory.ERROR, ResponseOrigin.CLIENT);
throw new StyxException(responseEntity);
}
String tokenHash;
try {
tokenHash = TokenGenerator.hashSHA256(token);
} catch (NoSuchAlgorithmException e) {
LOG.error("plainToken could not be hashed error={}", e.getMessage());
ResponseEntity responseEntity = new ResponseEntity(ResponseConstant.STYX_INVALID_TOKEN_FORMAT, ResponseCategory.ERROR, ResponseOrigin.CLIENT);
throw new StyxException(responseEntity);
}
boolean tokenValid = checkToken(tokenHash);
if (!tokenValid) {
ResponseEntity responseEntity = new ResponseEntity(ResponseConstant.STYX_TOKEN_EXPIRED_OR_REVOKED, ResponseCategory.ERROR, ResponseOrigin.CLIENT);
throw new StyxException(responseEntity);
}
context.setProperty(AbstractTokenFilter.class.getName(), tokenHash);
}
use of net.petafuel.styx.api.exception.StyxException 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);
}
Aggregations