use of io.gravitee.gateway.handlers.api.definition.Plan in project gravitee-gateway by gravitee-io.
the class SyncManager method convert.
private Plan convert(io.gravitee.repository.management.model.Plan repoPlan) {
Plan plan = new Plan();
plan.setId(repoPlan.getId());
plan.setName(repoPlan.getName());
plan.setApis(repoPlan.getApis());
plan.setSecurityDefinition(repoPlan.getSecurityDefinition());
if (repoPlan.getSecurity() != null) {
plan.setSecurity(repoPlan.getSecurity().name());
} else {
// TODO: must be handle by a migration script
plan.setSecurity("api_key");
}
try {
if (repoPlan.getDefinition() != null && !repoPlan.getDefinition().trim().isEmpty()) {
HashMap<String, Path> paths = objectMapper.readValue(repoPlan.getDefinition(), new TypeReference<HashMap<String, Path>>() {
});
plan.setPaths(paths);
}
} catch (IOException ioe) {
logger.error("Unexpected error while converting plan: {}", plan, ioe);
}
return plan;
}
use of io.gravitee.gateway.handlers.api.definition.Plan in project gravitee-gateway by gravitee-io.
the class AbstractGatewayTest method before.
@Override
public void before(Api api) {
// By default, add a keyless plan to the API
Plan plan = new Plan();
plan.setId("default_plan");
plan.setName("Default plan");
plan.setSecurity("key_less");
api.setPlans(Collections.singletonList(plan));
}
use of io.gravitee.gateway.handlers.api.definition.Plan in project gravitee-gateway by gravitee-io.
the class PlanBasedAuthenticationHandlerEnhancerTest method shouldResolveKeylessPolicy_becauseOnePlanKeyless.
@Test
public void shouldResolveKeylessPolicy_becauseOnePlanKeyless() {
AuthenticationHandler authenticationHandler = mock(AuthenticationHandler.class);
when(authenticationHandler.name()).thenReturn("keyless");
Plan plan1 = new Plan();
plan1.setSecurity("keyless");
when(api.getPlans()).thenReturn(Collections.singletonList(plan1));
List<AuthenticationHandler> SecurityProviders = authenticationHandlerEnhancer.filter(Collections.singletonList(authenticationHandler));
assertNotNull(SecurityProviders);
assertFalse(SecurityProviders.isEmpty());
assertEquals("keyless", SecurityProviders.iterator().next().name());
}
use of io.gravitee.gateway.handlers.api.definition.Plan in project gravitee-gateway by gravitee-io.
the class PlanBasedAuthenticationHandlerEnhancerTest method shouldNotResolveKeylessPolicy_becauseOnePlanApikey.
@Test
public void shouldNotResolveKeylessPolicy_becauseOnePlanApikey() {
AuthenticationHandler authenticationHandler = mock(AuthenticationHandler.class);
when(authenticationHandler.name()).thenReturn("keyless");
Plan plan1 = new Plan();
plan1.setSecurity("apikey");
when(api.getPlans()).thenReturn(Collections.singletonList(plan1));
List<AuthenticationHandler> SecurityProviders = authenticationHandlerEnhancer.filter(Collections.singletonList(authenticationHandler));
assertNotNull(SecurityProviders);
assertTrue(SecurityProviders.isEmpty());
}
use of io.gravitee.gateway.handlers.api.definition.Plan in project gravitee-gateway by gravitee-io.
the class ApiManagerImpl method update.
@Override
public void update(Api api) {
MDC.put("api", api.getId());
logger.info("Updating {}", api);
if (!api.getPlans().isEmpty()) {
logger.info("Deploying {} plan(s) for API {}:", api.getPlans().size(), api.getId());
for (Plan plan : api.getPlans()) {
logger.info("\t- {}", plan.getName());
}
try {
validator.validate(api);
apis.put(api.getId(), api);
eventManager.publishEvent(ReactorEvent.UPDATE, api);
} catch (ValidationException ve) {
logger.error("API {} can't be updated because of validation errors", api, ve);
}
} else {
logger.warn("There is no published plan associated to this API, undeploy it...");
undeploy(api.getId());
}
MDC.remove("api");
}
Aggregations