Skip to content

Commit

Permalink
Merge branch 'release/0.10.0'
Browse files Browse the repository at this point in the history
Conflicts:
	pom.xml
  • Loading branch information
ujibang committed Feb 14, 2015
2 parents e5135b4 + a8a75cb commit ef43a94
Show file tree
Hide file tree
Showing 52 changed files with 715 additions and 884 deletions.
12 changes: 6 additions & 6 deletions etc/restheart-dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -109,12 +109,12 @@ application-logic-mounts:
# the provided default implementations of IDM and AM are SimpleFileIdentityManager and SimpleAccessManager.
# conf-file paths are either absolute (starting with /) or relative to the restheart.jar directory

#idm:
# implementation-class: org.restheart.security.impl.SimpleFileIdentityManager
# conf-file: ../etc/security.yml
#access-manager:
# implementation-class: org.restheart.security.impl.SimpleAccessManager
# conf-file: ../etc/security.yml
idm:
implementation-class: org.restheart.security.impl.SimpleFileIdentityManager
conf-file: ../etc/security.yml
access-manager:
implementation-class: org.restheart.security.impl.SimpleAccessManager
conf-file: ../etc/security.yml

# authentication token

Expand Down
22 changes: 16 additions & 6 deletions etc/security.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,27 @@ users:
roles: [users, admins]

permissions:
# users with role 'admins' can do anything
- role: admins
predicate: path-prefix[path="/"]


# not authenticated user can only GET any resource under the /publicdb URI
- role: $unauthenticated
predicate: path-prefix[path="/publicdb/"] and method[value="GET"]

- role: $unauthenticated
predicate: path[path="/integrationtestdb/coll1"] and method[value="GET"]


# users with role 'users' can GET any collection or document resource (excluding dbs)
- role: users
predicate: regex[pattern="/.*/.*", value="%R", full-match=true] and method[value="GET"]

# users with role 'users' can do anything on the collection /publicdb/{username}
- role: users
predicate: path-template[value="/publicdb/{username}"] and equals[%u, "${username}"]

# users with role 'users' can do anything on documents of the collection /publicdb/{username}
- role: users
predicate: path-prefix[path="/publicdb/{username}/"]
predicate: path-template[value="/publicdb/{username}/{doc}"] and equals[%u, "${username}"]

# same than previous one, but using regex predicate
# users with role 'users' can do anything on documents of the collection /publicdb/{username}
# - role: users
# predicate: regex[pattern="/publicdb/(.*?)/.*", value="%R", full-match=true] and equals[%u, "${1}"]
6 changes: 3 additions & 3 deletions nbactions.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<goal>org.codehaus.mojo:exec-maven-plugin:1.2.1:exec</goal>
</goals>
<properties>
<exec.args>-Xdock:name=RESTHeart -classpath %classpath org.restheart.Bootstrapper etc/restheart-integrationtest.yml</exec.args>
<exec.args>-Xdock:name=RESTHeart -classpath %classpath org.restheart.Bootstrapper etc/restheart-dev.yml</exec.args>
<exec.executable>java</exec.executable>
</properties>
</action>
Expand All @@ -24,7 +24,7 @@
<goal>org.codehaus.mojo:exec-maven-plugin:1.2.1:exec</goal>
</goals>
<properties>
<exec.args>-Xdebug -Xrunjdwp:transport=dt_socket,server=n,address=${jpda.address} -Xdock:name=RESTHeart -classpath %classpath org.restheart.Bootstrapper etc/restheart-integrationtest.yml</exec.args>
<exec.args>-Xdebug -Xrunjdwp:transport=dt_socket,server=n,address=${jpda.address} -Xdock:name=RESTHeart -classpath %classpath org.restheart.Bootstrapper etc/restheart-dev.yml</exec.args>
<exec.executable>java</exec.executable>
<jpda.listen>true</jpda.listen>
</properties>
Expand All @@ -39,7 +39,7 @@
<goal>org.codehaus.mojo:exec-maven-plugin:1.2.1:exec</goal>
</goals>
<properties>
<exec.args>-Xdock:name=RESTHeart -classpath %classpath org.restheart.Bootstrapper etc/restheart-integrationtest.yml</exec.args>
<exec.args>-Xdock:name=RESTHeart -classpath %classpath org.restheart.Bootstrapper etc/restheart-dev.yml</exec.args>
<exec.executable>java</exec.executable>
</properties>
</action>
Expand Down
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>org.restheart</groupId>
<artifactId>restheart</artifactId>
<version>0.10.0.RC</version>
<version>0.10.0</version>
<packaging>jar</packaging>
<name>Restheart</name>
<description>
Expand Down Expand Up @@ -89,7 +89,7 @@
<dependency>
<groupId>org.mongodb</groupId>
<artifactId>mongo-java-driver</artifactId>
<version>2.12.4</version>
<version>2.13.0</version>
</dependency>

<dependency>
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/org/restheart/Configuration.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public class Configuration {
/**
* URL pointing to the online documentation specific for this version.
*/
public static final String RESTHEART_ONLINE_DOC_URL = "http://www.restheart.org/docs/v0.9";
public static final String RESTHEART_ONLINE_DOC_URL = "http://www.restheart.org/docs/v0.10";

private static final Logger LOGGER = LoggerFactory.getLogger(Configuration.class);

Expand Down Expand Up @@ -602,8 +602,8 @@ public Configuration(final Path confFilePath, boolean silent) throws Configurati

List<Map<String, Object>> mongoServersDefault = new ArrayList<>();
Map<String, Object> defaultMongoServer = new HashMap<>();
defaultMongoServer.put(MONGO_HOST_KEY, "127.0.0.1");
defaultMongoServer.put(MONGO_PORT_KEY, 27017);
defaultMongoServer.put(MONGO_HOST_KEY, DEFAULT_MONGO_HOST);
defaultMongoServer.put(MONGO_PORT_KEY, DEFAULT_MONGO_PORT);
mongoServersDefault.add(defaultMongoServer);

mongoServers = getAsListOfMaps(conf, MONGO_SERVERS_KEY, mongoServersDefault);
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/org/restheart/Shutdowner.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ public class Shutdowner {
private static final Logger LOGGER = LoggerFactory.getLogger(Shutdowner.class);

public static void main(final String[] args) {
LOGGER.info("Shutdowner called...");

if (askingForHelp(args)) {
LOGGER.info("usage: java -cp restheart.jar org.restheart.Shutdowner [configuration file].");
LOGGER.info("shutdown --help\t\tprints this help message and exits.");
Expand Down
65 changes: 13 additions & 52 deletions src/main/java/org/restheart/db/CollectionDAO.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
import com.mongodb.util.JSONParseException;
import org.restheart.utils.HttpStatus;
import java.time.Instant;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Deque;
import org.bson.BSONObject;
Expand Down Expand Up @@ -148,14 +147,12 @@ DBCursor getCollectionDBCursor(DBCollection coll, Deque<String> sortBy, Deque<St
DBObject sort = new BasicDBObject();

if (sortBy == null || sortBy.isEmpty()) {
sort.put("_created_on", -1);
sort.put("_id", -1);
} else {
sortBy.stream().forEach((s) -> {

String _s = s.trim(); // the + sign is decoded into a space, in case remove it

_s = _s.replaceAll("_lastupdated_on", "_etag"); // _lastupdated is not stored and actually generated from @etag

if (_s.startsWith("-")) {
sort.put(_s.substring(1), -1);
} else if (_s.startsWith("+")) {
Expand Down Expand Up @@ -186,16 +183,11 @@ ArrayList<DBObject> getCollectionData(
int pagesize,
Deque<String> sortBy,
Deque<String> filters,
DBCursorPool.EAGER_CURSOR_ALLOCATION_POLICY eager,
boolean detectOids) throws JSONParseException {
DBCursorPool.EAGER_CURSOR_ALLOCATION_POLICY eager) throws JSONParseException {
ArrayList<DBObject> ret = new ArrayList<>();

int toskip = pagesize * (page - 1);

if (detectOids) {
filters = replaceObjectIdsInFilters(filters);
}

DBCursor cursor;
SkippedDBCursor _cursor = null;

Expand Down Expand Up @@ -224,13 +216,19 @@ ArrayList<DBObject> getCollectionData(
pagesize--;
}

// add the _lastupdated_on and _created_on
ret.forEach(row -> {
Object etag = row.get("_etag");

if (etag != null && ObjectId.isValid("" + etag)) {
ObjectId _etag = new ObjectId("" + etag);
if (row.get("_lastupdated_on") == null && etag != null && etag instanceof ObjectId) {
row.put("_lastupdated_on", Instant.ofEpochSecond(((ObjectId) etag).getTimestamp()).toString());
}

Object id = row.get("_id");

row.put("_lastupdated_on", Instant.ofEpochSecond(_etag.getTimestamp()).toString());
// generate the _created_on timestamp from the _id if this is an instance of ObjectId
if (row.get("_created_on") == null && id != null && id instanceof ObjectId) {
row.put("_created_on", Instant.ofEpochSecond(((ObjectId) id).getTimestamp()).toString());
}
}
);
Expand All @@ -255,10 +253,8 @@ public DBObject getCollectionProps(String dbName, String collName, boolean fixMi

Object etag = properties.get("_etag");

if (etag != null && ObjectId.isValid("" + etag)) {
ObjectId oid = new ObjectId("" + etag);

properties.put("_lastupdated_on", Instant.ofEpochSecond(oid.getTimestamp()).toString());
if (etag != null && etag instanceof ObjectId) {
properties.put("_lastupdated_on", Instant.ofEpochSecond(((ObjectId) etag).getTimestamp()).toString());
}
} else if (fixMissingProperties) {
new PropsFixer().addCollectionProps(dbName, collName);
Expand Down Expand Up @@ -388,40 +384,5 @@ int deleteCollection(String dbName, String collName, ObjectId etag) {
private void initDefaultIndexes(DBCollection coll) {
coll.createIndex(new BasicDBObject("_id", 1).append("_etag", 1), new BasicDBObject("name", "_id_etag_idx"));
coll.createIndex(new BasicDBObject("_etag", 1), new BasicDBObject("name", "_etag_idx"));
coll.createIndex(new BasicDBObject("_created_on", 1), new BasicDBObject("name", "_created_on_idx"));
}

private Deque<String> replaceObjectIdsInFilters(Deque<String> filters) {
if (filters == null) {
return null;
}

ArrayDeque<String> ret = new ArrayDeque<>();

filters.stream().forEach((filter) -> {
BSONObject _filter = (BSONObject) JSON.parse(filter);

replaceObjectIdsInFilters(_filter);

ret.add(_filter.toString());
});

return ret;
}

private void replaceObjectIdsInFilters(BSONObject source) {
if (source == null) {
return;
}

source.keySet().stream().forEach((key) -> {
Object value = source.get(key);

if (value instanceof BSONObject) {
replaceObjectIdsInFilters((BSONObject) value);
} else if (ObjectId.isValid(value.toString())) {
source.put(key, new ObjectId(value.toString()));
}
});
}
}
2 changes: 1 addition & 1 deletion src/main/java/org/restheart/db/DBCursorPool.java
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ private DBCursorPool(DbsDAO dbsDAO) {

public synchronized SkippedDBCursor get(DBCursorPoolEntryKey key, EAGER_CURSOR_ALLOCATION_POLICY allocationPolicy) {
if (key.getSkipped() < SKIP_SLICE_LINEAR_WIDTH) {
LOGGER.debug("no cursor to reuse found with skipped {} that is less than SKIP_SLICE_WIDTH {}", key.getSkipped(), SKIP_SLICE_LINEAR_WIDTH);
LOGGER.trace("no cursor to reuse found with skipped {} that is less than SKIP_SLICE_WIDTH {}", key.getSkipped(), SKIP_SLICE_LINEAR_WIDTH);
return null;
}

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/restheart/db/Database.java
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ public interface Database {
* @param detectObjectids
* @return Collection Data as ArrayList of DBObject
*/
ArrayList<DBObject> getCollectionData(DBCollection collection, int page, int pagesize, Deque<String> sortBy, Deque<String> filter, DBCursorPool.EAGER_CURSOR_ALLOCATION_POLICY cursorAllocationPolicy, boolean detectObjectids);
ArrayList<DBObject> getCollectionData(DBCollection collection, int page, int pagesize, Deque<String> sortBy, Deque<String> filter, DBCursorPool.EAGER_CURSOR_ALLOCATION_POLICY cursorAllocationPolicy);

/**
*
Expand Down
10 changes: 4 additions & 6 deletions src/main/java/org/restheart/db/DbsDAO.java
Original file line number Diff line number Diff line change
Expand Up @@ -160,10 +160,8 @@ public DBObject getDatabaseProperties(String dbName, boolean fixMissingPropertie

Object etag = row.get("_etag");

if (etag != null && ObjectId.isValid("" + etag)) {
ObjectId oid = new ObjectId("" + etag);

row.put("_lastupdated_on", Instant.ofEpochSecond(oid.getTimestamp()).toString());
if (etag != null && etag instanceof ObjectId) {
row.put("_lastupdated_on", Instant.ofEpochSecond(((ObjectId)etag).getTimestamp()).toString());
}
} else if (fixMissingProperties) {
new PropsFixer().addDbProps(dbName);
Expand Down Expand Up @@ -375,8 +373,8 @@ public long getCollectionSize(DBCollection coll, Deque<String> filters) {
}

@Override
public ArrayList<DBObject> getCollectionData(DBCollection coll, int page, int pagesize, Deque<String> sortBy, Deque<String> filter, DBCursorPool.EAGER_CURSOR_ALLOCATION_POLICY cursorAllocationPolicy, boolean detectObjectids) {
return collectionDAO.getCollectionData(coll, page, pagesize, sortBy, filter, cursorAllocationPolicy, detectObjectids);
public ArrayList<DBObject> getCollectionData(DBCollection coll, int page, int pagesize, Deque<String> sortBy, Deque<String> filter, DBCursorPool.EAGER_CURSOR_ALLOCATION_POLICY cursorAllocationPolicy) {
return collectionDAO.getCollectionData(coll, page, pagesize, sortBy, filter, cursorAllocationPolicy);
}

@Override
Expand Down
Loading

0 comments on commit ef43a94

Please sign in to comment.