Search in sources :

Example 1 with SubscriptionEntity

use of io.gravitee.rest.api.model.SubscriptionEntity in project gravitee-api-management by gravitee-io.

the class ApplicationSubscriptionApiKeysResource method renewApiKeyForApplicationSubscription.

@POST
@Path("/_renew")
@Produces(MediaType.APPLICATION_JSON)
@ApiOperation(value = "Renew an API key", notes = "User must have the MANAGE_API_KEYS permission to use this service")
@ApiResponses({ @ApiResponse(code = 201, message = "A new API Key", response = ApiKeyEntity.class), @ApiResponse(code = 500, message = "Internal server error") })
@Permissions({ @Permission(value = RolePermission.APPLICATION_SUBSCRIPTION, acls = RolePermissionAction.UPDATE) })
public Response renewApiKeyForApplicationSubscription() {
    checkApplicationApiKeyModeAllowed(application);
    SubscriptionEntity subscriptionEntity = subscriptionService.findById(subscription);
    ApiKeyEntity apiKeyEntity = apiKeyService.renew(subscriptionEntity);
    URI location = URI.create(uriInfo.getPath().replace("_renew", apiKeyEntity.getId()));
    return Response.created(location).entity(apiKeyEntity).build();
}
Also used : ApiKeyEntity(io.gravitee.rest.api.model.ApiKeyEntity) SubscriptionEntity(io.gravitee.rest.api.model.SubscriptionEntity) URI(java.net.URI) Permissions(io.gravitee.rest.api.management.rest.security.Permissions)

Example 2 with SubscriptionEntity

use of io.gravitee.rest.api.model.SubscriptionEntity in project gravitee-api-management by gravitee-io.

the class SubscriptionKeysResourceTest method shouldRevokeKeyNoSubscription.

@Test
public void shouldRevokeKeyNoSubscription() {
    SubscriptionEntity subscription = new SubscriptionEntity();
    subscription.setApi(API);
    subscription.setId(SUBSCRIPTION);
    apiKeyEntity = new ApiKeyEntity();
    apiKeyEntity.setKey(KEY);
    apiKeyEntity.setSubscriptions(Set.of(subscription));
    doReturn(subscription).when(subscriptionService).findById(SUBSCRIPTION);
    doReturn(apiKeyEntity).when(apiKeyService).findByKeyAndApi(KEY, API);
    final Response response = target(SUBSCRIPTION).path("keys/" + KEY + "/_revoke").request().post(null);
    assertEquals(HttpStatusCode.NO_CONTENT_204, response.getStatus());
    Mockito.verify(apiKeyService).revoke(apiKeyEntity, true);
    assertFalse(response.hasEntity());
}
Also used : Response(javax.ws.rs.core.Response) ApiKeyEntity(io.gravitee.rest.api.model.ApiKeyEntity) SubscriptionEntity(io.gravitee.rest.api.model.SubscriptionEntity) Test(org.junit.Test)

Example 3 with SubscriptionEntity

use of io.gravitee.rest.api.model.SubscriptionEntity in project gravitee-api-management by gravitee-io.

the class SubscriptionKeysResourceTest method init.

@Before
public void init() {
    resetAllMocks();
    SubscriptionEntity subscription = new SubscriptionEntity();
    subscription.setId(SUBSCRIPTION);
    apiKeyEntity = new ApiKeyEntity();
    apiKeyEntity.setKey(KEY);
    apiKeyEntity.setSubscriptions(Set.of(subscription));
    apiKeyEntity.setCreatedAt(new Date());
    doReturn(apiKeyEntity).when(apiKeyService).renew(subscription);
    doReturn(apiKeyEntity).when(apiKeyService).findByKeyAndApi(KEY, API);
    doReturn(new Key().key(KEY)).when(keyMapper).convert(apiKeyEntity);
    SubscriptionEntity subscriptionEntity = new SubscriptionEntity();
    subscriptionEntity.setApi(API);
    subscriptionEntity.setApplication(APPLICATION);
    doReturn(subscriptionEntity).when(subscriptionService).findById(eq(SUBSCRIPTION));
    doReturn(true).when(permissionService).hasPermission(any(), any(), any());
}
Also used : ApiKeyEntity(io.gravitee.rest.api.model.ApiKeyEntity) SubscriptionEntity(io.gravitee.rest.api.model.SubscriptionEntity) Date(java.util.Date) Key(io.gravitee.rest.api.portal.rest.model.Key) Before(org.junit.Before)

Example 4 with SubscriptionEntity

use of io.gravitee.rest.api.model.SubscriptionEntity in project gravitee-api-management by gravitee-io.

the class SubscriptionResourceTest method init.

@Before
public void init() {
    resetAllMocks();
    subscriptionEntity = new SubscriptionEntity();
    subscriptionEntity.setId(SUBSCRIPTION);
    subscriptionEntity.setApi(API);
    subscriptionEntity.setApplication(APPLICATION);
    doReturn(subscriptionEntity).when(subscriptionService).findById(SUBSCRIPTION);
    doThrow(SubscriptionNotFoundException.class).when(subscriptionService).findById(UNKNOWN_SUBSCRIPTION);
    doReturn(Arrays.asList(new ApiKeyEntity())).when(apiKeyService).findBySubscription(SUBSCRIPTION);
    doReturn(new Subscription()).when(subscriptionMapper).convert(any());
    doReturn(new Key()).when(keyMapper).convert(any(ApiKeyEntity.class));
    doReturn(true).when(permissionService).hasPermission(any(), any(), any());
}
Also used : ApiKeyEntity(io.gravitee.rest.api.model.ApiKeyEntity) SubscriptionEntity(io.gravitee.rest.api.model.SubscriptionEntity) Subscription(io.gravitee.rest.api.portal.rest.model.Subscription) Key(io.gravitee.rest.api.portal.rest.model.Key) Before(org.junit.Before)

Example 5 with SubscriptionEntity

use of io.gravitee.rest.api.model.SubscriptionEntity in project gravitee-api-management by gravitee-io.

the class ApiSubscriptionApikeyResourceTest method mockExistingSubscriptionWithApplication.

private void mockExistingSubscriptionWithApplication(ApiKeyMode apiKeyMode) {
    SubscriptionEntity subscription = new SubscriptionEntity();
    subscription.setApplication(APPLICATION_ID);
    when(subscriptionService.findById(SUBSCRIPTION_ID)).thenReturn(subscription);
    ApplicationEntity application = new ApplicationEntity();
    application.setApiKeyMode(apiKeyMode);
    when(applicationService.findById(GraviteeContext.getCurrentEnvironment(), APPLICATION_ID)).thenReturn(application);
}
Also used : ApplicationEntity(io.gravitee.rest.api.model.ApplicationEntity) SubscriptionEntity(io.gravitee.rest.api.model.SubscriptionEntity)

Aggregations

SubscriptionEntity (io.gravitee.rest.api.model.SubscriptionEntity)61 Test (org.junit.Test)30 Response (javax.ws.rs.core.Response)24 ApiKeyEntity (io.gravitee.rest.api.model.ApiKeyEntity)18 SubscriptionQuery (io.gravitee.rest.api.model.subscription.SubscriptionQuery)18 ApplicationEntity (io.gravitee.rest.api.model.ApplicationEntity)13 ApplicationListItem (io.gravitee.rest.api.model.application.ApplicationListItem)13 ApiEntity (io.gravitee.rest.api.model.api.ApiEntity)12 SubscriptionService (io.gravitee.rest.api.service.SubscriptionService)11 TopHitsAnalytics (io.gravitee.rest.api.model.analytics.TopHitsAnalytics)10 GroupByQuery (io.gravitee.rest.api.model.analytics.query.GroupByQuery)10 Collectors (java.util.stream.Collectors)10 MediaType (io.gravitee.common.http.MediaType)8 SubscriptionStatus (io.gravitee.rest.api.model.SubscriptionStatus)8 ErrorResponse (io.gravitee.rest.api.portal.rest.model.ErrorResponse)8 java.util (java.util)8 Inject (javax.inject.Inject)8 Before (org.junit.Before)8 Key (io.gravitee.rest.api.portal.rest.model.Key)7 ApplicationService (io.gravitee.rest.api.service.ApplicationService)7