use of net.petafuel.styx.core.xs2a.entities.Consent in project styx by petafuel.
the class PersistentConsentIntegrationTest method getConsent.
@Test
@Order(3)
void getConsent() {
Consent fromDatabase = new PersistentConsent().get(consent);
Assert.assertNotNull(fromDatabase.getId());
Assert.assertEquals(ConsentStatus.RECEIVED, fromDatabase.getState());
Assert.assertEquals(SCA.Approach.REDIRECT, fromDatabase.getSca().getApproach());
Assert.assertEquals("PSU-ID-33241", fromDatabase.getPsu().getId());
}
use of net.petafuel.styx.core.xs2a.entities.Consent in project styx by petafuel.
the class PersistentConsentIntegrationTest method setup.
@BeforeAll
public void setup() {
AccountReference IngoZebadich = new AccountReference("DE48500105171271124579", AccountReference.Type.IBAN);
AccountReference MiaDochegal = new AccountReference("4253614013", AccountReference.Type.BBAN);
AccountReference KlaraFall = new AccountReference("AAAPL1234C", AccountReference.Type.PAN);
AccountReference JohannesBeer = new AccountReference("460323255272", AccountReference.Type.MSISDN);
consent = new Consent();
consent.setId(String.valueOf(UUID.randomUUID()));
consent.setState(ConsentStatus.RECEIVED);
consent.getAccess().setTransactions(Arrays.asList(KlaraFall, JohannesBeer));
consent.getAccess().setBalances(Arrays.asList(IngoZebadich, MiaDochegal));
consent.setRecurringIndicator(false);
consent.setFrequencyPerDay(4);
consent.getSca().setApproach(SCA.Approach.REDIRECT);
consent.setCombinedServiceIndicator(false);
PSU psu = new PSU("PSU-ID-33241");
psu.setIdType("PSU-ID-TYPE-33241");
psu.setIp("127.0.0.1");
psu.setPort(9999);
psu.setCorporateIdType("PSU-CO-ID-TYPE-33242");
psu.setCorporateId("PSU-CO-ID-33242");
psu.setGeoLocation("48.3938:11.7331");
psu.setUserAgent("VIMpay 1.2.3");
consent.setPsu(psu);
consent.setxRequestId(UUID.randomUUID());
}
use of net.petafuel.styx.core.xs2a.entities.Consent in project styx by petafuel.
the class PersistentConsentIntegrationTest method updateConsentState.
@Test
@Order(5)
void updateConsentState() {
Consent updatedConsent = new PersistentConsent().updateState(consent, ConsentStatus.TERMINATED_BY_TPP);
Assert.assertEquals(consent.getId(), updatedConsent.getId());
Assert.assertEquals(ConsentStatus.TERMINATED_BY_TPP, updatedConsent.getState());
}
use of net.petafuel.styx.core.xs2a.entities.Consent in project styx by petafuel.
the class PersistentConsent method dbToModel.
/**
* Maps the query ResultSet to a consent model
*
* @param resultSet Result set of a selecting database function
* @return Mapped Consent from the database columns
* @throws SQLException If the expected database column is not available
*/
private Consent dbToModel(ResultSet resultSet) throws SQLException {
Consent consent = new Consent();
consent.setId(resultSet.getString("id"));
try (Jsonb jsonb = JsonbBuilder.create()) {
AccountAccess consentAccess = jsonb.fromJson(resultSet.getString("access"), AccountAccess.class);
consent.setAccess(consentAccess);
} catch (Exception e) {
throw new SerializerException(e.getMessage(), e);
}
consent.setRecurringIndicator(resultSet.getBoolean("recurring_indicator"));
consent.setLastAction(getDateFromTimestamp(resultSet.getTimestamp("last_action")));
consent.setValidUntil(getDateFromTimestamp(resultSet.getTimestamp("valid_until")));
consent.setLastUpdated(getDateFromTimestamp(resultSet.getTimestamp("last_updated")));
consent.setCreatedAt(getDateFromTimestamp(resultSet.getTimestamp("created_at")));
consent.setFrequencyPerDay(resultSet.getInt("frequency_per_day"));
consent.setState(ConsentStatus.getByString(resultSet.getString("state")));
consent.getSca().setApproach(SCA.Approach.valueOf(resultSet.getString("chosen_sca_method")));
consent.setCombinedServiceIndicator(resultSet.getBoolean("combined_service_indicator"));
consent.setxRequestId(UUID.fromString(resultSet.getString("x_request_id")));
PSU psu = new PSU(resultSet.getString("psu_id"));
psu.setIdType(resultSet.getString("psu_id_type"));
psu.setIp(resultSet.getString("psu_ip_address"));
psu.setPort(resultSet.getInt("psu_ip_port"));
psu.setUserAgent(resultSet.getString("psu_user_agent"));
psu.setGeoLocation(resultSet.getString("psu_geo_location"));
psu.setCorporateId(resultSet.getString("psu_corporate_id"));
psu.setCorporateIdType(resultSet.getString("psu_corporate_id_type"));
consent.setPsu(psu);
return consent;
}
use of net.petafuel.styx.core.xs2a.entities.Consent in project styx by petafuel.
the class SCAHandler method decision.
public static SCAApproach decision(StrongAuthenticatableResource strongAuthenticatableResource) {
SCA sca;
SCAApproach scaMethod = null;
String scope;
ServiceRealm serviceRealm;
if (strongAuthenticatableResource instanceof Consent) {
Consent consent = (Consent) strongAuthenticatableResource;
sca = consent.getSca();
scope = "AIS: " + consent.getId();
serviceRealm = ServiceRealm.CONSENT;
} else if (strongAuthenticatableResource instanceof InitiatedPayment) {
InitiatedPayment payment = (InitiatedPayment) strongAuthenticatableResource;
sca = payment.getSca();
scope = "PIS:" + payment.getPaymentId();
serviceRealm = ServiceRealm.PAYMENT;
} else {
return null;
}
switch(sca.getApproach()) {
case DECOUPLED:
break;
case EMBEDDED:
break;
case OAUTH2:
String link;
if (isLinkBuilt(strongAuthenticatableResource.getLinks().getScaOAuth())) {
link = strongAuthenticatableResource.getLinks().getScaOAuth().getUrl();
} else {
OAuthSession session = OAuthService.startSession(strongAuthenticatableResource, scope);
link = OAuthService.buildLink(session.getState(), strongAuthenticatableResource.getxRequestId(), serviceRealm);
}
scaMethod = new OAuth2(link);
break;
case REDIRECT:
scaMethod = new Redirect(strongAuthenticatableResource.getLinks().getScaRedirect().getUrl());
break;
case REQUIRE_AUTHORISATION_RESOURCE:
// Do nothing
break;
default:
throw new InvalidSCAMethodException("Found SCA Method is unsupported");
}
return scaMethod;
}
Aggregations