Search in sources :

Example 1 with Wall

use of io.vertx.up.annotations.Wall in project vertx-zero by silentbalanceyh.

the class WallInquirer method scan.

@Override
public Set<Cliff> scan(final Set<Class<?>> walls) {
    /**
     * 1. Build result *
     */
    final Set<Cliff> wallSet = new TreeSet<>();
    final Set<Class<?>> wallClses = walls.stream().filter((item) -> item.isAnnotationPresent(Wall.class)).collect(Collectors.toSet());
    if (!wallClses.isEmpty()) {
        /**
         * It means that you have set Wall and enable security configuration
         * wallClses verification
         */
        final ConcurrentMap<String, Class<?>> keys = new ConcurrentHashMap<>();
        final JsonObject config = this.verify(wallClses, keys);
        for (final String field : config.fieldNames()) {
            // Difference key setting
            final Class<?> cls = keys.get(field);
            final Cliff cliff = this.transformer.transform(config.getJsonObject(field));
            // Set Information from class
            this.mountData(cliff, cls);
            wallSet.add(cliff);
        }
    }
    /**
     * 3. Transfer *
     */
    return wallSet;
}
Also used : Transformer(io.vertx.zero.marshal.Transformer) Ut(io.vertx.up.tool.Ut) Rampart(io.vertx.up.secure.Rampart) TreeSet(java.util.TreeSet) ConcurrentMap(java.util.concurrent.ConcurrentMap) HashSet(java.util.HashSet) Annal(io.vertx.up.log.Annal) Observable(io.reactivex.Observable) JsonObject(io.vertx.core.json.JsonObject) Node(io.vertx.zero.marshal.node.Node) WallKeyMissingException(io.vertx.zero.exception.WallKeyMissingException) PhylumAuth(io.vertx.up.secure.inquire.PhylumAuth) Fn(io.vertx.up.func.Fn) Cliff(io.vertx.up.atom.secure.Cliff) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) DynamicKeyMissingException(io.vertx.zero.exception.DynamicKeyMissingException) Set(java.util.Set) Collectors(java.util.stream.Collectors) Instance(io.vertx.up.tool.mirror.Instance) ZeroUniform(io.vertx.zero.marshal.node.ZeroUniform) Objects(java.util.Objects) OstiumAuth(io.vertx.up.secure.inquire.OstiumAuth) WallDuplicatedException(io.vertx.zero.exception.WallDuplicatedException) Annotation(java.lang.annotation.Annotation) Wall(io.vertx.up.annotations.Wall) Cliff(io.vertx.up.atom.secure.Cliff) TreeSet(java.util.TreeSet) JsonObject(io.vertx.core.json.JsonObject) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap)

Example 2 with Wall

use of io.vertx.up.annotations.Wall in project vertx-zero by silentbalanceyh.

the class WallInquirer method verify.

/**
 * @param wallClses
 * @param keysRef
 * @return
 */
private JsonObject verify(final Set<Class<?>> wallClses, final ConcurrentMap<String, Class<?>> keysRef) {
    /**
     * Wall duplicated *
     */
    final Set<String> hashs = new HashSet<>();
    Observable.fromIterable(wallClses).filter(Objects::nonNull).map(item -> {
        final Annotation annotation = item.getAnnotation(Wall.class);
        // Add configuration key into keys;
        keysRef.put(Instance.invoke(annotation, "value"), item);
        return this.hashPath(annotation);
    }).subscribe(hashs::add);
    // Duplicated adding.
    Fn.flingUp(hashs.size() != wallClses.size(), LOGGER, WallDuplicatedException.class, this.getClass(), wallClses.stream().map(Class::getName).collect(Collectors.toSet()));
    /**
     * Shared key does not existing *
     */
    final JsonObject config = NODE.read();
    Fn.flingUp(!config.containsKey(KEY), LOGGER, DynamicKeyMissingException.class, this.getClass(), KEY, config);
    /**
     * Wall key missing *
     */
    final JsonObject hitted = config.getJsonObject(KEY);
    for (final String key : keysRef.keySet()) {
        Fn.flingUp(null == hitted || !hitted.containsKey(key), LOGGER, WallKeyMissingException.class, this.getClass(), key, keysRef.get(key));
    }
    return hitted;
}
Also used : Transformer(io.vertx.zero.marshal.Transformer) Ut(io.vertx.up.tool.Ut) Rampart(io.vertx.up.secure.Rampart) TreeSet(java.util.TreeSet) ConcurrentMap(java.util.concurrent.ConcurrentMap) HashSet(java.util.HashSet) Annal(io.vertx.up.log.Annal) Observable(io.reactivex.Observable) JsonObject(io.vertx.core.json.JsonObject) Node(io.vertx.zero.marshal.node.Node) WallKeyMissingException(io.vertx.zero.exception.WallKeyMissingException) PhylumAuth(io.vertx.up.secure.inquire.PhylumAuth) Fn(io.vertx.up.func.Fn) Cliff(io.vertx.up.atom.secure.Cliff) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) DynamicKeyMissingException(io.vertx.zero.exception.DynamicKeyMissingException) Set(java.util.Set) Collectors(java.util.stream.Collectors) Instance(io.vertx.up.tool.mirror.Instance) ZeroUniform(io.vertx.zero.marshal.node.ZeroUniform) Objects(java.util.Objects) OstiumAuth(io.vertx.up.secure.inquire.OstiumAuth) WallDuplicatedException(io.vertx.zero.exception.WallDuplicatedException) Annotation(java.lang.annotation.Annotation) Wall(io.vertx.up.annotations.Wall) Wall(io.vertx.up.annotations.Wall) Objects(java.util.Objects) JsonObject(io.vertx.core.json.JsonObject) Annotation(java.lang.annotation.Annotation) HashSet(java.util.HashSet)

Aggregations

Observable (io.reactivex.Observable)2 JsonObject (io.vertx.core.json.JsonObject)2 Wall (io.vertx.up.annotations.Wall)2 Cliff (io.vertx.up.atom.secure.Cliff)2 Fn (io.vertx.up.func.Fn)2 Annal (io.vertx.up.log.Annal)2 Rampart (io.vertx.up.secure.Rampart)2 OstiumAuth (io.vertx.up.secure.inquire.OstiumAuth)2 PhylumAuth (io.vertx.up.secure.inquire.PhylumAuth)2 Ut (io.vertx.up.tool.Ut)2 Instance (io.vertx.up.tool.mirror.Instance)2 DynamicKeyMissingException (io.vertx.zero.exception.DynamicKeyMissingException)2 WallDuplicatedException (io.vertx.zero.exception.WallDuplicatedException)2 WallKeyMissingException (io.vertx.zero.exception.WallKeyMissingException)2 Transformer (io.vertx.zero.marshal.Transformer)2 Node (io.vertx.zero.marshal.node.Node)2 ZeroUniform (io.vertx.zero.marshal.node.ZeroUniform)2 Annotation (java.lang.annotation.Annotation)2 HashSet (java.util.HashSet)2 Objects (java.util.Objects)2