org.sfs.SfsRequest - java examples

Here are the examples of the java api org.sfs.SfsRequest taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

123 Examples 7

19 View Complete Implementation : ValidateActionObjectCreate.java
Copyright Apache License 2.0
Author : pitchpoint-solutions
public clreplaced ValidateActionObjectCreate implements Func1<TransientVersion, Observable<TransientVersion>> {

    private final SfsRequest sfsRequest;

    public ValidateActionObjectCreate(SfsRequest sfsRequest) {
        this.sfsRequest = sfsRequest;
    }

    @Override
    public Observable<TransientVersion> call(TransientVersion version) {
        AuthProviderService authProvider = sfsRequest.vertxContext().verticle().authProviderService();
        return authProvider.canObjectCreate(sfsRequest, version).map(canDo -> {
            if (!canDo) {
                JsonObject jsonObject = new JsonObject().put("message", "Object Create Forbidden");
                throw new HttpRequestValidationException(HTTP_FORBIDDEN, jsonObject);
            }
            return version;
        });
    }
}

19 View Complete Implementation : SimpleAuthProvider.java
Copyright Apache License 2.0
Author : pitchpoint-solutions
@Override
public Observable<Boolean> canAccountCreate(SfsRequest sfsRequest, TransientAccount account) {
    return aVoid().map(aVoid -> isAdmin(sfsRequest));
}

19 View Complete Implementation : SimpleAuthProvider.java
Copyright Apache License 2.0
Author : pitchpoint-solutions
@Override
public Observable<Void> authenticate(SfsRequest sfsRequest) {
    return aVoid().doOnNext(aVoid -> {
        UserAndRole userAndRole = getUserByCredentials(sfsRequest);
        sfsRequest.setUserAndRole(userAndRole);
    });
}

19 View Complete Implementation : ValidateActionContainerDelete.java
Copyright Apache License 2.0
Author : pitchpoint-solutions
public clreplaced ValidateActionContainerDelete implements Func1<PersistentContainer, Observable<PersistentContainer>> {

    private final SfsRequest sfsRequest;

    public ValidateActionContainerDelete(SfsRequest sfsRequest) {
        this.sfsRequest = sfsRequest;
    }

    @Override
    public Observable<PersistentContainer> call(PersistentContainer container) {
        AuthProviderService authProvider = sfsRequest.vertxContext().verticle().authProviderService();
        return authProvider.canContainerDelete(sfsRequest, container).map(canDo -> {
            if (!canDo) {
                JsonObject jsonObject = new JsonObject().put("message", "Container Delete Forbidden");
                throw new HttpRequestValidationException(HTTP_FORBIDDEN, jsonObject);
            }
            return container;
        });
    }
}

19 View Complete Implementation : HeadAccount.java
Copyright Apache License 2.0
Author : pitchpoint-solutions
@Override
public void handle(final SfsRequest httpServerRequest) {
    aVoid().flatMap(new Authenticate(httpServerRequest)).flatMap(new ValidateActionAdmin(httpServerRequest)).map(aVoid -> fromSfsRequest(httpServerRequest)).map(new ValidateAccountPath()).map(objectPath -> objectPath.accountPath().get()).flatMap(new LoadAccount(httpServerRequest.vertxContext())).map(new ValidatePersistentAccountExists()).flatMap(new Func1<PersistentAccount, Observable<PersistentAccount>>() {

        @Override
        public Observable<PersistentAccount> call(final PersistentAccount persistentAccount) {
            httpServerRequest.params().set(LIMIT, "0");
            return just(persistentAccount).flatMap(new ListContainers(httpServerRequest)).map(containerList -> {
                HttpServerResponse httpServerResponse = httpServerRequest.response();
                httpServerResponse.putHeader(X_ACCOUNT_OBJECT_COUNT, valueOf(containerList.getObjectCount()));
                httpServerResponse.putHeader(X_ACCOUNT_CONTAINER_COUNT, valueOf(containerList.getContainerCount()));
                httpServerResponse.putHeader(X_ACCOUNT_BYTES_USED, BigDecimal.valueOf(containerList.getBytesUsed()).setScale(0, ROUND_HALF_UP).toString());
                return persistentAccount;
            });
        }
    }).single().subscribe(new ConnectionCloseTerminus<PersistentAccount>(httpServerRequest) {

        @Override
        public void onNext(PersistentAccount account) {
            HttpServerResponse httpServerResponse = httpServerRequest.response();
            Metadata metadata = account.getMetadata();
            for (String key : metadata.keySet()) {
                SortedSet<String> values = metadata.get(key);
                if (values != null && !values.isEmpty()) {
                    httpServerResponse.putHeader(format("%s%s", X_ADD_ACCOUNT_META_PREFIX, key), values);
                }
            }
            httpServerResponse.setStatusCode(HTTP_NO_CONTENT);
        }
    });
}

19 View Complete Implementation : SimpleAuthProvider.java
Copyright Apache License 2.0
Author : pitchpoint-solutions
protected boolean isAdmin(SfsRequest sfsRequest) {
    UserAndRole userAndRole = sfsRequest.getUserAndRole();
    return userAndRole != null && ADMIN.equals(userAndRole.getRole());
}

19 View Complete Implementation : Account.java
Copyright Apache License 2.0
Author : pitchpoint-solutions
public T merge(SfsRequest httpServerRequest) {
    MultiMap headers = httpServerRequest.headers();
    metadata.withHttpHeaders(headers);
    return (T) this;
}

19 View Complete Implementation : AuthProviderService.java
Copyright Apache License 2.0
Author : pitchpoint-solutions
public Observable<Boolean> canContainerListObjects(SfsRequest sfsRequest, PersistentContainer version) {
    return selectWithHighestPriority().canContainerListObjects(sfsRequest, version);
}

19 View Complete Implementation : ListObjects.java
Copyright Apache License 2.0
Author : pitchpoint-solutions
public clreplaced ListObjects implements Func1<PersistentContainer, Observable<ObjectList>> {

    private static final Logger LOGGER = getLogger(ListObjects.clreplaced);

    private final SfsRequest sfsRequest;

    private final VertxContext<Server> vertxContext;

    public ListObjects(SfsRequest sfsRequest) {
        this.sfsRequest = sfsRequest;
        this.vertxContext = sfsRequest.vertxContext();
    }

    @Override
    public Observable<ObjectList> call(PersistentContainer container) {
        MultiMap queryParams = sfsRequest.params();
        Elasticsearch elasticSearch = vertxContext.verticle().elasticsearch();
        final String limit = queryParams.get(LIMIT);
        String marker = unescape(queryParams.get(MARKER));
        String endMarker = unescape(queryParams.get(END_MARKER));
        final String prefix = unescape(queryParams.get(PREFIX));
        final String delimiter = unescape(queryParams.get(DELIMITER));
        Integer parsedLimit = !isNullOrEmpty(limit) ? tryParse(limit) : valueOf(10000);
        parsedLimit = parsedLimit == null || parsedLimit < 0 || parsedLimit > 10000 ? 10000 : parsedLimit;
        String containerId = container.getId();
        String containerPrefix = containerId + ObjectPath.DELIMITER;
        if (!isNullOrEmpty(prefix)) {
            containerPrefix += prefix;
        }
        String objectIndex = elasticSearch.objectIndex(container.getName());
        final SearchRequestBuilder scrollRequest = elasticSearch.get().prepareSearch(objectIndex).setTypes(elasticSearch.defaultType()).addSort(DOC_FIELD_NAME, ASC).setScroll(timeValueMillis(elasticSearch.getDefaultScrollTimeout())).setTimeout(timeValueMillis(elasticSearch.getDefaultSearchTimeout() - 10)).setQuery(prefixQuery("_id", containerPrefix)).setSize(100);
        final Integer finalParsedLimit = parsedLimit;
        final NavigableMap<String, ListedObject> listedObjects = new TreeMap<>();
        return scan(container, prefix, delimiter, marker, endMarker, finalParsedLimit, elasticSearch, scrollRequest, listedObjects).map(aVoid -> new ObjectList(container, listedObjects.values())).onErrorResumeNext(throwable -> {
            if (containsException(IndexNotFoundException.clreplaced, throwable)) {
                return just(new ObjectList(container, emptyList()));
            } else {
                return error(throwable);
            }
        });
    }

    protected Observable<Void> scan(final PersistentContainer container, final String prefix, final String delimiter, final String marker, final String endMarker, final int limit, final Elasticsearch elasticsearch, final SearchRequestBuilder scrollRequest, final NavigableMap<String, ListedObject> listedObjects) {
        if (LOGGER.isDebugEnabled()) {
            LOGGER.debug(format("Search Request = %s", Jsonify.toString(scrollRequest)));
        }
        return elasticsearch.execute(vertxContext, scrollRequest, elasticsearch.getDefaultSearchTimeout()).map(Optional::get).flatMap(searchResponse -> {
            if (LOGGER.isDebugEnabled()) {
                LOGGER.debug(format("Search Response = %s", Jsonify.toString(searchResponse)));
            }
            SearchHits hits = searchResponse.getHits();
            for (ListedObject listedObject : toIterable(container, prefix, delimiter, marker, endMarker, hits)) {
                String id = listedObject.getName();
                ListedObject existing = listedObjects.get(id);
                if (existing == null) {
                    listedObjects.put(id, listedObject);
                } else {
                    existing.setLength(existing.getLength() + listedObject.getLength());
                }
                if (listedObjects.size() > limit) {
                    listedObjects.pollLastEntry();
                }
            }
            return scroll(container, prefix, delimiter, marker, endMarker, limit, elasticsearch, searchResponse.getScrollId(), listedObjects);
        });
    }

    protected Observable<Void> scroll(final PersistentContainer container, final String prefix, final String delimiter, final String marker, final String endMarker, final int limit, final Elasticsearch elasticsearch, final String scrollId, final NavigableMap<String, ListedObject> listedObjects) {
        SearchScrollRequestBuilder scrollRequest = elasticsearch.get().prepareSearchScroll(scrollId).setScroll(timeValueMillis(elasticsearch.getDefaultScrollTimeout()));
        if (LOGGER.isDebugEnabled()) {
            LOGGER.debug(format("Search Request = %s", Jsonify.toString(scrollRequest)));
        }
        return elasticsearch.execute(vertxContext, scrollRequest, elasticsearch.getDefaultSearchTimeout()).map(Optional::get).flatMap(searchResponse -> {
            if (LOGGER.isDebugEnabled()) {
                LOGGER.debug(format("Search Response = %s", Jsonify.toString(searchResponse)));
            }
            SearchHits hits = searchResponse.getHits();
            int numberOfHits = hits.getHits().length;
            if (numberOfHits > 0) {
                for (ListedObject listedObject : toIterable(container, prefix, delimiter, marker, endMarker, hits)) {
                    String id = listedObject.getName();
                    ListedObject existing = listedObjects.get(id);
                    if (existing == null) {
                        listedObjects.put(id, listedObject);
                    } else {
                        existing.setLength(existing.getLength() + listedObject.getLength());
                    }
                    if (listedObjects.size() > limit) {
                        listedObjects.pollLastEntry();
                    }
                }
                return scroll(container, prefix, delimiter, marker, endMarker, limit, elasticsearch, searchResponse.getScrollId(), listedObjects);
            } else {
                return clearScroll(elasticsearch, searchResponse.getScrollId());
            }
        });
    }

    protected Observable<Void> clearScroll(Elasticsearch elasticSearch, String scrollId) {
        ClearScrollRequestBuilder request = elasticSearch.get().prepareClearScroll().addScrollId(scrollId);
        return elasticSearch.execute(vertxContext, request, elasticSearch.getDefaultSearchTimeout()).onErrorResumeNext(throwable -> {
            LOGGER.warn("Handling Clear Scroll Error", throwable);
            return Defer.just(null);
        }).map(clearScrollResponseOptional -> null);
    }

    protected Iterable<ListedObject> toIterable(final PersistentContainer container, final String prefix, final String delimiter, final String marker, final String endMarker, SearchHits searchHits) {
        // container id looks like /account/container
        // object id looks like /account/container/a/b/c/1/2/3
        // which makes the start index of the object name is the length of the
        // container id + 1
        int objectNameStartIndex = container.getId().length() + DELIMITER_LENGTH;
        return Fluenreplacederable.from(searchHits).transform(searchHit -> {
            String objectId = searchHit.getId();
            objectId = objectId.substring(objectNameStartIndex, objectId.length());
            boolean trimmed = false;
            if (delimiter != null) {
                int prefixLength = prefix != null ? prefix.length() : 0;
                int objectIdLength = objectId.length();
                if (objectIdLength > prefixLength) {
                    int indexOfDelimiter = objectId.indexOf(delimiter, prefixLength);
                    if (indexOfDelimiter <= objectIdLength && indexOfDelimiter >= 0) {
                        objectId = objectId.substring(0, indexOfDelimiter);
                        trimmed = true;
                    }
                }
            }
            boolean isInRange = (marker == null || objectId.compareTo(marker) > 0) && (endMarker == null || objectId.compareTo(endMarker) < 0);
            if (isInRange) {
                PersistentObject persistentObject = fromSearchHit(container, searchHit);
                Optional<TransientVersion> oTransientVersion = persistentObject.getNewestVersion();
                if (oTransientVersion.isPresent()) {
                    TransientVersion transientVersion = oTransientVersion.get();
                    boolean finalTrimmed = trimmed;
                    String finalObjectId = objectId;
                    // TODO clean this up!. Make GET object and HEAD object share the same logic
                    try {
                        new ValidateVersionNotDeleted().call(transientVersion);
                        new ValidateVersionNotDeleteMarker().call(transientVersion);
                        new ValidateVersionNotExpired().call(transientVersion);
                        new ValidateVersionHreplacedegments().call(transientVersion);
                        new ValidateVersionSegmentsHasData().call(transientVersion);
                        new ValidateVersionIsReadable().call(transientVersion);
                    } catch (HttpRequestValidationException e) {
                        LOGGER.debug("Version " + transientVersion.getId() + " failed validation", e);
                        return null;
                    }
                    Optional<byte[]> oEtag = transientVersion.calculateMd5();
                    Calendar lastModified = transientVersion.getUpdateTs();
                    Optional<Long> oContentLength = transientVersion.calculateLength();
                    Optional<String> oContentType = transientVersion.getContentType();
                    ListedObject listedObject = new ListedObject(finalObjectId);
                    if (oEtag.isPresent()) {
                        listedObject.setEtag(oEtag.get());
                    } else {
                        listedObject.setEtag(EMPTY_MD5);
                    }
                    listedObject.setLastModified(lastModified);
                    if (finalTrimmed) {
                        listedObject.setContentType("application/directory");
                    } else if (oContentType.isPresent()) {
                        listedObject.setContentType(oContentType.get());
                    } else {
                        listedObject.setContentType(OCTET_STREAM.toString());
                    }
                    if (oContentLength.isPresent()) {
                        listedObject.setLength(oContentLength.get());
                    } else {
                        listedObject.setLength(0);
                    }
                    return listedObject;
                }
            }
            return null;
        }).filter(Predicates.notNull());
    }

    public static clreplaced ListedObject {

        private byte[] etag;

        private Calendar lastModified;

        private long length;

        private String contentType;

        private final String name;

        public ListedObject(String name) {
            this.name = name;
        }

        public void setEtag(byte[] etag) {
            this.etag = etag;
        }

        public void setLastModified(Calendar lastModified) {
            this.lastModified = lastModified;
        }

        public void setLength(long length) {
            this.length = length;
        }

        public void setContentType(String contentType) {
            this.contentType = contentType;
        }

        public byte[] getEtag() {
            return etag;
        }

        public Calendar getLastModified() {
            return lastModified;
        }

        public long getLength() {
            return length;
        }

        public String getContentType() {
            return contentType;
        }

        public String getName() {
            return name;
        }

        @Override
        public boolean equals(Object o) {
            if (this == o)
                return true;
            if (!(o instanceof ListedObject))
                return false;
            ListedObject that = (ListedObject) o;
            return name != null ? name.equals(that.name) : that.name == null;
        }

        @Override
        public int hashCode() {
            return name != null ? name.hashCode() : 0;
        }
    }
}

19 View Complete Implementation : SimpleAuthProvider.java
Copyright Apache License 2.0
Author : pitchpoint-solutions
@Override
public Observable<Boolean> canAccountUpdate(SfsRequest sfsRequest, PersistentAccount account) {
    return aVoid().map(aVoid -> isAdmin(sfsRequest));
}

19 View Complete Implementation : ValidateActionAuthenticated.java
Copyright Apache License 2.0
Author : pitchpoint-solutions
public clreplaced ValidateActionAuthenticated implements Func1<Void, Observable<Void>> {

    private final SfsRequest sfsRequest;

    public ValidateActionAuthenticated(SfsRequest sfsRequest) {
        this.sfsRequest = sfsRequest;
    }

    @Override
    public Observable<Void> call(Void aVoid) {
        AuthProviderService authProvider = sfsRequest.vertxContext().verticle().authProviderService();
        return authProvider.isAuthenticated(sfsRequest).map(isAuthenticated -> {
            if (!isAuthenticated) {
                JsonObject jsonObject = new JsonObject().put("message", "Action Forbidden");
                throw new HttpRequestValidationException(HTTP_FORBIDDEN, jsonObject);
            }
            return null;
        });
    }
}

19 View Complete Implementation : KeptAliveTerminus.java
Copyright Apache License 2.0
Author : pitchpoint-solutions
public abstract clreplaced KeptAliveTerminus extends Subscriber<SfsRequest> {

    private static final Logger LOGGER = getLogger(KeptAliveTerminus.clreplaced);

    private final SfsRequest httpServerRequest;

    public KeptAliveTerminus(SfsRequest httpServerRequest) {
        this.httpServerRequest = httpServerRequest;
    }

    @Override
    public void onCompleted() {
        httpServerRequest.response().end();
    }

    @Override
    public void onError(Throwable e) {
        JsonObject doreplacedent = new JsonObject();
        HttpServerResponse response = httpServerRequest.response();
        if (e instanceof HttpRequestValidationException) {
            HttpRequestValidationException cause = (HttpRequestValidationException) e;
            JsonObject enreplacedy = cause.getEnreplacedy();
            int status = cause.getStatusCode();
            LOGGER.debug("Validate Error", e);
            doreplacedent.put("status", status).put("message", enreplacedy.encode());
        } else if (e instanceof HttpStatusCodeException) {
            HttpStatusCodeException cause = (HttpStatusCodeException) e;
            LOGGER.debug("HttpStatusCode Error", e);
            doreplacedent.put("status", cause.getStatusCode());
        } else {
            LOGGER.error("Unhandled Exception", e);
            doreplacedent.put("status", HTTP_INTERNAL_ERROR);
        }
        response.end(doreplacedent.encode(), UTF_8.toString());
    }
}

19 View Complete Implementation : SimpleAuthProvider.java
Copyright Apache License 2.0
Author : pitchpoint-solutions
@Override
public Observable<Boolean> canAccountDelete(SfsRequest sfsRequest, PersistentAccount account) {
    return aVoid().map(aVoid -> isAdmin(sfsRequest));
}

19 View Complete Implementation : ValidateActionContainerRead.java
Copyright Apache License 2.0
Author : pitchpoint-solutions
public clreplaced ValidateActionContainerRead implements Func1<PersistentContainer, Observable<PersistentContainer>> {

    private final SfsRequest sfsRequest;

    public ValidateActionContainerRead(SfsRequest sfsRequest) {
        this.sfsRequest = sfsRequest;
    }

    @Override
    public Observable<PersistentContainer> call(PersistentContainer container) {
        AuthProviderService authProvider = sfsRequest.vertxContext().verticle().authProviderService();
        return authProvider.canContainerRead(sfsRequest, container).map(canDo -> {
            if (!canDo) {
                JsonObject jsonObject = new JsonObject().put("message", "Container Read Forbidden");
                throw new HttpRequestValidationException(HTTP_FORBIDDEN, jsonObject);
            }
            return container;
        });
    }
}

19 View Complete Implementation : AuthProviderService.java
Copyright Apache License 2.0
Author : pitchpoint-solutions
public Observable<Boolean> isAuthenticated(SfsRequest sfsRequest) {
    return selectWithHighestPriority().isAuthenticated(sfsRequest);
}

19 View Complete Implementation : ValidateActionObjectRead.java
Copyright Apache License 2.0
Author : pitchpoint-solutions
public clreplaced ValidateActionObjectRead implements Func1<TransientVersion, Observable<TransientVersion>> {

    private final SfsRequest sfsRequest;

    public ValidateActionObjectRead(SfsRequest sfsRequest) {
        this.sfsRequest = sfsRequest;
    }

    @Override
    public Observable<TransientVersion> call(TransientVersion version) {
        AuthProviderService authProvider = sfsRequest.vertxContext().verticle().authProviderService();
        return authProvider.canObjectRead(sfsRequest, version).map(canDo -> {
            if (!canDo) {
                JsonObject jsonObject = new JsonObject().put("message", "Object Read Forbidden");
                throw new HttpRequestValidationException(HTTP_FORBIDDEN, jsonObject);
            }
            return version;
        });
    }
}

19 View Complete Implementation : SimpleAuthProvider.java
Copyright Apache License 2.0
Author : pitchpoint-solutions
protected boolean isAdminOrUser(SfsRequest sfsRequest) {
    UserAndRole userAndRole = sfsRequest.getUserAndRole();
    return userAndRole != null && (ADMIN.equals(userAndRole.getRole()) || USER.equals(userAndRole.getRole()));
}

19 View Complete Implementation : TransientAccount.java
Copyright Apache License 2.0
Author : pitchpoint-solutions
public static TransientAccount fromSfsRequest(SfsRequest httpServerRequest) {
    ObjectPath objectPath = ObjectPath.fromSfsRequest(httpServerRequest);
    return new TransientAccount(objectPath.accountPath().get()).merge(httpServerRequest);
}

19 View Complete Implementation : AuthProviderService.java
Copyright Apache License 2.0
Author : pitchpoint-solutions
public Observable<Boolean> canAccountCreate(SfsRequest sfsRequest, TransientAccount version) {
    return selectWithHighestPriority().canAccountCreate(sfsRequest, version);
}

19 View Complete Implementation : SimpleAuthProvider.java
Copyright Apache License 2.0
Author : pitchpoint-solutions
protected UserAndRole getUserByCredentials(SfsRequest sfsRequest) {
    MultiMap headers = sfsRequest.headers();
    Optional<String> oToken;
    if (headers.contains(X_AUTH_TOKEN)) {
        oToken = fromNullable(headers.get(X_AUTH_TOKEN));
    } else if (headers.contains(AUTHORIZATION)) {
        oToken = extractToken(headers.get(AUTHORIZATION), "Basic");
    } else {
        oToken = absent();
    }
    if (oToken.isPresent()) {
        String token = oToken.get();
        String decoded = new String(base64().decode(token), StandardCharsets.UTF_8);
        String[] parts = toArray(on(':').limit(2).split(decoded), String.clreplaced);
        if (parts.length == 2) {
            String username = parts[0];
            String preplacedword = parts[1];
            for (Role role : new Role[] { ADMIN, USER }) {
                Set<User> usersForRole = this.roles.get(role);
                if (usersForRole != null) {
                    for (User user : usersForRole) {
                        if (equal(user.getUsername(), username) && equal(user.getPreplacedword(), preplacedword)) {
                            return new UserAndRole(role, user);
                        }
                    }
                }
            }
        }
    }
    return null;
}

19 View Complete Implementation : SimpleAuthProvider.java
Copyright Apache License 2.0
Author : pitchpoint-solutions
@Override
public Observable<Boolean> isAuthenticated(SfsRequest sfsRequest) {
    return just(sfsRequest.getUserAndRole() != null);
}

19 View Complete Implementation : RefreshIndex.java
Copyright Apache License 2.0
Author : pitchpoint-solutions
@Override
public void handle(SfsRequest sfsRequest) {
    aVoid().flatMap(new IndexRefresh(sfsRequest.vertxContext())).subscribe(new Terminus<Void>(sfsRequest) {

        @Override
        public void onNext(Void aVoid) {
            sfsRequest.response().setStatusCode(HTTP_OK);
        }
    });
}

19 View Complete Implementation : Authenticate.java
Copyright Apache License 2.0
Author : pitchpoint-solutions
public clreplaced Authenticate implements Func1<Void, Observable<Void>> {

    private final SfsRequest sfsRequest;

    public Authenticate(SfsRequest sfsRequest) {
        this.sfsRequest = sfsRequest;
    }

    @Override
    public Observable<Void> call(Void aVoid) {
        AuthProviderService authProvider = sfsRequest.vertxContext().verticle().authProviderService();
        return authProvider.authenticate(sfsRequest);
    }
}

19 View Complete Implementation : PostAccount.java
Copyright Apache License 2.0
Author : pitchpoint-solutions
@Override
public void handle(final SfsRequest httpServerRequest) {
    aVoid().flatMap(new Authenticate(httpServerRequest)).flatMap(new ValidateActionAdmin(httpServerRequest)).map(aVoid -> fromSfsRequest(httpServerRequest)).map(new ValidateAccountPath()).map(objectPath -> objectPath.accountPath().get()).flatMap(new LoadAccount(httpServerRequest.vertxContext())).flatMap(new Func1<Optional<PersistentAccount>, Observable<PersistentAccount>>() {

        @Override
        public Observable<PersistentAccount> call(Optional<PersistentAccount> oPersistentAccount) {
            if (oPersistentAccount.isPresent()) {
                PersistentAccount persistentAccount = oPersistentAccount.get();
                persistentAccount.merge(httpServerRequest);
                return just(persistentAccount).flatMap(new UpdateAccount(httpServerRequest.vertxContext())).map(new ValidateOptimisticAccountLock());
            } else {
                return just(TransientAccount.fromSfsRequest(httpServerRequest)).doOnNext(transientAccount -> {
                    VertxContext<Server> vertxContext = httpServerRequest.vertxContext();
                    Optional<TransientServiceDef> currentMaintainerNode = vertxContext.verticle().getClusterInfo().getCurrentMaintainerNode();
                    if (currentMaintainerNode.isPresent()) {
                        transientAccount.setNodeId(currentMaintainerNode.get().getId());
                    }
                }).flatMap(new PersistAccount(httpServerRequest.vertxContext())).map(new ValidateOptimisticAccountLock());
            }
        }
    }).single().subscribe(new ConnectionCloseTerminus<PersistentAccount>(httpServerRequest) {

        @Override
        public void onNext(PersistentAccount persistentAccount) {
            httpServerRequest.response().setStatusCode(HTTP_NO_CONTENT);
        }
    });
}

19 View Complete Implementation : SimpleAuthProvider.java
Copyright Apache License 2.0
Author : pitchpoint-solutions
@Override
public Observable<Boolean> canContainerDelete(SfsRequest sfsRequest, PersistentContainer container) {
    return aVoid().map(aVoid -> isAdminOrUser(sfsRequest));
}

19 View Complete Implementation : ValidateActionAdminOrSystem.java
Copyright Apache License 2.0
Author : pitchpoint-solutions
public clreplaced ValidateActionAdminOrSystem implements Func1<Void, Observable<Void>> {

    private final SfsRequest sfsRequest;

    public ValidateActionAdminOrSystem(SfsRequest sfsRequest) {
        this.sfsRequest = sfsRequest;
    }

    @Override
    public Observable<Void> call(Void aVoid) {
        Server verticle = sfsRequest.vertxContext().verticle();
        AuthProviderService authProvider = verticle.authProviderService();
        return authProvider.canAdmin(sfsRequest).map(canDo -> {
            if (!canDo) {
                MultiMap headers = sfsRequest.headers();
                if (headers.contains(X_SFS_REMOTE_NODE_TOKEN)) {
                    byte[] actualToken = null;
                    try {
                        actualToken = base64().decode(headers.get(X_SFS_REMOTE_NODE_TOKEN));
                    } catch (Throwable ignore) {
                    }
                    byte[] expectedToken = verticle.getRemoteNodeSecret();
                    if (Arrays.equals(expectedToken, actualToken)) {
                        // autenticated
                        return null;
                    }
                }
                JsonObject jsonObject = new JsonObject().put("message", "Admin and System Action Forbidden");
                throw new HttpRequestValidationException(HTTP_FORBIDDEN, jsonObject);
            }
            return null;
        });
    }
}

19 View Complete Implementation : Terminus.java
Copyright Apache License 2.0
Author : pitchpoint-solutions
public abstract clreplaced Terminus<T> extends Subscriber<T> {

    private static final Logger LOGGER = getLogger(Terminus.clreplaced);

    private final SfsRequest httpServerRequest;

    public Terminus(SfsRequest httpServerRequest) {
        this.httpServerRequest = httpServerRequest;
    }

    public SfsRequest getSfsRequest() {
        return httpServerRequest;
    }

    @Override
    public void onCompleted() {
        LOGGER.debug("Ended onComplete");
        try {
            HttpServerResponse response = httpServerRequest.response();
            response.end();
        } finally {
            try {
                httpServerRequest.resume();
            } catch (Throwable e) {
            // do nothing
            }
        }
    }

    @Override
    public void onError(Throwable e) {
        try {
            HttpServerResponse response = httpServerRequest.response();
            response.setChunked(true);
            if (containsException(HttpRequestValidationException.clreplaced, e)) {
                HttpRequestValidationException cause = unwrapCause(HttpRequestValidationException.clreplaced, e).get();
                JsonObject enreplacedy = cause.getEnreplacedy();
                int status = cause.getStatusCode();
                // if credentials weren't supplied send unauthorized instead
                // of forbidden
                if (status == HTTP_FORBIDDEN && !httpServerRequest.headers().contains(AUTHORIZATION) && !httpServerRequest.headers().contains(X_AUTH_TOKEN)) {
                    status = HTTP_UNAUTHORIZED;
                    if (!httpServerRequest.proxyKeepAliveStarted()) {
                        response.putHeader(WWW_AUTHENTICATE, "Basic realm=\"Helix\"");
                    }
                }
                if (LOGGER.isDebugEnabled()) {
                    LOGGER.debug("Validate Error " + httpServerRequest.path(), e);
                }
                HttpMethod method = httpServerRequest.method();
                if (Objects.equals(HEAD, method)) {
                    if (httpServerRequest.proxyKeepAliveStarted()) {
                        Buffer encoded = buffer(enreplacedy.encodePrettily(), UTF_8.toString()).appendBuffer(DELIMITER_BUFFER);
                        response.end(encoded);
                    } else {
                        Buffer encoded = buffer(enreplacedy.encodePrettily(), UTF_8.toString());
                        response.setStatusCode(status).write(encoded).end();
                    }
                } else {
                    if (httpServerRequest.proxyKeepAliveStarted()) {
                        Buffer encoded = buffer(enreplacedy.encodePrettily(), UTF_8.toString()).appendBuffer(DELIMITER_BUFFER);
                        response.end(encoded);
                    } else {
                        Buffer buffer = buffer(enreplacedy.encodePrettily(), UTF_8.toString());
                        response.setStatusCode(status).write(buffer).end();
                    }
                }
            } else if (containsException(HttpStatusCodeException.clreplaced, e)) {
                HttpStatusCodeException cause = unwrapCause(HttpStatusCodeException.clreplaced, e).get();
                int status = cause.getStatusCode();
                // if credentials weren't supplied send unauthorized instead
                // of forbidden
                if (status == HTTP_FORBIDDEN && !httpServerRequest.headers().contains(AUTHORIZATION) && !httpServerRequest.headers().contains(X_AUTH_TOKEN)) {
                    status = HTTP_UNAUTHORIZED;
                    if (!httpServerRequest.proxyKeepAliveStarted()) {
                        response.putHeader(WWW_AUTHENTICATE, "Basic realm=\"Helix\"");
                    }
                }
                LOGGER.error("HttpStatusCode Error " + httpServerRequest.path(), e);
                if (httpServerRequest.proxyKeepAliveStarted()) {
                    JsonObject jsonObject = new JsonObject().put("code", status);
                    Buffer encoded = buffer(jsonObject.encodePrettily(), UTF_8.toString()).appendBuffer(DELIMITER_BUFFER);
                    response.end(encoded);
                } else {
                    response.setStatusCode(status).end();
                }
            } else {
                LOGGER.error("Unhandled Exception " + httpServerRequest.path(), e);
                if (httpServerRequest.proxyKeepAliveStarted()) {
                    JsonObject jsonObject = new JsonObject().put("code", HTTP_INTERNAL_ERROR);
                    Buffer encoded = buffer(jsonObject.encode(), UTF_8.toString()).appendBuffer(DELIMITER_BUFFER);
                    response.end(encoded);
                } else {
                    response.setStatusCode(HTTP_INTERNAL_ERROR).end();
                }
            }
        } finally {
            try {
                httpServerRequest.resume();
            } catch (Throwable ex) {
            // do nothing
            }
        }
    }
}

19 View Complete Implementation : SimpleAuthProvider.java
Copyright Apache License 2.0
Author : pitchpoint-solutions
@Override
public Observable<Boolean> canContainerUpdate(SfsRequest sfsRequest, PersistentContainer container) {
    return aVoid().map(aVoid -> isAdminOrUser(sfsRequest));
}

19 View Complete Implementation : ValidateActionContainerCreate.java
Copyright Apache License 2.0
Author : pitchpoint-solutions
public clreplaced ValidateActionContainerCreate implements Func1<TransientContainer, Observable<TransientContainer>> {

    private final SfsRequest sfsRequest;

    public ValidateActionContainerCreate(SfsRequest sfsRequest) {
        this.sfsRequest = sfsRequest;
    }

    @Override
    public Observable<TransientContainer> call(TransientContainer container) {
        AuthProviderService authProvider = sfsRequest.vertxContext().verticle().authProviderService();
        return authProvider.canContainerCreate(sfsRequest, container).map(canDo -> {
            if (!canDo) {
                JsonObject jsonObject = new JsonObject().put("message", "Container Create Forbidden");
                throw new HttpRequestValidationException(HTTP_FORBIDDEN, jsonObject);
            }
            return container;
        });
    }
}

19 View Complete Implementation : AuthProviderService.java
Copyright Apache License 2.0
Author : pitchpoint-solutions
public Observable<Boolean> canContainerRead(SfsRequest sfsRequest, PersistentContainer version) {
    return selectWithHighestPriority().canContainerRead(sfsRequest, version);
}

19 View Complete Implementation : ValidateActionContainerListObjects.java
Copyright Apache License 2.0
Author : pitchpoint-solutions
public clreplaced ValidateActionContainerListObjects implements Func1<PersistentContainer, Observable<PersistentContainer>> {

    private final SfsRequest sfsRequest;

    public ValidateActionContainerListObjects(SfsRequest sfsRequest) {
        this.sfsRequest = sfsRequest;
    }

    @Override
    public Observable<PersistentContainer> call(PersistentContainer container) {
        AuthProviderService authProvider = sfsRequest.vertxContext().verticle().authProviderService();
        return authProvider.canContainerListObjects(sfsRequest, container).map(canDo -> {
            if (!canDo) {
                JsonObject jsonObject = new JsonObject().put("message", "Container List Objects Forbidden");
                throw new HttpRequestValidationException(HTTP_FORBIDDEN, jsonObject);
            }
            return container;
        });
    }
}

19 View Complete Implementation : SimpleAuthProvider.java
Copyright Apache License 2.0
Author : pitchpoint-solutions
@Override
public Observable<Boolean> canContainerRead(SfsRequest sfsRequest, PersistentContainer container) {
    return aVoid().map(aVoid -> isAdminOrUser(sfsRequest));
}

19 View Complete Implementation : ValidateActionContainerUpdate.java
Copyright Apache License 2.0
Author : pitchpoint-solutions
public clreplaced ValidateActionContainerUpdate implements Func1<PersistentContainer, Observable<PersistentContainer>> {

    private final SfsRequest sfsRequest;

    public ValidateActionContainerUpdate(SfsRequest sfsRequest) {
        this.sfsRequest = sfsRequest;
    }

    @Override
    public Observable<PersistentContainer> call(PersistentContainer persistentContainer) {
        AuthProviderService authProvider = sfsRequest.vertxContext().verticle().authProviderService();
        return authProvider.canContainerUpdate(sfsRequest, persistentContainer).map(canDo -> {
            if (!canDo) {
                JsonObject jsonObject = new JsonObject().put("message", "Container Update Forbidden");
                throw new HttpRequestValidationException(HTTP_FORBIDDEN, jsonObject);
            }
            return persistentContainer;
        });
    }
}

19 View Complete Implementation : AuthProviderService.java
Copyright Apache License 2.0
Author : pitchpoint-solutions
public Observable<Boolean> canContainerUpdate(SfsRequest sfsRequest, PersistentContainer container) {
    return selectWithHighestPriority().canContainerUpdate(sfsRequest, container);
}

19 View Complete Implementation : ValidateActionObjectDelete.java
Copyright Apache License 2.0
Author : pitchpoint-solutions
public clreplaced ValidateActionObjectDelete implements Func1<TransientVersion, Observable<TransientVersion>> {

    private final SfsRequest sfsRequest;

    public ValidateActionObjectDelete(SfsRequest sfsRequest) {
        this.sfsRequest = sfsRequest;
    }

    @Override
    public Observable<TransientVersion> call(TransientVersion version) {
        AuthProviderService authProvider = sfsRequest.vertxContext().verticle().authProviderService();
        return authProvider.canObjectDelete(sfsRequest, version).map(canDo -> {
            if (!canDo) {
                JsonObject jsonObject = new JsonObject().put("message", "Object Delete Forbidden");
                throw new HttpRequestValidationException(HTTP_FORBIDDEN, jsonObject);
            }
            return version;
        });
    }
}

19 View Complete Implementation : SimpleAuthProvider.java
Copyright Apache License 2.0
Author : pitchpoint-solutions
@Override
public Observable<Boolean> canAccountRead(SfsRequest sfsRequest, PersistentAccount account) {
    return aVoid().map(aVoid -> isAdmin(sfsRequest));
}

19 View Complete Implementation : ValidateActionObjectUpdate.java
Copyright Apache License 2.0
Author : pitchpoint-solutions
public clreplaced ValidateActionObjectUpdate implements Func1<TransientVersion, Observable<TransientVersion>> {

    private final SfsRequest sfsRequest;

    public ValidateActionObjectUpdate(SfsRequest sfsRequest) {
        this.sfsRequest = sfsRequest;
    }

    @Override
    public Observable<TransientVersion> call(TransientVersion version) {
        AuthProviderService authProvider = sfsRequest.vertxContext().verticle().authProviderService();
        return authProvider.canObjectUpdate(sfsRequest, version).map(canDo -> {
            if (!canDo) {
                JsonObject jsonObject = new JsonObject().put("message", "Object Update Forbidden");
                throw new HttpRequestValidationException(HTTP_FORBIDDEN, jsonObject);
            }
            return version;
        });
    }
}

19 View Complete Implementation : AuthProviderService.java
Copyright Apache License 2.0
Author : pitchpoint-solutions
public Observable<Boolean> canContainerDelete(SfsRequest sfsRequest, PersistentContainer version) {
    return selectWithHighestPriority().canContainerDelete(sfsRequest, version);
}

19 View Complete Implementation : ObjectPath.java
Copyright Apache License 2.0
Author : pitchpoint-solutions
public static ObjectPath fromSfsRequest(SfsRequest httpServerRequest) {
    return new ObjectPath(true, unescape(httpServerRequest.path()));
}

19 View Complete Implementation : SimpleAuthProvider.java
Copyright Apache License 2.0
Author : pitchpoint-solutions
@Override
public Observable<Boolean> canContainerListObjects(SfsRequest sfsRequest, PersistentContainer container) {
    return aVoid().map(aVoid -> isAdminOrUser(sfsRequest));
}

19 View Complete Implementation : TransientContainer.java
Copyright Apache License 2.0
Author : pitchpoint-solutions
public static TransientContainer fromSfsRequest(PersistentAccount persistentAccount, SfsRequest httpServerRequest) {
    ObjectPath objectPath = ObjectPath.fromSfsRequest(httpServerRequest);
    return new TransientContainer(persistentAccount, objectPath.containerPath().get()).merge(httpServerRequest).setOwnerGuid(null);
}

19 View Complete Implementation : AuthProviderService.java
Copyright Apache License 2.0
Author : pitchpoint-solutions
public Observable<Boolean> canAdmin(SfsRequest sfsRequest) {
    return selectWithHighestPriority().canAdmin(sfsRequest);
}

19 View Complete Implementation : AuthProviderService.java
Copyright Apache License 2.0
Author : pitchpoint-solutions
public Observable<Void> authenticate(SfsRequest sfsRequest) {
    return selectWithHighestPriority().authenticate(sfsRequest);
}

19 View Complete Implementation : AuthProviderService.java
Copyright Apache License 2.0
Author : pitchpoint-solutions
public void handleOpenstackKeystoneAuth(SfsRequest sfsRequest) {
    selectWithHighestPriority().handleOpenstackKeystoneAuth(sfsRequest);
}

19 View Complete Implementation : SimpleAuthProvider.java
Copyright Apache License 2.0
Author : pitchpoint-solutions
@Override
public Observable<Boolean> canAdmin(SfsRequest sfsRequest) {
    return aVoid().map(aVoid -> isAdmin(sfsRequest));
}

19 View Complete Implementation : ValidateActionAdmin.java
Copyright Apache License 2.0
Author : pitchpoint-solutions
public clreplaced ValidateActionAdmin implements Func1<Void, Observable<Void>> {

    private final SfsRequest sfsRequest;

    public ValidateActionAdmin(SfsRequest sfsRequest) {
        this.sfsRequest = sfsRequest;
    }

    @Override
    public Observable<Void> call(Void aVoid) {
        AuthProviderService authProvider = sfsRequest.vertxContext().verticle().authProviderService();
        return authProvider.canAdmin(sfsRequest).map(canDo -> {
            if (!canDo) {
                JsonObject jsonObject = new JsonObject().put("message", "Admin Action Forbidden");
                throw new HttpRequestValidationException(HTTP_FORBIDDEN, jsonObject);
            }
            return null;
        });
    }
}

18 View Complete Implementation : AuthProviderService.java
Copyright Apache License 2.0
Author : pitchpoint-solutions
public Observable<Boolean> canObjectCreate(SfsRequest sfsRequest, TransientVersion version) {
    return selectWithHighestPriority().canObjectCreate(sfsRequest, version);
}

18 View Complete Implementation : AuthProviderService.java
Copyright Apache License 2.0
Author : pitchpoint-solutions
public Observable<Boolean> canAccountRead(SfsRequest sfsRequest, PersistentAccount version) {
    return selectWithHighestPriority().canAccountRead(sfsRequest, version);
}

18 View Complete Implementation : AuthProviderService.java
Copyright Apache License 2.0
Author : pitchpoint-solutions
public Observable<Boolean> canObjectUpdate(SfsRequest sfsRequest, TransientVersion version) {
    return selectWithHighestPriority().canObjectUpdate(sfsRequest, version);
}

18 View Complete Implementation : AuthProviderService.java
Copyright Apache License 2.0
Author : pitchpoint-solutions
public Observable<Boolean> canObjectDelete(SfsRequest sfsRequest, TransientVersion version) {
    return selectWithHighestPriority().canObjectDelete(sfsRequest, version);
}