Search in sources :

Example 1 with CheckAccessToken

use of net.petafuel.styx.api.filter.authentication.boundary.CheckAccessToken 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)

Example 2 with CheckAccessToken

use of net.petafuel.styx.api.filter.authentication.boundary.CheckAccessToken in project styx by petafuel.

the class PreAuthResource method getPreStepAuthentication.

/**
 * @param preauthId this id should match a state column within the oauth_sessions table
 * @return a GetPreStepResponse Object which contains certain values from an OAuthSession object
 */
@GET
@CheckAccessToken(allowedServices = { XS2ATokenType.AIS, XS2ATokenType.PIS, XS2ATokenType.AISPIS, XS2ATokenType.PIIS })
@Path("/preauth/{preauthId}")
public Response getPreStepAuthentication(@NotBlank @PathParam("preauthId") String preauthId) {
    OAuthSession oAuthSession;
    try {
        oAuthSession = PersistentOAuthSession.getById(UUID.fromString(preauthId));
    } catch (PersistenceEmptyResultSetException unknownPreauth) {
        throw new StyxException(new ResponseEntity(ResponseConstant.STYX_PREAUTH_NOT_FOUND, ResponseCategory.ERROR, ResponseOrigin.CLIENT));
    }
    LOG.info("Successfully retrieved preauth from oauth_session state={}", oAuthSession.getState());
    return Response.status(ResponseConstant.OK).entity(new GetPreStepResponse(oAuthSession)).build();
}
Also used : ResponseEntity(net.petafuel.styx.api.exception.ResponseEntity) GetPreStepResponse(net.petafuel.styx.api.v1.preauth.entity.GetPreStepResponse) PersistentOAuthSession(net.petafuel.styx.core.persistence.layers.PersistentOAuthSession) OAuthSession(net.petafuel.styx.core.xs2a.oauth.entities.OAuthSession) PersistenceEmptyResultSetException(net.petafuel.styx.core.persistence.PersistenceEmptyResultSetException) StyxException(net.petafuel.styx.api.exception.StyxException) Path(javax.ws.rs.Path) ApplicationPath(javax.ws.rs.ApplicationPath) CheckAccessToken(net.petafuel.styx.api.filter.authentication.boundary.CheckAccessToken) GET(javax.ws.rs.GET)

Aggregations

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