[
https://issues.apache.org/jira/browse/RYA-119?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15703538#comment-15703538
]
ASF GitHub Bot commented on RYA-119:
------------------------------------
Github user isper3at commented on a diff in the pull request:
https://github.com/apache/incubator-rya/pull/124#discussion_r89907937
--- Diff:
dao/mongodb.rya/src/main/java/org/apache/rya/mongodb/document/visibility/VisibilityEvaluator.java
---
@@ -0,0 +1,152 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.rya.mongodb.document.visibility;
+
+import java.util.ArrayList;
+
+import org.apache.rya.mongodb.document.visibility.DocumentVisibility.Node;
+
+/**
+ * A class which evaluates visibility expressions against a set of
authorizations.
+ */
+public class VisibilityEvaluator {
+ private final AuthorizationContainer auths;
+
+ /**
+ * Creates a new {@link Authorizations} object with escaped forms of the
authorizations in the given object.
+ *
+ * @param auths
+ * original authorizations
+ * @return authorizations object with escaped authorization strings
+ * @see #escape(byte[], boolean)
+ */
+ static Authorizations escape(final Authorizations auths) {
+ final ArrayList<byte[]> retAuths = new
ArrayList<byte[]>(auths.getAuthorizations().size());
+
+ for (final byte[] auth : auths.getAuthorizations()) {
+ retAuths.add(escape(auth, false));
+ }
+
+ return new Authorizations(retAuths);
+ }
+
+ /**
+ * Properly escapes an authorization string. The string can be quoted if
desired.
+ *
+ * @param auth
+ * authorization string, as UTF-8 encoded bytes
+ * @param quote
+ * true to wrap escaped authorization in quotes
+ * @return escaped authorization string
+ */
+ public static byte[] escape(byte[] auth, final boolean quote) {
+ int escapeCount = 0;
+
+ for (final byte element : auth) {
+ if (element == '"' || element == '\\') {
+ escapeCount++;
+ }
+ }
+
+ if (escapeCount > 0 || quote) {
+ final byte[] escapedAuth = new byte[auth.length + escapeCount +
(quote ? 2 : 0)];
+ int index = quote ? 1 : 0;
+ for (final byte element : auth) {
+ if (element == '"' || element == '\\') {
+ escapedAuth[index++] = '\\';
+ }
+ escapedAuth[index++] = element;
+ }
+
+ if (quote) {
+ escapedAuth[0] = '"';
+ escapedAuth[escapedAuth.length - 1] = '"';
+ }
+
+ auth = escapedAuth;
+ }
+ return auth;
+ }
+
+// /**
--- End diff --
remove doc'd code
> Add visibility support to MongoDB
> ---------------------------------
>
> Key: RYA-119
> URL: https://issues.apache.org/jira/browse/RYA-119
> Project: Rya
> Issue Type: Improvement
> Components: dao
> Affects Versions: 3.2.10
> Reporter: Andrew Smith
> Assignee: Eric White
>
> Currently, when querying mongo, visibility is ignored. Need to add support
> for visibility when querying mongo.
--
This message was sent by Atlassian JIRA
(v6.3.4#6332)