Search in sources :

Example 1 with Consent

use of com.authlete.jaxrs.server.obb.model.Consent in project java-oauth-server by authlete.

the class ConsentsEndpoint method delete.

@DELETE
@Path("{consentId}")
public Response delete(@Context HttpServletRequest request, @HeaderParam(X_FAPI_INTERACTION_ID) String incomingInteractionId, @PathParam("consentId") String consentId) {
    String code = "Consent Delete";
    // Compute a value for the "x-fapi-interaction-id" HTTP response header.
    String outgoingInteractionId = ObbUtils.computeOutgoingInteractionId(code, incomingInteractionId);
    // Validate the access token.
    AuthleteApi authleteApi = AuthleteApiFactory.getDefaultApi();
    IntrospectionResponse info = ObbUtils.validateAccessToken(outgoingInteractionId, code, authleteApi, request, "consents");
    // Find "consent".
    Consent consent = ConsentDao.getInstance().read(consentId);
    // Validate the consent.
    validateConsent(outgoingInteractionId, code, consent, info);
    // Delete the refresh token associated with the consent.
    deleteRefreshToken(outgoingInteractionId, code, authleteApi, consent.getRefreshToken());
    // Delete the consent.
    ConsentDao.getInstance().delete(consentId);
    // Build a successful response.
    return ObbUtils.noContent(outgoingInteractionId);
}
Also used : AuthleteApi(com.authlete.common.api.AuthleteApi) IntrospectionResponse(com.authlete.common.dto.IntrospectionResponse) CreateConsent(com.authlete.jaxrs.server.obb.model.CreateConsent) ResponseConsent(com.authlete.jaxrs.server.obb.model.ResponseConsent) Consent(com.authlete.jaxrs.server.obb.model.Consent) Path(javax.ws.rs.Path) DELETE(javax.ws.rs.DELETE)

Example 2 with Consent

use of com.authlete.jaxrs.server.obb.model.Consent in project java-oauth-server by authlete.

the class ConsentDao method create.

public Consent create(CreateConsent createConsent, long clientId) {
    CreateConsentData data = createConsent.getData();
    String consentId = generateConsentId();
    String now = ObbUtils.formatNow();
    Consent consent = new Consent().setConsentId(consentId).setPermissions(data.getPermissions()).setStatus("AWAITING_AUTHORISATION").setCreationDateTime(now).setExpirationDateTime(data.getExpirationDateTime()).setStatusUpdateDateTime(now).setClientId(clientId);
    getStore().put(consentId, consent);
    return consent;
}
Also used : CreateConsentData(com.authlete.jaxrs.server.obb.model.CreateConsentData) CreateConsent(com.authlete.jaxrs.server.obb.model.CreateConsent) Consent(com.authlete.jaxrs.server.obb.model.Consent)

Example 3 with Consent

use of com.authlete.jaxrs.server.obb.model.Consent in project java-oauth-server by authlete.

the class ConsentsEndpoint method read.

@GET
@Path("{consentId}")
public Response read(@Context HttpServletRequest request, @HeaderParam(X_FAPI_INTERACTION_ID) String incomingInteractionId, @PathParam("consentId") String consentId) {
    String code = "Consent Read";
    // Compute a value for the "x-fapi-interaction-id" HTTP response header.
    String outgoingInteractionId = ObbUtils.computeOutgoingInteractionId(code, incomingInteractionId);
    // Validate the access token.
    AuthleteApi authleteApi = AuthleteApiFactory.getDefaultApi();
    IntrospectionResponse info = ObbUtils.validateAccessToken(outgoingInteractionId, code, authleteApi, request, "consents");
    // Find "consent".
    Consent consent = ConsentDao.getInstance().read(consentId);
    // Validate the consent.
    validateConsent(outgoingInteractionId, code, consent, info);
    // Build a response body.
    ResponseConsent rc = ResponseConsent.create(consent);
    // Build a successful response.
    return ObbUtils.ok(outgoingInteractionId, rc);
}
Also used : ResponseConsent(com.authlete.jaxrs.server.obb.model.ResponseConsent) AuthleteApi(com.authlete.common.api.AuthleteApi) IntrospectionResponse(com.authlete.common.dto.IntrospectionResponse) CreateConsent(com.authlete.jaxrs.server.obb.model.CreateConsent) ResponseConsent(com.authlete.jaxrs.server.obb.model.ResponseConsent) Consent(com.authlete.jaxrs.server.obb.model.Consent) Path(javax.ws.rs.Path) GET(javax.ws.rs.GET)

Example 4 with Consent

use of com.authlete.jaxrs.server.obb.model.Consent in project java-oauth-server by authlete.

the class ConsentsEndpoint method create.

@POST
@Consumes(MediaType.APPLICATION_JSON)
public Response create(@Context HttpServletRequest request, @HeaderParam(X_FAPI_INTERACTION_ID) String incomingInteractionId, CreateConsent createConsent) {
    String code = "Consent Create";
    // Compute a value for the "x-fapi-interaction-id" HTTP response header.
    String outgoingInteractionId = ObbUtils.computeOutgoingInteractionId(code, incomingInteractionId);
    // Validate the access token.
    AuthleteApi authleteApi = AuthleteApiFactory.getDefaultApi();
    IntrospectionResponse info = ObbUtils.validateAccessToken(outgoingInteractionId, code, authleteApi, request, "consents");
    // Validate the input.
    validateCreateConsent(outgoingInteractionId, code, createConsent);
    // Create "consent".
    Consent consent = ConsentDao.getInstance().create(createConsent, info.getClientId());
    // Build a response body.
    ResponseConsent rc = ResponseConsent.create(consent);
    // Build a successful response.
    return ObbUtils.created(outgoingInteractionId, rc);
}
Also used : ResponseConsent(com.authlete.jaxrs.server.obb.model.ResponseConsent) AuthleteApi(com.authlete.common.api.AuthleteApi) IntrospectionResponse(com.authlete.common.dto.IntrospectionResponse) CreateConsent(com.authlete.jaxrs.server.obb.model.CreateConsent) ResponseConsent(com.authlete.jaxrs.server.obb.model.ResponseConsent) Consent(com.authlete.jaxrs.server.obb.model.Consent) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes)

Example 5 with Consent

use of com.authlete.jaxrs.server.obb.model.Consent in project java-oauth-server by authlete.

the class OBBTokenTask method process.

public void process(AuthleteApi authleteApi, HttpServletRequest request, MultivaluedMap<String, String> requestParams, Response response, Map<String, Object> responseParams) {
    // If further processing is not needed.
    if (!needsProcessing(requestParams, response, responseParams)) {
        // Nothing to do.
        return;
    }
    // Get the consent ID associated with the access token.
    String consentId = extractConsentId(responseParams);
    // If no consent ID is associated with the access token.
    if (consentId == null) {
        // Nothing to do.
        return;
    }
    // Get the consent corresponding to the consent ID.
    Consent consent = ConsentDao.getInstance().read(consentId);
    // If there is no consent which corresponds to the consent ID.
    if (consent == null) {
        // Delete the access token (and the refresh token).
        deleteAccessToken(authleteApi, responseParams);
        // Return an error response to the client application.
        throw badRequestException("invalid_request", String.format("There is no consent corresponding to the consent ID '%s'.", consentId));
    }
    // Task on a refresh token.
    doConsentTaskOnRefreshToken(authleteApi, responseParams, consent);
}
Also used : Consent(com.authlete.jaxrs.server.obb.model.Consent)

Aggregations

Consent (com.authlete.jaxrs.server.obb.model.Consent)5 CreateConsent (com.authlete.jaxrs.server.obb.model.CreateConsent)4 AuthleteApi (com.authlete.common.api.AuthleteApi)3 IntrospectionResponse (com.authlete.common.dto.IntrospectionResponse)3 ResponseConsent (com.authlete.jaxrs.server.obb.model.ResponseConsent)3 Path (javax.ws.rs.Path)2 CreateConsentData (com.authlete.jaxrs.server.obb.model.CreateConsentData)1 Consumes (javax.ws.rs.Consumes)1 DELETE (javax.ws.rs.DELETE)1 GET (javax.ws.rs.GET)1 POST (javax.ws.rs.POST)1