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);
}
}
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());
}
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());
}
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);
}
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());
}
}
Aggregations