Search in sources :

Example 1 with Activity

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;
}
Also used : AuthTokenHelper(org.eclipse.hono.service.auth.AuthTokenHelper) AuthoritiesImpl(org.eclipse.hono.auth.AuthoritiesImpl) Autowired(org.springframework.beans.factory.annotation.Autowired) HashMap(java.util.HashMap) HonoUser(org.eclipse.hono.auth.HonoUser) ArrayList(java.util.ArrayList) AuthenticationConstants(org.eclipse.hono.service.auth.AuthenticationConstants) Service(org.springframework.stereotype.Service) Map(java.util.Map) Qualifier(org.springframework.beans.factory.annotation.Qualifier) JsonObject(io.vertx.core.json.JsonObject) AsyncResult(io.vertx.core.AsyncResult) Resource(org.springframework.core.io.Resource) UTF_8(java.nio.charset.StandardCharsets.UTF_8) IOException(java.io.IOException) Reader(java.io.Reader) Instant(java.time.Instant) Activity(org.eclipse.hono.auth.Activity) InputStreamReader(java.io.InputStreamReader) Profile(org.springframework.context.annotation.Profile) Future(io.vertx.core.Future) FileNotFoundException(java.io.FileNotFoundException) Objects(java.util.Objects) JsonArray(io.vertx.core.json.JsonArray) List(java.util.List) AbstractHonoAuthenticationService(org.eclipse.hono.service.auth.AbstractHonoAuthenticationService) Handler(io.vertx.core.Handler) Authorities(org.eclipse.hono.auth.Authorities) JsonArray(io.vertx.core.json.JsonArray) AuthoritiesImpl(org.eclipse.hono.auth.AuthoritiesImpl) ArrayList(java.util.ArrayList) JsonObject(io.vertx.core.json.JsonObject) Activity(org.eclipse.hono.auth.Activity)

Aggregations

AsyncResult (io.vertx.core.AsyncResult)1 Future (io.vertx.core.Future)1 Handler (io.vertx.core.Handler)1 JsonArray (io.vertx.core.json.JsonArray)1 JsonObject (io.vertx.core.json.JsonObject)1 FileNotFoundException (java.io.FileNotFoundException)1 IOException (java.io.IOException)1 InputStreamReader (java.io.InputStreamReader)1 Reader (java.io.Reader)1 UTF_8 (java.nio.charset.StandardCharsets.UTF_8)1 Instant (java.time.Instant)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1 Objects (java.util.Objects)1 Activity (org.eclipse.hono.auth.Activity)1 Authorities (org.eclipse.hono.auth.Authorities)1 AuthoritiesImpl (org.eclipse.hono.auth.AuthoritiesImpl)1 HonoUser (org.eclipse.hono.auth.HonoUser)1