use of io.gravitee.rest.api.model.api.ApiEntity in project gravitee-management-rest-api by gravitee-io.
the class ApiPageResourceNotAuthenticatedTest method init.
@Before
public void init() {
resetAllMocks();
mockApi = new ApiEntity();
mockApi.setId(API);
doReturn(mockApi).when(apiService).findById(API);
Set<ApiEntity> mockApis = new HashSet<>(Arrays.asList(mockApi));
doReturn(mockApis).when(apiService).findPublishedByUser(isNull(), argThat(q -> singletonList(API).equals(q.getIds())));
mockPage = new PageEntity();
mockPage.setPublished(true);
mockPage.setVisibility(Visibility.PUBLIC);
doReturn(mockPage).when(pageService).findById(PAGE, null);
mockAnotherPage = new PageEntity();
mockAnotherPage.setPublished(true);
mockAnotherPage.setVisibility(Visibility.PUBLIC);
Map<String, String> metadataMap = new HashMap<>();
metadataMap.put(ANOTHER_PAGE, ANOTHER_PAGE);
mockAnotherPage.setMetadata(metadataMap);
doReturn(mockAnotherPage).when(pageService).findById(ANOTHER_PAGE, null);
doReturn(new Page()).when(pageMapper).convert(any(), any(), any());
}
use of io.gravitee.rest.api.model.api.ApiEntity in project gravitee-management-rest-api by gravitee-io.
the class PermissionFilterTest method shouldBeAuthorizedWhenApiPermissions.
@Test
public void shouldBeAuthorizedWhenApiPermissions() {
ApiEntity api = initApiMocks();
when(roleService.hasPermission(any(), any(), any())).thenReturn(true);
permissionFilter.filter(permissions, containerRequestContext);
verify(apiService, times(1)).findById(api.getId());
verify(applicationService, never()).findById(any());
verify(roleService, times(1)).hasPermission(any(), any(), any());
verify(membershipService, times(1)).getUserMemberPermissions(api, USERNAME);
verify(membershipService, never()).getRoles(any(), any(), any(), any());
}
use of io.gravitee.rest.api.model.api.ApiEntity in project gravitee-management-rest-api by gravitee-io.
the class PermissionFilterTest method initApiMocks.
/**
* API Tests
*/
private ApiEntity initApiMocks() {
ApiEntity api = new ApiEntity();
api.setId(API_ID);
Principal user = () -> USERNAME;
when(apiService.findById(api.getId())).thenReturn(api);
when(securityContext.getUserPrincipal()).thenReturn(user);
Permission perm = mock(Permission.class);
when(perm.value()).thenReturn(RolePermission.API_ANALYTICS);
when(perm.acls()).thenReturn(new RolePermissionAction[] { RolePermissionAction.UPDATE });
when(permissions.value()).thenReturn(new Permission[] { perm });
UriInfo uriInfo = mock(UriInfo.class);
MultivaluedHashMap<String, String> map = new MultivaluedHashMap<>();
map.put("apiId", Collections.singletonList(api.getId()));
when(uriInfo.getPathParameters()).thenReturn(map);
when(containerRequestContext.getUriInfo()).thenReturn(uriInfo);
return api;
}
use of io.gravitee.rest.api.model.api.ApiEntity in project gravitee-management-rest-api by gravitee-io.
the class WebhookNotifierServiceImpl method toJson.
private String toJson(final Hook hook, final Map<String, Object> params) {
JsonObject content = new JsonObject();
// hook
content.put("event", hook.name());
content.put("scope", hook.getScope().name());
// api
if (params.containsKey(PARAM_API)) {
Object api = params.get(PARAM_API);
if (api != null) {
JsonObject jsonApi = new JsonObject();
jsonApi.put("id", api instanceof ApiModelEntity ? ((ApiModelEntity) api).getId() : ((ApiEntity) api).getId());
jsonApi.put("name", api instanceof ApiModelEntity ? ((ApiModelEntity) api).getName() : ((ApiEntity) api).getName());
jsonApi.put("version", api instanceof ApiModelEntity ? ((ApiModelEntity) api).getVersion() : ((ApiEntity) api).getVersion());
content.put("api", jsonApi);
}
}
// application
if (params.containsKey(PARAM_APPLICATION)) {
ApplicationEntity application = (ApplicationEntity) params.get(PARAM_APPLICATION);
if (application != null) {
JsonObject jsonApplication = new JsonObject();
jsonApplication.put("id", application.getId());
jsonApplication.put("name", application.getName());
/*
if (application.getType() != null) {
jsonApplication.put("type", application.getType());
}
*/
content.put("application", jsonApplication);
}
}
// owner
if (params.containsKey(PARAM_OWNER)) {
PrimaryOwnerEntity owner = (PrimaryOwnerEntity) params.get(PARAM_OWNER);
if (owner != null) {
JsonObject jsonOwner = new JsonObject();
jsonOwner.put("id", owner.getId());
jsonOwner.put("username", owner.getDisplayName());
content.put("owner", jsonOwner);
}
}
// plan
if (params.containsKey(PARAM_PLAN)) {
PlanEntity plan = (PlanEntity) params.get(PARAM_PLAN);
if (plan != null) {
JsonObject jsonPlan = new JsonObject();
jsonPlan.put("id", plan.getId());
jsonPlan.put("name", plan.getName());
jsonPlan.put("security", plan.getSecurity());
content.put("plan", jsonPlan);
}
}
// subscription
if (params.containsKey(PARAM_SUBSCRIPTION)) {
SubscriptionEntity subscription = (SubscriptionEntity) params.get(PARAM_SUBSCRIPTION);
if (subscription != null) {
JsonObject jsonSubscription = new JsonObject();
jsonSubscription.put("id", subscription.getId());
jsonSubscription.put("status", subscription.getStatus());
content.put("subscription", jsonSubscription);
}
}
return content.encode();
}
use of io.gravitee.rest.api.model.api.ApiEntity in project gravitee-management-rest-api by gravitee-io.
the class ApiSynchronizationProcessor method processCheckSynchronization.
public boolean processCheckSynchronization(ApiEntity deployedApi, ApiEntity apiToDeploy) {
Class<ApiEntity> cl = ApiEntity.class;
List<Object> requiredFieldsDeployedApi = new ArrayList<Object>();
List<Object> requiredFieldsApiToDeploy = new ArrayList<Object>();
for (Field f : cl.getDeclaredFields()) {
if (f.getAnnotation(DeploymentRequired.class) != null) {
boolean previousAccessibleState = f.isAccessible();
f.setAccessible(true);
try {
requiredFieldsDeployedApi.add(f.get(deployedApi));
requiredFieldsApiToDeploy.add(f.get(apiToDeploy));
} catch (Exception e) {
LOGGER.error("Error access API required deployment fields", e);
} finally {
f.setAccessible(previousAccessibleState);
}
}
}
try {
String requiredFieldsDeployedApiDefinition = objectMapper.writeValueAsString(requiredFieldsDeployedApi);
String requiredFieldsApiToDeployDefinition = objectMapper.writeValueAsString(requiredFieldsApiToDeploy);
return requiredFieldsDeployedApiDefinition.equals(requiredFieldsApiToDeployDefinition);
} catch (Exception e) {
LOGGER.error("Unexpected error while generating API deployment required fields definition", e);
return false;
}
}
Aggregations