Search in sources :

Example 6 with AuthenticateRequest

use of com.google.nigori.common.NigoriMessages.AuthenticateRequest in project nigori by ucam-cl-dtg.

the class DatabaseNigoriProtocol method getRevisions.

@Override
public GetRevisionsResponse getRevisions(GetRevisionsRequest request) throws IOException, NotFoundException, UnauthorisedException {
    byte[] index = request.getKey().toByteArray();
    AuthenticateRequest auth = request.getAuth();
    User user = authenticateUser(auth, MessageLibrary.REQUEST_GET_REVISIONS, index);
    Collection<byte[]> value = database.getRevisions(user, index);
    if (value == null) {
        throw new NotFoundException("Cannot find requested key");
    }
    return MessageLibrary.getRevisionsResponseAsProtobuf(value);
}
Also used : AuthenticateRequest(com.google.nigori.common.NigoriMessages.AuthenticateRequest) NotFoundException(com.google.nigori.common.NotFoundException)

Example 7 with AuthenticateRequest

use of com.google.nigori.common.NigoriMessages.AuthenticateRequest in project nigori by ucam-cl-dtg.

the class DatabaseNigoriProtocol method get.

@Override
public GetResponse get(GetRequest request) throws IOException, NotFoundException, UnauthorisedException {
    byte[] index = request.getKey().toByteArray();
    AuthenticateRequest auth = request.getAuth();
    User user;
    byte[] revision = null;
    if (request.hasRevision()) {
        revision = request.getRevision().toByteArray();
        user = authenticateUser(auth, MessageLibrary.REQUEST_GET, index, revision);
    } else {
        user = authenticateUser(auth, MessageLibrary.REQUEST_GET, index);
    }
    Collection<RevValue> value;
    if (request.hasRevision()) {
        value = new ArrayList<RevValue>(1);
        RevValue revVal = database.getRevision(user, index, revision);
        if (revVal == null) {
            throw new NotFoundException("Cannot find requested index with revision");
        }
        value.add(revVal);
    } else {
        value = database.getRecord(user, index);
    }
    if (value == null) {
        throw new NotFoundException("No value for that index");
    }
    return MessageLibrary.getResponseAsProtobuf(value);
}
Also used : AuthenticateRequest(com.google.nigori.common.NigoriMessages.AuthenticateRequest) RevValue(com.google.nigori.common.RevValue) NotFoundException(com.google.nigori.common.NotFoundException)

Aggregations

AuthenticateRequest (com.google.nigori.common.NigoriMessages.AuthenticateRequest)7 NotFoundException (com.google.nigori.common.NotFoundException)4 RevValue (com.google.nigori.common.RevValue)1 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)1