use of net.petafuel.styx.core.xs2a.exceptions.InvalidSCAMethodException 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