Search in sources :

Example 1 with Links

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

the class AspspUrlMapper method map.

// Links need to be adapted depening on multiple cases
@SuppressWarnings("squid:S3776")
public Links map(Links links) {
    if (!Boolean.parseBoolean(System.getProperty(ApiProperties.STYX_PROXY_ENABLED))) {
        return links;
    }
    if (links == null) {
        // If the aspsp did not deliver any links within the HAL protocol create a new links object so we can at least add self and status
        links = new Links();
    }
    // copy object for lambda expression
    Links finalLinks = links;
    finalLinks.getUrlMapping().entrySet().parallelStream().forEach(entry -> {
        String route = null;
        switch(entry.getKey()) {
            case AUTHORISATION_WITH_PSU_IDENTIFICATION:
            case AUTHORISATION_WITH_PSU_AUTHENTICATION:
            case AUTHORISATION_WITH_ENCRYPTED_PSU_AUTHENTICATION:
            case AUTHORISATION_WITH_METHOD_SELECTION:
                if (isPIS) {
                    route = String.format(PIS_CREATE_OR_GET_AUTHORISATION, paymentService.getValue(), paymentProduct.getValue(), paymentId);
                } else {
                    route = String.format(CS_CREATE_OR_GET_AUTHORISATION, consentId);
                }
                break;
            case UPDATE_PSU_IDENTIFICATION:
            case UPDATE_PSU_AUTHENTICATION:
            case UPDATE_ENCRYPTED_PSU_AUTHENTICATION:
            case UPDATE_ADDITIONAL_PSU_AUTHENTICATION:
            case UPDATE_ENCRYPTED_ADDITIONAL_PSU_AUTHENTICATION:
            case SELECT_AUTHENTICATION_METHOD:
            case AUTHORISE_TRANSACTION:
            case SCA_STATUS:
                if (authorisationId == null || Objects.equals(authorisationId, "")) {
                    authorisationId = extractAuthorisationId(finalLinks);
                }
                if (isPIS) {
                    route = String.format(PIS_UPDATE_AUTHORISATION, paymentService.getValue(), paymentProduct.getValue(), paymentId, authorisationId);
                } else {
                    route = String.format(CS_UPDATE_AUTHORISATION, consentId, authorisationId);
                }
                break;
            case BALANCES:
                route = String.format(AIS_GET_BALANCES, accountId);
                break;
            case TRANSACTIONS:
                route = String.format(AIS_GET_TRANSACTIONS, accountId);
                break;
            default:
                // Keep url as is
                break;
        }
        Optional<URL> styxWrapperUrl = getMappedURL(route);
        styxWrapperUrl.ifPresent(presentValue -> entry.getValue().setUrl(presentValue.toString()));
    });
    // Always add Status and Self links
    String getStatus = null;
    String getSelf = null;
    if (isPIS) {
        getStatus = String.format(PIS_GET_STATUS, paymentService.getValue(), paymentProduct.getValue(), paymentId);
        getSelf = String.format(PIS_GET_SELF, paymentService.getValue(), paymentProduct.getValue(), paymentId);
    } else if (consentId != null) {
        getStatus = String.format(CS_GET_STATUS, consentId);
        getSelf = String.format(CS_GET_SELF, consentId);
    }
    Optional<URL> styxWrapperUrlStatus = getMappedURL(getStatus);
    Optional<URL> styxWrapperUrlSelf = getMappedURL(getSelf);
    styxWrapperUrlStatus.ifPresent(presentValue -> finalLinks.setStatus(new Links.Href(presentValue.toString(), LinkType.STATUS)));
    styxWrapperUrlSelf.ifPresent(presentValue -> finalLinks.setSelf(new Links.Href(presentValue.toString(), LinkType.SELF)));
    return finalLinks;
}
Also used : Links(net.petafuel.styx.core.xs2a.entities.Links) URL(java.net.URL)

Example 2 with Links

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

the class PreAuthResource method preAuthenticate.

/**
 * Starts an OAuth sessions and returns the preauthId and the link to the authorization page
 * Relevant only for ASPSPs which support/require a preauth in order to access their XS2A interface
 *
 * @return 200 if successful
 */
@RequiresBIC
@CheckAccessToken(allowedServices = { XS2ATokenType.AIS, XS2ATokenType.PIS, XS2ATokenType.AISPIS, XS2ATokenType.PIIS })
@POST
@Path("/preauth")
public Response preAuthenticate(@NotEmpty @NotBlank @HeaderParam("scope") String scope) {
    Url url;
    if (Boolean.TRUE.equals(WebServer.isSandbox())) {
        url = getXS2AStandard().getAspsp().getSandboxUrl();
    } else {
        url = getXS2AStandard().getAspsp().getProductionUrl();
    }
    OAuthSession oAuthSession = OAuthService.startPreAuthSession(url, scope);
    String state = oAuthSession.getState();
    String link = OAuthService.buildLink(state, getXS2AStandard().getAspsp().getBic());
    Links links = new Links();
    links.setAuthorizationEndpoint(new Links.Href(link, LinkType.AUTHORIZATION_ENDPOINT));
    PreAuthResponse response = new PreAuthResponse(oAuthSession.getId().toString(), links);
    LOG.info("Successfully started pre-step Authentication within OAuthSession state={}", state);
    return Response.status(ResponseConstant.OK).entity(response).build();
}
Also used : PreAuthResponse(net.petafuel.styx.api.v1.preauth.entity.PreAuthResponse) PersistentOAuthSession(net.petafuel.styx.core.persistence.layers.PersistentOAuthSession) OAuthSession(net.petafuel.styx.core.xs2a.oauth.entities.OAuthSession) Links(net.petafuel.styx.core.xs2a.entities.Links) Url(net.petafuel.styx.core.banklookup.sad.entities.Url) Path(javax.ws.rs.Path) ApplicationPath(javax.ws.rs.ApplicationPath) CheckAccessToken(net.petafuel.styx.api.filter.authentication.boundary.CheckAccessToken) POST(javax.ws.rs.POST) RequiresBIC(net.petafuel.styx.api.filter.input.boundary.RequiresBIC)

Aggregations

Links (net.petafuel.styx.core.xs2a.entities.Links)2 URL (java.net.URL)1 ApplicationPath (javax.ws.rs.ApplicationPath)1 POST (javax.ws.rs.POST)1 Path (javax.ws.rs.Path)1 CheckAccessToken (net.petafuel.styx.api.filter.authentication.boundary.CheckAccessToken)1 RequiresBIC (net.petafuel.styx.api.filter.input.boundary.RequiresBIC)1 PreAuthResponse (net.petafuel.styx.api.v1.preauth.entity.PreAuthResponse)1 Url (net.petafuel.styx.core.banklookup.sad.entities.Url)1 PersistentOAuthSession (net.petafuel.styx.core.persistence.layers.PersistentOAuthSession)1 OAuthSession (net.petafuel.styx.core.xs2a.oauth.entities.OAuthSession)1