use of io.gravitee.management.model.ApiEntity in project gravitee-management-rest-api by gravitee-io.
the class PlatformEventsResource method listEvents.
@GET
@Produces(MediaType.APPLICATION_JSON)
@Permissions({ @Permission(value = RolePermission.MANAGEMENT_PLATFORM, acls = RolePermissionAction.READ) })
public Page<EventEntity> listEvents(@BeanParam EventSearchParam eventSearchParam) {
eventSearchParam.validate();
Map<String, Object> properties = new HashMap<>();
if (eventSearchParam.getApiIdsParam() != null && eventSearchParam.getApiIdsParam().getIds() != null && !eventSearchParam.getApiIdsParam().getIds().isEmpty()) {
properties.put(Event.EventProperties.API_ID.getValue(), eventSearchParam.getApiIdsParam().getIds());
}
Page<EventEntity> events = eventService.search(eventSearchParam.getEventTypeListParam().getEventTypes(), properties, eventSearchParam.getFrom(), eventSearchParam.getTo(), eventSearchParam.getPage(), eventSearchParam.getSize());
events.getContent().forEach(event -> {
Map<String, String> properties1 = event.getProperties();
// Event relative to API
if (properties1 != null && properties1.containsKey(Event.EventProperties.API_ID.getValue())) {
// Remove payload content from response since it's not required anymore
event.setPayload(null);
// Retrieve additional data
String apiId = properties1.get(Event.EventProperties.API_ID.getValue());
ApiEntity api = apiService.findById(apiId);
properties1.put("api_name", api.getName());
properties1.put("api_version", api.getVersion());
}
});
return events;
}
use of io.gravitee.management.model.ApiEntity in project gravitee-management-rest-api by gravitee-io.
the class PermissionsFilter method filter.
protected void filter(Permissions permissions, ContainerRequestContext requestContext) {
if (permissions != null && permissions.value().length > 0) {
Principal principal = securityContext.getUserPrincipal();
if (principal != null) {
String username = principal.getName();
for (Permission permission : permissions.value()) {
RoleEntity role;
Map<String, char[]> memberPermissions;
switch(permission.value().getScope()) {
case MANAGEMENT:
role = membershipService.getRole(MembershipReferenceType.MANAGEMENT, MembershipDefaultReferenceId.DEFAULT.name(), username, RoleScope.MANAGEMENT);
if (roleService.hasPermission(role.getPermissions(), permission.value().getPermission(), permission.acls())) {
return;
}
break;
case PORTAL:
role = membershipService.getRole(MembershipReferenceType.PORTAL, MembershipDefaultReferenceId.DEFAULT.name(), username, RoleScope.PORTAL);
if (roleService.hasPermission(role.getPermissions(), permission.value().getPermission(), permission.acls())) {
return;
}
break;
case APPLICATION:
ApplicationEntity application = getApplication(requestContext);
memberPermissions = membershipService.getMemberPermissions(application, username);
if (roleService.hasPermission(memberPermissions, permission.value().getPermission(), permission.acls())) {
return;
}
break;
case API:
ApiEntity api = getApi(requestContext);
memberPermissions = membershipService.getMemberPermissions(api, username);
if (roleService.hasPermission(memberPermissions, permission.value().getPermission(), permission.acls())) {
return;
}
break;
default:
sendSecurityError();
}
}
}
sendSecurityError();
}
}
use of io.gravitee.management.model.ApiEntity in project gravitee-management-rest-api by gravitee-io.
the class HealthCheckServiceImpl method getResponseTime.
@Override
public ApiMetrics getResponseTime(String api, String field) {
logger.debug("Run health response-time query for API '{}'", api);
try {
ApiEntity apiEntity = apiService.findById(api);
AverageResponseTimeResponse response = healthCheckRepository.query(QueryBuilders.responseTime().api(api).field(AverageResponseTimeQuery.Field.valueOf(field)).build());
return convert(apiEntity, response.getEndpointResponseTimes(), field);
} catch (Exception ex) {
logger.error("An unexpected error occurs while searching for health data.", ex);
return null;
}
}
use of io.gravitee.management.model.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;
}
}
use of io.gravitee.management.model.ApiEntity in project gravitee-management-rest-api by gravitee-io.
the class ApiService_CreateTest method shouldCreateWithDefaultPath.
@Test
public void shouldCreateWithDefaultPath() throws TechnicalException {
when(api.getId()).thenReturn(API_ID);
when(api.getName()).thenReturn(API_NAME);
when(api.getVisibility()).thenReturn(Visibility.PRIVATE);
when(apiRepository.findById(anyString())).thenReturn(Optional.empty());
when(apiRepository.create(any())).thenReturn(api);
when(newApi.getName()).thenReturn(API_NAME);
when(newApi.getVersion()).thenReturn("v1");
when(newApi.getDescription()).thenReturn("Ma description");
when(newApi.getContextPath()).thenReturn("/context");
UserEntity admin = new UserEntity();
admin.setUsername(USER_NAME);
when(userService.findById(admin.getUsername())).thenReturn(admin);
final ApiEntity apiEntity = apiService.create(newApi, USER_NAME);
assertNotNull(apiEntity);
assertEquals(API_NAME, apiEntity.getName());
assertNotNull(apiEntity.getPaths());
/*assertTrue("paths not empty", !apiEntity.getPaths().isEmpty());
assertEquals("paths.size == 1", apiEntity.getPaths().size(), 1);
assertEquals("path == /* ", apiEntity.getPaths().get(0).getPath(), "/*");*/
}
Aggregations