Quantcast
Channel: Mobile - Couchbase Forums
Viewing all articles
Browse latest Browse all 1119

Data is visible from other channels for a user

$
0
0

I have created a user for sync gateway with access to a particular channel . However I am seeing that all the documents not marked for that channel are also visible. This is the sample sync-gatewaycofnig file that I have

  "samplebucket": {
	      "import_docs": "continuous",
	      "enable_shared_bucket_access":true,  
	      "bucket":"samplebucket",
	      "server": "http://localhost:8091",
	      "username": "sync_gateway",
	      "password": "password",
	      "num_index_replicas":0,
	      "users":{
		  "GUEST": {"disabled":true},
		  "user1": {"password": "password", "admin_channels": ["channel1"]}
	      },
	      "revs_limit": 20,
	      "sync": `function (doc, oldDoc) { 
		           if (doc.IsChannel1 == true) {
		           channel("Channel1");
		           }
		          else {
		          channel("ChannelX");
		          }
	      }`      
  }

I do see that the channels are assigned to individual documents in the sync gateway admin portal.
However when I run the following code, it prints all the documents in the bucket rather than just the documents from channel1:

    Endpoint targetEndpoint = new URLEndpoint(new URI(SYNC_GATEWAY_URL));
    ReplicatorConfiguration replConfig = new ReplicatorConfiguration(database, targetEndpoint);
    replConfig.setReplicatorType(ReplicatorConfiguration.ReplicatorType.PULL);
    replConfig.setContinuous(false);


    // Add authentication.
    replConfig.setAuthenticator(new BasicAuthenticator("user1", "password"));

    // Create replicator (be sure to hold a reference somewhere that will prevent the Replicator from being GCed)
    Replicator replicator = new Replicator(replConfig);

    // Listen to replicator change events.
    replicator.addChangeListener(change -> {
        if (change.getStatus().getError() != null) {
            System.err.println("Error code ::  " + change.getStatus().getError().getCode());
        }
    });

    // Start replication.
    replicator.start();

    // Check status of replication and wait till it is completed
    while (replicator.getStatus().getActivityLevel() != Replicator.ActivityLevel.STOPPED) {
        Thread.sleep(1000);
    }
// print query results from cb lite
    Query queryAll = QueryBuilder.select(SelectResult.expression(Meta.id))
            .from(DataSource.database(database));
    try {
        for (Result thisDoc : queryAll.execute()) {
            numRows++;
            System.out.println(String.format("%d ... Id: %s ",
                    numRows,
                    thisDoc.getString(Prop_Id)
            ));
        }
    } catch (CouchbaseLiteException e) {
        e.printStackTrace();
    }

1 post - 1 participant

Read full topic


Viewing all articles
Browse latest Browse all 1119

Trending Articles