use of io.gravitee.definition.model.Rule in project gravitee-gateway by gravitee-io.
the class Api method policies.
private Set<Policy> policies() {
if (getPaths() == null)
return Collections.emptySet();
Set<io.gravitee.definition.model.Policy> policies = new HashSet<>();
// Load policies from the API
getPaths().values().forEach(path -> policies.addAll(path.getRules().stream().map(Rule::getPolicy).distinct().collect(Collectors.toSet())));
// Load policies from Plans
getPlans().forEach(plan -> {
String security = plan.getSecurity();
Policy secPolicy = new Policy();
switch(security) {
case "KEY_LESS":
case "key_less":
secPolicy.setName("key-less");
break;
case "API_KEY":
case "api_key":
secPolicy.setName("api-key");
break;
case "OAUTH2":
secPolicy.setName("oauth2");
break;
case "JWT":
secPolicy.setName("jwt");
break;
}
if (secPolicy.getName() != null) {
policies.add(secPolicy);
}
if (plan.getPaths() != null) {
plan.getPaths().values().forEach(path -> policies.addAll(path.getRules().stream().map(Rule::getPolicy).distinct().collect(Collectors.toSet())));
}
});
return policies;
}