use of net.petafuel.styx.core.ioprocessing.ImplementerOptionException in project styx by petafuel.
the class STYX02 method extractPsuId.
public String extractPsuId(String authroisationHeader) throws ImplementerOptionException {
String[] jwtParts = authroisationHeader != null ? authroisationHeader.split("\\.") : null;
if (jwtParts == null || jwtParts.length < 2) {
throw new ImplementerOptionException("Error parsing pre-auth access token to JWT");
}
String decoded = new String(Base64.getDecoder().decode(jwtParts[1]));
try (Jsonb jsonb = JsonbBuilder.create()) {
JsonObject jwtPayload = jsonb.fromJson(decoded, JsonObject.class);
return jwtPayload.getString("sub", null);
} catch (Exception e) {
throw new ImplementerOptionException("Error extracting sub field from JWT Access Token for pre-step authentication", e);
}
}
use of net.petafuel.styx.core.ioprocessing.ImplementerOptionException 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.ioprocessing.ImplementerOptionException in project styx by petafuel.
the class SpardaPreauthParseTest method testJWTParsing.
@Test
void testJWTParsing() throws ImplementerOptionException {
// Prepare initialized objects
String authroisationHeader = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiJTVFlYVGVzdDtQU0QyO1hTMkE7c29tZWlkIiwibmFtZSI6Ikx1bGFkb3IiLCJpYXQiOjE1MTYyMzkwMjJ9.opDGt6XzgWE7Hrwy4TBWZlhDWVYhhYFOBv-1wFu8cAQ";
String[] jwtParts = authroisationHeader.split("\\.");
if (jwtParts.length < 2) {
throw new ImplementerOptionException("Error parsing pre-auth access token to JWT");
}
String decoded = new String(Base64.getDecoder().decode(jwtParts[1]));
try (Jsonb jsonb = JsonbBuilder.create()) {
javax.json.JsonObject jwtPayload = jsonb.fromJson(decoded, JsonObject.class);
Assertions.assertNotNull(jwtPayload.getString("sub", null));
} catch (Exception e) {
throw new ImplementerOptionException("Error extracting sub field from JWT Access Token for pre-step authentication", e);
}
}
Aggregations