use of net.petafuel.styx.api.exception.ResponseEntity 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.ResponseEntity in project styx by petafuel.
the class SADResourceTest method GetAspspDataWrongBicTest.
@Test
@Category(IntegrationTest.class)
public void GetAspspDataWrongBicTest() {
Invocation.Builder invocationBuilder = target("/v1/aspsp/" + WRONG_BIC).request();
invocationBuilder.header("token", pisAccessToken);
invocationBuilder.header("Content-Type", "application/json");
Invocation invocation = invocationBuilder.buildGet();
Response response = invocation.invoke(Response.class);
Assertions.assertEquals(409, response.getStatus());
ResponseEntity responseEntity = response.readEntity(ResponseEntity.class);
Assertions.assertEquals("The requested ASPSP was not found within SAD for BIC " + WRONG_BIC, responseEntity.getMessage());
Assertions.assertEquals(ResponseConstant.SAD_ASPSP_NOT_FOUND, responseEntity.getCode());
Assertions.assertEquals(ResponseCategory.ERROR, responseEntity.getCategory());
Assertions.assertEquals(ResponseOrigin.STYX, responseEntity.getOrigin());
}
use of net.petafuel.styx.api.exception.ResponseEntity 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.ResponseEntity 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.ResponseEntity 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);
}
Aggregations