Search in sources :

Example 1 with ServiceRealm

use of net.petafuel.styx.core.xs2a.callback.entity.ServiceRealm in project styx by petafuel.

the class CallbackHandler method handleCallback.

public static Response handleCallback(String serviceRealm, String realmParameter, String xRequestId, OAuthCallback oAuthCallback) {
    ServiceRealm requestedServiceRealm;
    RealmParameter receivedRealmParameter;
    RedirectStatus redirectStatus = null;
    try {
        requestedServiceRealm = ServiceRealm.valueOf(serviceRealm.toUpperCase());
    } catch (IllegalArgumentException unknownRealmException) {
        LOG.warn("Callback was received with an unknown serviceRealm={}", serviceRealm);
        requestedServiceRealm = ServiceRealm.UNKNOWN;
    }
    try {
        receivedRealmParameter = RealmParameter.valueOf(realmParameter.toUpperCase());
    } catch (IllegalArgumentException unknownRealmException) {
        LOG.warn("Callback was received with an unknown realmParameter={}", realmParameter);
        receivedRealmParameter = RealmParameter.UNKNOWN;
    }
    LOG.info("Received callback for resource serviceRealm={}, realmParameter={}, originRequestUUID={}, oAuthCallback={}", requestedServiceRealm, realmParameter, xRequestId, oAuthCallback);
    if (oAuthCallback != null && (oAuthCallback.getCode() != null || oAuthCallback.getError() != null)) {
        redirectStatus = OAuthCallbackProcessor.processCallback(requestedServiceRealm, receivedRealmParameter, xRequestId, oAuthCallback);
    }
    if (redirectStatus == null) {
        redirectStatus = RedirectCallbackProcessor.processCallback(requestedServiceRealm, receivedRealmParameter, xRequestId);
    }
    return StatusHelper.createStatusRedirection(redirectStatus);
}
Also used : RedirectStatus(net.petafuel.styx.api.v1.status.entity.RedirectStatus) RealmParameter(net.petafuel.styx.core.xs2a.callback.entity.RealmParameter) ServiceRealm(net.petafuel.styx.core.xs2a.callback.entity.ServiceRealm)

Example 2 with ServiceRealm

use of net.petafuel.styx.core.xs2a.callback.entity.ServiceRealm 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;
}
Also used : SCA(net.petafuel.styx.core.xs2a.entities.SCA) InvalidSCAMethodException(net.petafuel.styx.core.xs2a.exceptions.InvalidSCAMethodException) Consent(net.petafuel.styx.core.xs2a.entities.Consent) OAuthSession(net.petafuel.styx.core.xs2a.oauth.entities.OAuthSession) InitiatedPayment(net.petafuel.styx.core.xs2a.entities.InitiatedPayment) ServiceRealm(net.petafuel.styx.core.xs2a.callback.entity.ServiceRealm)

Aggregations

ServiceRealm (net.petafuel.styx.core.xs2a.callback.entity.ServiceRealm)2 RedirectStatus (net.petafuel.styx.api.v1.status.entity.RedirectStatus)1 RealmParameter (net.petafuel.styx.core.xs2a.callback.entity.RealmParameter)1 Consent (net.petafuel.styx.core.xs2a.entities.Consent)1 InitiatedPayment (net.petafuel.styx.core.xs2a.entities.InitiatedPayment)1 SCA (net.petafuel.styx.core.xs2a.entities.SCA)1 InvalidSCAMethodException (net.petafuel.styx.core.xs2a.exceptions.InvalidSCAMethodException)1 OAuthSession (net.petafuel.styx.core.xs2a.oauth.entities.OAuthSession)1