Search in sources :

Example 1 with RedirectStatus

use of net.petafuel.styx.api.v1.status.entity.RedirectStatus in project styx by petafuel.

the class OAuthCallbackProcessor method handlePreStepOAuth2.

/**
 * Legacy method to handle pre-step authentication for Sparda, might be deprecated in the future
 *
 * @param code         received from the bank
 * @param state        received from the bank - matches in styx database
 * @param error        received from the bank on error
 * @param errorMessage received from the bank on error
 * @param path         to be used as redirect url to styx
 * @return returns a jaxrs response object to be returned to a client
 */
public static Response handlePreStepOAuth2(String code, String state, String error, String errorMessage, String path) {
    OAuthSession oAuthSession = new OAuthSession();
    try {
        oAuthSession = PersistentOAuthSession.getByState(state);
    } catch (PersistenceEmptyResultSetException oauthSessionNotFound) {
        LOG.warn("Error retrieving oAuthSession within prestep callback error={}", oauthSessionNotFound.getMessage());
        error += " " + STYX_PREAUTH_NOT_AVAILABLE.name();
    }
    if (error == null && handleSuccessfulOAuth2(code, state, path)) {
        RedirectStatus redirectStatus = new RedirectStatus(StatusType.SUCCESS, oAuthSession.getState(), RedirectStep.PREAUTH);
        return StatusHelper.createStatusRedirection(redirectStatus);
    } else {
        LOG.error(FAILED_OAUTH2, error, errorMessage, state);
        RedirectStatus redirectStatus = new RedirectStatus(StatusType.ERROR, oAuthSession.getState(), RedirectStep.PREAUTH);
        return StatusHelper.createStatusRedirection(redirectStatus);
    }
}
Also used : RedirectStatus(net.petafuel.styx.api.v1.status.entity.RedirectStatus) PersistentOAuthSession(net.petafuel.styx.core.persistence.layers.PersistentOAuthSession) OAuthSession(net.petafuel.styx.core.xs2a.oauth.entities.OAuthSession) PersistenceEmptyResultSetException(net.petafuel.styx.core.persistence.PersistenceEmptyResultSetException)

Example 2 with RedirectStatus

use of net.petafuel.styx.api.v1.status.entity.RedirectStatus in project styx by petafuel.

the class OAuthCallbackProcessorUnitTest method testPaymentResourceRealm_SCACallback_Ok.

@ParameterizedTest
@ArgumentsSource(OAuthCallbackProcessorUnitTest.CallbackTestDataProvider.class)
void testPaymentResourceRealm_SCACallback_Ok(ServiceRealm serviceRealm, RealmParameter realmParameter, String identifer, OAuthCallback oAuthCallback, StatusType expected) {
    RedirectStatus redirectStatus = OAuthCallbackProcessor.processCallback(serviceRealm, realmParameter, identifer, oAuthCallback);
    Assertions.assertEquals(expected, redirectStatus.getStatusType());
}
Also used : RedirectStatus(net.petafuel.styx.api.v1.status.entity.RedirectStatus) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) ArgumentsSource(org.junit.jupiter.params.provider.ArgumentsSource)

Example 3 with RedirectStatus

use of net.petafuel.styx.api.v1.status.entity.RedirectStatus in project styx by petafuel.

the class RedirectProcessorUnitTest method testPaymentResourceRealm_SCACallback_Ok.

@ParameterizedTest
@ArgumentsSource(CallbackTestDataProvider.class)
void testPaymentResourceRealm_SCACallback_Ok(ServiceRealm serviceRealm, RealmParameter realmParameter, String identifer, StatusType expected) {
    RedirectStatus redirectStatus = RedirectCallbackProcessor.processCallback(serviceRealm, realmParameter, identifer);
    Assertions.assertEquals(expected, redirectStatus.getStatusType());
}
Also used : RedirectStatus(net.petafuel.styx.api.v1.status.entity.RedirectStatus) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) ArgumentsSource(org.junit.jupiter.params.provider.ArgumentsSource)

Example 4 with RedirectStatus

use of net.petafuel.styx.api.v1.status.entity.RedirectStatus 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 5 with RedirectStatus

use of net.petafuel.styx.api.v1.status.entity.RedirectStatus in project styx by petafuel.

the class OAuthCallbackProcessor method handlePaymentRealm.

private static RedirectStatus handlePaymentRealm(ServiceRealm serviceRealm, RealmParameter realmParameter, String identifier, OAuthCallback oAuthCallback) {
    String path = String.format("%s/%s/%s", serviceRealm.name().toLowerCase(), realmParameter.name().toLowerCase(), identifier);
    if (oAuthCallback.getError() == null && handleSuccessfulOAuth2(oAuthCallback.getCode(), oAuthCallback.getState(), path)) {
        PaymentEntry paymentEntry = PersistentPayment.getById(identifier);
        XS2AStandard xs2AStandard;
        try {
            xs2AStandard = (new SAD()).getBankByBIC(paymentEntry.getBic());
        } catch (BankNotFoundException | BankLookupFailedException e) {
            LOG.error("OAuth Callback on serviceRealm={}, identifier={}, realmParameter={} failed due to SAD not being able to initialize the aspsp connected to the payment SCA", serviceRealm, identifier, realmParameter, e);
            return new RedirectStatus(StatusType.ERROR, identifier);
        }
        // In case of oauth we will not schedule the task during payment initiation but here after we received a callback
        XS2AFactoryInput xs2AFactoryInput = new XS2AFactoryInput();
        xs2AFactoryInput.setPaymentId(paymentEntry.getPaymentId());
        xs2AFactoryInput.setPaymentService(paymentEntry.getPaymentService());
        xs2AFactoryInput.setPaymentProduct(paymentEntry.getPaymentProduct());
        ThreadManager.getInstance().queueTask(new PaymentStatusPoll(xs2AFactoryInput, xs2AStandard.getAspsp().getBic(), UUID.fromString(paymentEntry.getId())));
        return new RedirectStatus(StatusType.SUCCESS, oAuthCallback.getState());
    } else {
        LOG.error(FAILED_OAUTH2, oAuthCallback.getError(), oAuthCallback.getErrorDescription(), oAuthCallback.getState());
        return new RedirectStatus(StatusType.ERROR, oAuthCallback.getState());
    }
}
Also used : XS2AStandard(net.petafuel.styx.core.banklookup.XS2AStandard) RedirectStatus(net.petafuel.styx.api.v1.status.entity.RedirectStatus) PaymentEntry(net.petafuel.styx.core.persistence.models.PaymentEntry) SAD(net.petafuel.styx.core.banklookup.sad.SAD) XS2AFactoryInput(net.petafuel.styx.core.xs2a.factory.XS2AFactoryInput) PaymentStatusPoll(net.petafuel.styx.keepalive.tasks.PaymentStatusPoll) BankLookupFailedException(net.petafuel.styx.core.banklookup.exceptions.BankLookupFailedException) BankNotFoundException(net.petafuel.styx.core.banklookup.exceptions.BankNotFoundException)

Aggregations

RedirectStatus (net.petafuel.styx.api.v1.status.entity.RedirectStatus)5 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)2 ArgumentsSource (org.junit.jupiter.params.provider.ArgumentsSource)2 XS2AStandard (net.petafuel.styx.core.banklookup.XS2AStandard)1 BankLookupFailedException (net.petafuel.styx.core.banklookup.exceptions.BankLookupFailedException)1 BankNotFoundException (net.petafuel.styx.core.banklookup.exceptions.BankNotFoundException)1 SAD (net.petafuel.styx.core.banklookup.sad.SAD)1 PersistenceEmptyResultSetException (net.petafuel.styx.core.persistence.PersistenceEmptyResultSetException)1 PersistentOAuthSession (net.petafuel.styx.core.persistence.layers.PersistentOAuthSession)1 PaymentEntry (net.petafuel.styx.core.persistence.models.PaymentEntry)1 RealmParameter (net.petafuel.styx.core.xs2a.callback.entity.RealmParameter)1 ServiceRealm (net.petafuel.styx.core.xs2a.callback.entity.ServiceRealm)1 XS2AFactoryInput (net.petafuel.styx.core.xs2a.factory.XS2AFactoryInput)1 OAuthSession (net.petafuel.styx.core.xs2a.oauth.entities.OAuthSession)1 PaymentStatusPoll (net.petafuel.styx.keepalive.tasks.PaymentStatusPoll)1