use of org.eclipse.hono.auth.Activity in project hono by eclipse.
the class FileBasedAuthenticationService method toAuthorities.
private Authorities toAuthorities(final JsonArray authorities) {
AuthoritiesImpl result = new AuthoritiesImpl();
Objects.requireNonNull(authorities).stream().filter(obj -> obj instanceof JsonObject).forEach(obj -> {
final JsonObject authSpec = (JsonObject) obj;
final JsonArray activities = authSpec.getJsonArray(FIELD_ACTIVITIES, new JsonArray());
final String resource = authSpec.getString(FIELD_RESOURCE);
final String operation = authSpec.getString(FIELD_OPERATION);
if (resource != null) {
List<Activity> activityList = new ArrayList<>();
activities.forEach(s -> {
Activity act = Activity.valueOf((String) s);
if (act != null) {
activityList.add(act);
}
});
result.addResource(resource, activityList.toArray(new Activity[activityList.size()]));
} else if (operation != null) {
String[] parts = operation.split(":", 2);
if (parts.length == 2) {
result.addOperation(parts[0], parts[1]);
} else {
log.debug("ignoring malformed operation spec [{}], operation name missing", operation);
}
} else {
throw new IllegalArgumentException("malformed authorities");
}
});
return result;
}
Aggregations