Package com.wesabe.grendel.entities

Examples of com.wesabe.grendel.entities.Document


      this.recipientKeySet = KeySet.load(recipientKeyring);
      recipientKeyring.close();
     
      this.owner = new User(ownerKeySet);
      this.reader = new User(recipientKeySet);
      this.doc = new Document(owner, "test", MediaType.APPLICATION_OCTET_STREAM_TYPE);
    }
View Full Code Here


  public Response show(@Context Request request, @Context Credentials credentials,
    @PathParam("user_id") String userId, @PathParam("name") String name) throws CryptographicException {
   
    final Session session = credentials.buildSession(userDAO, userId);
   
    final Document doc = documentDAO.findByOwnerAndName(session.getUser(), name);
   
    if (doc == null) {
      throw new WebApplicationException(Status.NOT_FOUND);
    }
   
    checkPreconditions(request, doc);
   
    final byte[] body = doc.decryptBody(session.getKeySet());
    return Response.ok()
        .entity(body)
        .type(doc.getContentType())
        .cacheControl(CACHE_SETTINGS)
        .lastModified(doc.getModifiedAt().toDate())
        .tag(doc.getEtag())
        .build();
  }
View Full Code Here

  @Transactional
  public Response delete(@Context Request request, @Context Credentials credentials,
    @PathParam("user_id") String userId, @PathParam("name") String name) {
   
    final Session session = credentials.buildSession(userDAO, userId);
    final Document doc = documentDAO.findByOwnerAndName(session.getUser(), name);
    if (doc == null) {
      throw new WebApplicationException(Status.NOT_FOUND);
    }
   
    checkPreconditions(request, doc);
View Full Code Here

  public Response store(@Context Request request, @Context HttpHeaders headers,
    @Context Credentials credentials, @PathParam("user_id") String userId,
    @PathParam("name") String name, byte[] body) throws CryptographicException {
   
    final Session session = credentials.buildSession(userDAO, userId);
    Document doc = documentDAO.findByOwnerAndName(session.getUser(), name);
    if (doc == null) {
      doc = documentDAO.newDocument(session.getUser(), name, headers.getMediaType());
    } else {
      checkPreconditions(request, doc);
    }
   
    doc.setModifiedAt(new DateTime(DateTimeZone.UTC));
    doc.encryptAndSetBody(
      session.getKeySet(),
      randomProvider.get(),
      body
    );
   
    documentDAO.saveOrUpdate(doc);
     
    return Response
        .noContent()
        .tag(doc.getEtag())
        .build();
  }
View Full Code Here

  /**
   * Returns a new {@link Document} with the provided owner, name, and
   * content-type.
   */
  public Document newDocument(User owner, String name, MediaType contentType) {
    return new Document(owner, name, contentType);
  }
View Full Code Here

    @Context Credentials credentials, @PathParam("user_id") String userId,
    @PathParam("name") String documentName) {
   
    final Session session = credentials.buildSession(userDAO, userId);
   
    final Document doc = documentDAO.findByOwnerAndName(session.getUser(), documentName);
    if (doc == null) {
      throw new WebApplicationException(Status.NOT_FOUND);
    }
   
    return new LinkListRepresentation(uriInfo, doc);
View Full Code Here

    @PathParam("user_id") String userId, @PathParam("name") String name,
    @PathParam("reader_id") String readerId) {
   
    final Session session = credentials.buildSession(userDAO, userId);
    final User reader = findUser(readerId);
    final Document doc = findDocument(session.getUser(), name);
   
    doc.linkUser(reader);
    reEncrypt(doc, session.getKeySet());
   
    documentDAO.saveOrUpdate(doc);
   
    return Response.noContent().build();
View Full Code Here

    @PathParam("user_id") String userId, @PathParam("name") String name,
    @PathParam("reader_id") String readerId) {
   
    final Session session = credentials.buildSession(userDAO, userId);
    final User reader = findUser(readerId);
    final Document doc = findDocument(session.getUser(), name);
   
    doc.unlinkUser(reader);
    reEncrypt(doc, session.getKeySet());
   
    documentDAO.saveOrUpdate(doc);
   
    return Response.noContent().build();
View Full Code Here

      throw new RuntimeException(e);
    }
  }

  private Document findDocument(User owner, String name) {
    final Document doc = documentDAO.findByOwnerAndName(owner, name);
    if (doc == null) {
      throw new WebApplicationException(Status.NOT_FOUND);
    }
    return doc;
  }
View Full Code Here

    @PathParam("user_id") String userId, @PathParam("owner_id") String ownerId,
    @PathParam("name") String name) {
   
    final Session session = credentials.buildSession(userDAO, userId);
    final User owner = findUser(ownerId);
    final Document doc = findDocument(owner, name);
   
    checkLinkage(doc, session.getUser());
   
    try {
      final byte[] body = doc.decryptBody(session.getKeySet());
      return Response.ok()
          .entity(body)
          .type(doc.getContentType())
          .cacheControl(CACHE_SETTINGS)
          .lastModified(doc.getModifiedAt().toDate())
          .build();
    } catch (CryptographicException e) {
      throw new RuntimeException(e);
    }
  }
View Full Code Here

TOP

Related Classes of com.wesabe.grendel.entities.Document

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.