use of io.gravitee.rest.api.service.jackson.filter.ApiPermissionFilter in project gravitee-management-rest-api by gravitee-io.
the class ApiService_StartTest method setUp.
@Before
public void setUp() {
PropertyFilter apiMembershipTypeFilter = new ApiPermissionFilter();
objectMapper.setFilterProvider(new SimpleFilterProvider(Collections.singletonMap("apiMembershipTypeFilter", apiMembershipTypeFilter)));
UserEntity u = mock(UserEntity.class);
when(u.getId()).thenReturn("uid");
when(userService.findById(any())).thenReturn(u);
MembershipEntity po = mock(MembershipEntity.class);
when(membershipService.getPrimaryOwner(eq(io.gravitee.rest.api.model.MembershipReferenceType.API), anyString())).thenReturn(po);
when(api.getId()).thenReturn(API_ID);
}
use of io.gravitee.rest.api.service.jackson.filter.ApiPermissionFilter in project gravitee-management-rest-api by gravitee-io.
the class ApiService_FindByIdTest method setUp.
@Before
public void setUp() {
PropertyFilter apiMembershipTypeFilter = new ApiPermissionFilter();
objectMapper.setFilterProvider(new SimpleFilterProvider(Collections.singletonMap("apiMembershipTypeFilter", apiMembershipTypeFilter)));
GraviteeContext.setCurrentEnvironment("DEFAULT");
}
use of io.gravitee.rest.api.service.jackson.filter.ApiPermissionFilter in project gravitee-management-rest-api by gravitee-io.
the class ApiDuplicatorService_gRPC_ExportAsJsonTestSetup method setUp.
@Before
public void setUp() throws TechnicalException {
PropertyFilter apiMembershipTypeFilter = new ApiPermissionFilter();
objectMapper.setFilterProvider(new SimpleFilterProvider(Collections.singletonMap("apiMembershipTypeFilter", apiMembershipTypeFilter)));
// register API Entity serializers
when(applicationContext.getBean(MembershipService.class)).thenReturn(membershipService);
when(applicationContext.getBean(PlanService.class)).thenReturn(planService);
when(applicationContext.getBean(PageService.class)).thenReturn(pageService);
when(applicationContext.getBean(GroupService.class)).thenReturn(groupService);
when(applicationContext.getBean(UserService.class)).thenReturn(userService);
when(applicationContext.getBean(ApiMetadataService.class)).thenReturn(apiMetadataService);
when(applicationContext.getBean(MediaService.class)).thenReturn(mediaService);
ApiCompositeSerializer apiCompositeSerializer = new ApiCompositeSerializer();
ApiSerializer apiDefaultSerializer = new ApiDefaultSerializer();
apiDefaultSerializer.setApplicationContext(applicationContext);
// V_1_15
ApiSerializer apiPrior115VersionSerializer = new Api1_15VersionSerializer();
apiPrior115VersionSerializer.setApplicationContext(applicationContext);
// V_1_20
ApiSerializer apiPrior120VersionSerializer = new Api1_20VersionSerializer();
apiPrior120VersionSerializer.setApplicationContext(applicationContext);
// V_1_25
ApiSerializer apiPrior125VersionSerializer = new Api1_25VersionSerializer();
apiPrior125VersionSerializer.setApplicationContext(applicationContext);
// V_3_0
ApiSerializer apiPrior30VersionSerializer = new Api3_0VersionSerializer();
apiPrior30VersionSerializer.setApplicationContext(applicationContext);
// V_3_7
ApiSerializer apiPrior37VersionSerializer = new Api3_7VersionSerializer();
apiPrior37VersionSerializer.setApplicationContext(applicationContext);
apiCompositeSerializer.setSerializers(Arrays.asList(apiDefaultSerializer, apiPrior115VersionSerializer, apiPrior120VersionSerializer, apiPrior125VersionSerializer, apiPrior30VersionSerializer, apiPrior37VersionSerializer));
SimpleModule module = new SimpleModule();
module.addSerializer(ApiEntity.class, apiCompositeSerializer);
objectMapper.registerModule(module);
ApiEntity apiEntity = new ApiEntity();
apiEntity.setId(API_ID);
apiEntity.setDescription("Gravitee.io");
apiEntity.setFlowMode(FlowMode.DEFAULT);
apiEntity.setFlows(null);
apiEntity.setGraviteeDefinitionVersion(DefinitionVersion.V1.getLabel());
// set proxy
Proxy proxy = new Proxy();
proxy.setVirtualHosts(Collections.singletonList(new VirtualHost("/test")));
proxy.setStripContextPath(false);
Logging logging = new Logging();
logging.setMode(LoggingMode.CLIENT_PROXY);
logging.setCondition("condition");
proxy.setLogging(logging);
EndpointGroup endpointGroup = new EndpointGroup();
endpointGroup.setName("default-group");
Endpoint endpoint = new HttpEndpoint("default", "http://test");
HttpEndpoint endPointGrpc = new GrpcEndpoint("EndPoint GRPC", "grpc://localhost:8888");
HttpClientOptions httpClientOptions = new HttpClientOptions();
httpClientOptions.setVersion(ProtocolVersion.HTTP_2);
httpClientOptions.setClearTextUpgrade(true);
endPointGrpc.setHttpClientOptions(httpClientOptions);
LinkedHashSet<Endpoint> endpoints = new LinkedHashSet<>();
endpoints.add(endpoint);
endpoints.add(endPointGrpc);
endpointGroup.setEndpoints(endpoints);
LoadBalancer loadBalancer = new LoadBalancer();
loadBalancer.setType(LoadBalancerType.ROUND_ROBIN);
endpointGroup.setLoadBalancer(loadBalancer);
proxy.setGroups(Collections.singleton(endpointGroup));
ResponseTemplate responseTemplate = new ResponseTemplate();
responseTemplate.setStatusCode(400);
responseTemplate.setBody("{\"bad\":\"news\"}");
apiEntity.setResponseTemplates(Collections.singletonMap("API_KEY_MISSING", Collections.singletonMap("*/*", responseTemplate)));
apiEntity.setPaths(null);
apiEntity.setProxy(proxy);
PrimaryOwnerEntity primaryOwnerEntity = new PrimaryOwnerEntity();
primaryOwnerEntity.setDisplayName("johndoe-sourceId");
primaryOwnerEntity.setId("johndoe");
primaryOwnerEntity.setType(MembershipMemberType.USER.toString());
apiEntity.setPrimaryOwner(primaryOwnerEntity);
when(apiService.findById(API_ID)).thenReturn(prepareApiEntity(apiEntity));
PageEntity folder = new PageEntity();
folder.setName("My Folder");
folder.setOrder(1);
folder.setType(PageType.FOLDER.toString());
folder.setVisibility(Visibility.PUBLIC);
PageEntity markdownPage = new PageEntity();
markdownPage.setName("My Title");
markdownPage.setOrder(1);
markdownPage.setType(PageType.MARKDOWN.toString());
markdownPage.setContent("Read the doc");
markdownPage.setVisibility(Visibility.PUBLIC);
PageEntity asideFolder = new PageEntity();
asideFolder.setName("Aside");
asideFolder.setOrder(1);
asideFolder.setPublished(true);
asideFolder.setType(PageType.SYSTEM_FOLDER.toString());
asideFolder.setVisibility(Visibility.PUBLIC);
PageEntity swaggerPage = new PageEntity();
swaggerPage.setName("My Swagger");
swaggerPage.setOrder(1);
swaggerPage.setType(PageType.SWAGGER.toString());
swaggerPage.setContent("Read the doc");
swaggerPage.setVisibility(Visibility.PUBLIC);
PageEntity linkPage = new PageEntity();
linkPage.setName("My Link");
linkPage.setOrder(1);
linkPage.setType(PageType.LINK.toString());
linkPage.setContent("Read the doc");
linkPage.setVisibility(Visibility.PUBLIC);
PageEntity translationPage = new PageEntity();
translationPage.setName("My Translation");
translationPage.setOrder(1);
translationPage.setType(PageType.TRANSLATION.toString());
translationPage.setContent("Lire la documentation");
translationPage.setVisibility(Visibility.PUBLIC);
PageEntity markdownTemplatePage = new PageEntity();
markdownTemplatePage.setName("My Template");
markdownTemplatePage.setOrder(1);
markdownTemplatePage.setType(PageType.MARKDOWN_TEMPLATE.toString());
markdownTemplatePage.setContent("Read the doc");
markdownTemplatePage.setVisibility(Visibility.PUBLIC);
PageEntity asciidocPage = new PageEntity();
asciidocPage.setName("My asciidoc");
asciidocPage.setOrder(1);
asciidocPage.setType(PageType.ASCIIDOC.toString());
asciidocPage.setContent("Read the asciidoc");
asciidocPage.setVisibility(Visibility.PUBLIC);
when(pageService.search(any(), eq(true), eq(GraviteeContext.getCurrentEnvironment()))).thenReturn(Arrays.asList(folder, markdownPage, swaggerPage, asideFolder, linkPage, translationPage, markdownTemplatePage, asciidocPage));
RoleEntity poRole = new RoleEntity();
poRole.setName("PRIMARY_OWNER");
poRole.setId("API_PRIMARY_OWNER");
MembershipEntity membership = new MembershipEntity();
membership.setMemberId("johndoe");
membership.setMemberType(MembershipMemberType.USER);
membership.setRoleId("API_PRIMARY_OWNER");
MemberEntity memberEntity = new MemberEntity();
memberEntity.setId(membership.getMemberId());
memberEntity.setType(membership.getMemberType());
memberEntity.setRoles(Collections.singletonList(poRole));
when(membershipService.getMembersByReference(eq(MembershipReferenceType.API), eq(API_ID))).thenReturn(Collections.singleton(memberEntity));
UserEntity userEntity = new UserEntity();
userEntity.setId(memberEntity.getId());
userEntity.setSource(userEntity.getId() + "-source");
userEntity.setSourceId(userEntity.getId() + "-sourceId");
when(userService.findById(memberEntity.getId())).thenReturn(userEntity);
apiEntity.setGroups(Collections.singleton("my-group"));
GroupEntity groupEntity = new GroupEntity();
groupEntity.setId("my-group");
groupEntity.setName("My Group");
when(groupService.findByIds(apiEntity.getGroups())).thenReturn(Collections.singleton(groupEntity));
PlanEntity publishedPlan = new PlanEntity();
publishedPlan.setId("plan-id");
publishedPlan.setApi(API_ID);
publishedPlan.setDescription("free plan");
publishedPlan.setType(PlanType.API);
publishedPlan.setSecurity(PlanSecurityType.API_KEY);
publishedPlan.setValidation(PlanValidationType.AUTO);
publishedPlan.setStatus(PlanStatus.PUBLISHED);
Map<String, List<Rule>> paths = new HashMap<>();
Rule rule = new Rule();
rule.setEnabled(true);
rule.setMethods(Sets.newSet(HttpMethod.GET));
Policy policy = new Policy();
policy.setName("rate-limit");
String ls = System.lineSeparator();
policy.setConfiguration("{" + ls + " \"rate\": {" + ls + " \"limit\": 1," + ls + " \"periodTime\": 1," + ls + " \"periodTimeUnit\": \"SECONDS\"" + ls + " }" + ls + " }");
rule.setPolicy(policy);
paths.put("/", Collections.singletonList(rule));
publishedPlan.setPaths(paths);
PlanEntity closedPlan = new PlanEntity();
closedPlan.setId("closedPlan-id");
closedPlan.setApi(API_ID);
closedPlan.setDescription("free closedPlan");
closedPlan.setType(PlanType.API);
closedPlan.setSecurity(PlanSecurityType.API_KEY);
closedPlan.setValidation(PlanValidationType.AUTO);
closedPlan.setStatus(PlanStatus.CLOSED);
closedPlan.setPaths(paths);
Set<PlanEntity> set = new HashSet<>();
set.add(publishedPlan);
set.add(closedPlan);
when(planService.findByApi(API_ID)).thenReturn(set);
ApiMetadataEntity apiMetadataEntity = new ApiMetadataEntity();
apiMetadataEntity.setApiId(API_ID);
apiMetadataEntity.setKey("metadata-key");
apiMetadataEntity.setName("metadata-name");
apiMetadataEntity.setValue("metadata-value");
apiMetadataEntity.setDefaultValue("metadata-default-value");
apiMetadataEntity.setFormat(MetadataFormat.STRING);
when(apiMetadataService.findAllByApi(API_ID)).thenReturn(Collections.singletonList(apiMetadataEntity));
}
use of io.gravitee.rest.api.service.jackson.filter.ApiPermissionFilter in project gravitee-management-rest-api by gravitee-io.
the class ApiDuplicatorService_ExportAsJsonTestSetup method setUp.
@Before
public void setUp() throws TechnicalException {
GraviteeContext.setCurrentEnvironment("DEFAULT");
PropertyFilter apiMembershipTypeFilter = new ApiPermissionFilter();
objectMapper.setFilterProvider(new SimpleFilterProvider(Collections.singletonMap("apiMembershipTypeFilter", apiMembershipTypeFilter)));
// register API Entity serializers
when(applicationContext.getBean(MembershipService.class)).thenReturn(membershipService);
when(applicationContext.getBean(PlanService.class)).thenReturn(planService);
when(applicationContext.getBean(PageService.class)).thenReturn(pageService);
when(applicationContext.getBean(GroupService.class)).thenReturn(groupService);
when(applicationContext.getBean(UserService.class)).thenReturn(userService);
when(applicationContext.getBean(ApiMetadataService.class)).thenReturn(apiMetadataService);
when(applicationContext.getBean(MediaService.class)).thenReturn(mediaService);
ApiCompositeSerializer apiCompositeSerializer = new ApiCompositeSerializer();
ApiSerializer apiDefaultSerializer = new ApiDefaultSerializer();
apiDefaultSerializer.setApplicationContext(applicationContext);
// V_1_15
ApiSerializer apiPrior115VersionSerializer = new Api1_15VersionSerializer();
apiPrior115VersionSerializer.setApplicationContext(applicationContext);
// V_1_20
ApiSerializer apiPrior120VersionSerializer = new Api1_20VersionSerializer();
apiPrior120VersionSerializer.setApplicationContext(applicationContext);
// V_1_25
ApiSerializer apiPrior125VersionSerializer = new Api1_25VersionSerializer();
apiPrior125VersionSerializer.setApplicationContext(applicationContext);
// V_3_0
ApiSerializer apiPrior30VersionSerializer = new Api3_0VersionSerializer();
apiPrior30VersionSerializer.setApplicationContext(applicationContext);
// V_3_7
ApiSerializer apiPrior37VersionSerializer = new Api3_7VersionSerializer();
apiPrior37VersionSerializer.setApplicationContext(applicationContext);
apiCompositeSerializer.setSerializers(Arrays.asList(apiDefaultSerializer, apiPrior115VersionSerializer, apiPrior120VersionSerializer, apiPrior125VersionSerializer, apiPrior30VersionSerializer, apiPrior37VersionSerializer));
SimpleModule module = new SimpleModule();
module.addSerializer(ApiEntity.class, apiCompositeSerializer);
objectMapper.registerModule(module);
ApiEntity apiEntity = new ApiEntity();
apiEntity.setId(API_ID);
apiEntity.setDescription("Gravitee.io");
apiEntity.setFlowMode(FlowMode.DEFAULT);
apiEntity.setFlows(null);
apiEntity.setGraviteeDefinitionVersion(DefinitionVersion.V1.getLabel());
// set proxy
Proxy proxy = new Proxy();
proxy.setVirtualHosts(Collections.singletonList(new VirtualHost("/test")));
proxy.setStripContextPath(false);
Logging logging = new Logging();
logging.setMode(LoggingMode.CLIENT_PROXY);
logging.setCondition("condition");
proxy.setLogging(logging);
EndpointGroup endpointGroup = new EndpointGroup();
endpointGroup.setName("default-group");
Endpoint endpoint = new HttpEndpoint("default", "http://test");
endpointGroup.setEndpoints(Collections.singleton(endpoint));
LoadBalancer loadBalancer = new LoadBalancer();
loadBalancer.setType(LoadBalancerType.ROUND_ROBIN);
endpointGroup.setLoadBalancer(loadBalancer);
proxy.setGroups(Collections.singleton(endpointGroup));
apiEntity.setPaths(null);
apiEntity.setProxy(proxy);
ResponseTemplate responseTemplate = new ResponseTemplate();
responseTemplate.setStatusCode(400);
responseTemplate.setBody("{\"bad\":\"news\"}");
apiEntity.setResponseTemplates(Collections.singletonMap("API_KEY_MISSING", Collections.singletonMap("*/*", responseTemplate)));
when(apiService.findById(API_ID)).thenReturn(apiEntity);
PageEntity folder = new PageEntity();
folder.setName("My Folder");
folder.setOrder(1);
folder.setType(PageType.FOLDER.toString());
folder.setVisibility(Visibility.PUBLIC);
PageEntity markdownPage = new PageEntity();
markdownPage.setName("My Title");
markdownPage.setOrder(1);
markdownPage.setType(PageType.MARKDOWN.toString());
markdownPage.setContent("Read the doc");
markdownPage.setVisibility(Visibility.PUBLIC);
PageEntity asideFolder = new PageEntity();
asideFolder.setName("Aside");
asideFolder.setOrder(1);
asideFolder.setPublished(true);
asideFolder.setType(PageType.SYSTEM_FOLDER.toString());
asideFolder.setVisibility(Visibility.PUBLIC);
PageEntity swaggerPage = new PageEntity();
swaggerPage.setName("My Swagger");
swaggerPage.setOrder(1);
swaggerPage.setType(PageType.SWAGGER.toString());
swaggerPage.setContent("Read the doc");
swaggerPage.setVisibility(Visibility.PUBLIC);
PageEntity linkPage = new PageEntity();
linkPage.setName("My Link");
linkPage.setOrder(1);
linkPage.setType(PageType.LINK.toString());
linkPage.setContent("Read the doc");
linkPage.setVisibility(Visibility.PUBLIC);
PageEntity translationPage = new PageEntity();
translationPage.setName("My Translation");
translationPage.setOrder(1);
translationPage.setType(PageType.TRANSLATION.toString());
translationPage.setContent("Lire la documentation");
translationPage.setVisibility(Visibility.PUBLIC);
PageEntity markdownTemplatePage = new PageEntity();
markdownTemplatePage.setName("My Template");
markdownTemplatePage.setOrder(1);
markdownTemplatePage.setType(PageType.MARKDOWN_TEMPLATE.toString());
markdownTemplatePage.setContent("Read the doc");
markdownTemplatePage.setVisibility(Visibility.PUBLIC);
PageEntity asciidocPage = new PageEntity();
asciidocPage.setName("My asciidoc");
asciidocPage.setOrder(1);
asciidocPage.setType(PageType.ASCIIDOC.toString());
asciidocPage.setContent("Read the asciidoc");
asciidocPage.setVisibility(Visibility.PUBLIC);
when(pageService.search(any(), eq(true), eq(GraviteeContext.getCurrentEnvironment()))).thenReturn(Arrays.asList(folder, markdownPage, swaggerPage, asideFolder, linkPage, translationPage, markdownTemplatePage, asciidocPage));
RoleEntity poRole = new RoleEntity();
poRole.setName("PRIMARY_OWNER");
poRole.setId("API_PRIMARY_OWNER");
MembershipEntity membership = new MembershipEntity();
membership.setMemberId("johndoe");
membership.setMemberType(MembershipMemberType.USER);
membership.setRoleId("API_PRIMARY_OWNER");
MemberEntity memberEntity = new MemberEntity();
memberEntity.setId(membership.getMemberId());
memberEntity.setType(membership.getMemberType());
memberEntity.setRoles(Collections.singletonList(poRole));
when(membershipService.getMembersByReference(eq(MembershipReferenceType.API), eq(API_ID))).thenReturn(Collections.singleton(memberEntity));
UserEntity userEntity = new UserEntity();
userEntity.setId(memberEntity.getId());
userEntity.setSource(userEntity.getId() + "-source");
userEntity.setSourceId(userEntity.getId() + "-sourceId");
when(userService.findById(memberEntity.getId())).thenReturn(userEntity);
PrimaryOwnerEntity primaryOwnerEntity = new PrimaryOwnerEntity();
primaryOwnerEntity.setDisplayName("johndoe-sourceId");
primaryOwnerEntity.setId("johndoe");
primaryOwnerEntity.setType(MembershipMemberType.USER.toString());
apiEntity.setPrimaryOwner(primaryOwnerEntity);
apiEntity.setGroups(Collections.singleton("my-group"));
GroupEntity groupEntity = new GroupEntity();
groupEntity.setId("my-group");
groupEntity.setName("My Group");
when(groupService.findByIds(apiEntity.getGroups())).thenReturn(Collections.singleton(groupEntity));
PlanEntity publishedPlan = new PlanEntity();
publishedPlan.setId("plan-id");
publishedPlan.setApi(API_ID);
publishedPlan.setDescription("free plan");
publishedPlan.setType(PlanType.API);
publishedPlan.setSecurity(PlanSecurityType.API_KEY);
publishedPlan.setValidation(PlanValidationType.AUTO);
publishedPlan.setStatus(PlanStatus.PUBLISHED);
Map<String, List<Rule>> paths = new HashMap<>();
io.gravitee.definition.model.Rule rule = new io.gravitee.definition.model.Rule();
rule.setEnabled(true);
rule.setMethods(Sets.newSet(HttpMethod.GET));
Policy policy = new Policy();
policy.setName("rate-limit");
String ls = System.lineSeparator();
policy.setConfiguration("{" + ls + " \"rate\": {" + ls + " \"limit\": 1," + ls + " \"periodTime\": 1," + ls + " \"periodTimeUnit\": \"SECONDS\"" + ls + " }" + ls + " }");
rule.setPolicy(policy);
paths.put("/", Collections.singletonList(rule));
publishedPlan.setPaths(paths);
PlanEntity closedPlan = new PlanEntity();
closedPlan.setId("closedPlan-id");
closedPlan.setApi(API_ID);
closedPlan.setDescription("free closedPlan");
closedPlan.setType(PlanType.API);
closedPlan.setSecurity(PlanSecurityType.API_KEY);
closedPlan.setValidation(PlanValidationType.AUTO);
closedPlan.setStatus(PlanStatus.CLOSED);
closedPlan.setPaths(paths);
Set<PlanEntity> set = new HashSet<>();
set.add(publishedPlan);
set.add(closedPlan);
when(planService.findByApi(API_ID)).thenReturn(set);
ApiMetadataEntity apiMetadataEntity = new ApiMetadataEntity();
apiMetadataEntity.setApiId(API_ID);
apiMetadataEntity.setKey("metadata-key");
apiMetadataEntity.setName("metadata-name");
apiMetadataEntity.setValue("metadata-value");
apiMetadataEntity.setDefaultValue("metadata-default-value");
apiMetadataEntity.setFormat(MetadataFormat.STRING);
when(apiMetadataService.findAllByApi(API_ID)).thenReturn(Collections.singletonList(apiMetadataEntity));
}
use of io.gravitee.rest.api.service.jackson.filter.ApiPermissionFilter in project gravitee-management-rest-api by gravitee-io.
the class ApiService_StopTest method setUp.
@Before
public void setUp() throws TechnicalException {
PropertyFilter apiMembershipTypeFilter = new ApiPermissionFilter();
objectMapper.setFilterProvider(new SimpleFilterProvider(Collections.singletonMap("apiMembershipTypeFilter", apiMembershipTypeFilter)));
UserEntity u = mock(UserEntity.class);
when(u.getId()).thenReturn("uid");
when(userService.findById(any())).thenReturn(u);
MembershipEntity po = mock(MembershipEntity.class);
when(membershipService.getPrimaryOwner(eq(io.gravitee.rest.api.model.MembershipReferenceType.API), anyString())).thenReturn(po);
when(api.getId()).thenReturn(API_ID);
}
Aggregations