Search in sources :

Example 1 with StrongAuthenticatableResource

use of net.petafuel.styx.core.xs2a.entities.StrongAuthenticatableResource in project styx by petafuel.

the class STYX05 method apply.

@Override
public boolean apply(XS2AFactoryInput xs2AFactoryInput, XS2ARequest xs2ARequest, XS2AResponse xs2AResponse) throws ImplementerOptionException {
    if (xs2AResponse instanceof StrongAuthenticatableResource) {
        Boolean optionRequired = ioParser.getOption(IO, IOParser.Option.REQUIRED);
        if (optionRequired != null && optionRequired) {
            StrongAuthenticatableResource response = (StrongAuthenticatableResource) xs2AResponse;
            String authorizationLink = response.getLinks().getScaRedirect().getUrl();
            OAuthSession oAuthSession = OAuthSession.start(response.getxRequestId());
            oAuthSession.setScope(SCAHandler.getQueryParameterValue(authorizationLink, "scope"));
            oAuthSession.setAuthorizationEndpoint(getBaseUrl(authorizationLink));
            boolean isSandbox = WebServer.isSandbox();
            Aspsp aspsp = ioParser.getAspsp();
            if (isSandbox) {
                oAuthSession.setTokenEndpoint(aspsp.getSandboxUrl().getPreauthTokenEndpoint());
            } else {
                oAuthSession.setTokenEndpoint(aspsp.getProductionUrl().getPreauthTokenEndpoint());
            }
            PersistentOAuthSession.create(oAuthSession);
            String generatedCodeChallenge = OAuthService.getCodeChallengeFromState(oAuthSession.getState());
            String codeChallengePlaceholder = SCAHandler.getQueryParameterValue(authorizationLink, "code_challenge");
            authorizationLink = authorizationLink.replace(codeChallengePlaceholder, generatedCodeChallenge) + "&state=" + oAuthSession.getState();
            response.getLinks().setScaRedirect(new Links.Href(authorizationLink, LinkType.SCA_REDIRECT));
            return true;
        }
    }
    return false;
}
Also used : Aspsp(net.petafuel.styx.core.banklookup.sad.entities.Aspsp) OAuthSession(net.petafuel.styx.core.xs2a.oauth.entities.OAuthSession) PersistentOAuthSession(net.petafuel.styx.core.persistence.layers.PersistentOAuthSession) Links(net.petafuel.styx.core.xs2a.entities.Links) StrongAuthenticatableResource(net.petafuel.styx.core.xs2a.entities.StrongAuthenticatableResource)

Example 2 with StrongAuthenticatableResource

use of net.petafuel.styx.core.xs2a.entities.StrongAuthenticatableResource in project styx by petafuel.

the class STYX03 method apply.

@Override
public boolean apply(XS2AFactoryInput xs2AFactoryInput, XS2ARequest xs2ARequest, XS2AResponse xs2AResponse) throws ImplementerOptionException {
    if (xs2AResponse instanceof StrongAuthenticatableResource) {
        Boolean optionRequired = ioParser.getOption(IO, IOParser.Option.REQUIRED);
        if (optionRequired != null && optionRequired) {
            StrongAuthenticatableResource response = (StrongAuthenticatableResource) xs2AResponse;
            String redirectLink = response.getLinks().getScaRedirect().getUrl();
            OAuthSession oAuthSession = PersistentOAuthSession.getById(STYX03.getPreauthId());
            String codeChallenge = OAuthService.getCodeChallengeFromState(oAuthSession.getState());
            redirectLink = redirectLink.replace("{code_challenge}", codeChallenge);
            response.getLinks().setScaRedirect(new Links.Href(redirectLink, LinkType.SCA_REDIRECT));
            return true;
        }
    }
    return false;
}
Also used : OAuthSession(net.petafuel.styx.core.xs2a.oauth.entities.OAuthSession) PersistentOAuthSession(net.petafuel.styx.core.persistence.layers.PersistentOAuthSession) Links(net.petafuel.styx.core.xs2a.entities.Links) StrongAuthenticatableResource(net.petafuel.styx.core.xs2a.entities.StrongAuthenticatableResource)

Example 3 with StrongAuthenticatableResource

use of net.petafuel.styx.core.xs2a.entities.StrongAuthenticatableResource in project styx by petafuel.

the class STYX07 method apply.

@Override
public boolean apply(XS2AFactoryInput xs2AFactoryInput, XS2ARequest xs2ARequest, XS2AResponse xs2AResponse) throws ImplementerOptionException {
    if (Boolean.FALSE.equals(ioParser.getOption(IO, IOParser.Option.REQUIRED))) {
        return false;
    }
    if (!(xs2AResponse instanceof StrongAuthenticatableResource)) {
        LOG.debug("Not executing, response is not StrongAuthenticatableResource");
        return false;
    }
    StrongAuthenticatableResource scaResource = (StrongAuthenticatableResource) xs2AResponse;
    ThreadManager.getInstance().queueTask(new PaymentStatusPoll(xs2AFactoryInput, ioParser.getAspsp().getBic(), scaResource.getxRequestId()));
    return true;
}
Also used : PaymentStatusPoll(net.petafuel.styx.keepalive.tasks.PaymentStatusPoll) StrongAuthenticatableResource(net.petafuel.styx.core.xs2a.entities.StrongAuthenticatableResource)

Aggregations

StrongAuthenticatableResource (net.petafuel.styx.core.xs2a.entities.StrongAuthenticatableResource)3 PersistentOAuthSession (net.petafuel.styx.core.persistence.layers.PersistentOAuthSession)2 Links (net.petafuel.styx.core.xs2a.entities.Links)2 OAuthSession (net.petafuel.styx.core.xs2a.oauth.entities.OAuthSession)2 Aspsp (net.petafuel.styx.core.banklookup.sad.entities.Aspsp)1 PaymentStatusPoll (net.petafuel.styx.keepalive.tasks.PaymentStatusPoll)1