use of nl.uva.cs.lobcder.auth.Permissions in project lobcder by skoulouzis.
the class TTL method setTTL.
/**
* Sets the time to live for a folder
*
* @param uid the uid of the folder
* @param ttl the time to live in sec
*/
@Path("{uid}/{ttl}")
@PUT
public void setTTL(@PathParam("uid") Long uid, @PathParam("ttl") Integer ttl) {
try {
MyPrincipal mp = (MyPrincipal) request.getAttribute("myprincipal");
try (Connection cn = getCatalogue().getConnection()) {
LogicalData ld = getCatalogue().getLogicalDataByUid(uid, cn);
if (ld == null) {
throw new WebApplicationException(Response.Status.NOT_FOUND);
}
Permissions p = getCatalogue().getPermissions(uid, ld.getOwner(), cn);
if (!mp.canWrite(p)) {
throw new WebApplicationException(Response.Status.UNAUTHORIZED);
}
getCatalogue().setTTL(uid, ttl, cn);
cn.commit();
}
// try (Connection cn = getCatalogue().getConnection()) {
// try (PreparedStatement ps = cn.prepareStatement("SELECT uid, ownerId, ttlSec FROM ldata_table WHERE uid=?", ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_UPDATABLE)) {
// ps.setLong(1, uid);
// ResultSet rs = ps.executeQuery();
// if (!rs.next()) {
// throw new WebApplicationException(Response.Status.NOT_FOUND);
// } else {
// String owner = rs.getString(2);
// p = getCatalogue().getPermissions(uid, owner, cn);
// if (!mp.canWrite(p)) {
// throw new WebApplicationException(Response.Status.UNAUTHORIZED);
// }
// rs.updateInt(3, ttl);
// rs.updateRow();
// cn.commit();
// }
// } catch (SQLException ex) {
// Logger.getLogger(TTL.class.getName()).log(Level.SEVERE, null, ex);
// cn.rollback();
// throw new WebApplicationException(Response.Status.INTERNAL_SERVER_ERROR);
// }
// } catch (SQLException ex) {
// Logger.getLogger(TTL.class.getName()).log(Level.SEVERE, null, ex);
// }
// }
} catch (SQLException ex) {
Logger.getLogger(TTL.class.getName()).log(Level.SEVERE, null, ex);
throw new WebApplicationException(Response.Status.INTERNAL_SERVER_ERROR);
}
}
use of nl.uva.cs.lobcder.auth.Permissions in project lobcder by skoulouzis.
the class TTL method getDir.
@Path("getdir/{ttl}")
@GET
public String getDir(@PathParam("ttl") Integer ttl) {
if (PropertiesHelper.getTmpDirUid() == null) {
throw new WebApplicationException(Response.Status.SERVICE_UNAVAILABLE);
}
MyPrincipal mp = (MyPrincipal) request.getAttribute("myprincipal");
try (Connection cn = getCatalogue().getConnection()) {
try {
LogicalData newFolderEntry = new LogicalData();
newFolderEntry.setType(Constants.LOGICAL_FOLDER);
newFolderEntry.setParentRef(PropertiesHelper.getTmpDirUid());
newFolderEntry.setName(UUID.randomUUID().toString());
newFolderEntry.setCreateDate(System.currentTimeMillis());
newFolderEntry.setModifiedDate(System.currentTimeMillis());
newFolderEntry.setLastAccessDate(System.currentTimeMillis());
newFolderEntry.setTtlSec(ttl);
newFolderEntry.setOwner(mp.getUserId());
getCatalogue().setPermissions(getCatalogue().registerDirLogicalData(newFolderEntry, cn).getUid(), new Permissions(mp, new Permissions()), cn);
cn.commit();
return newFolderEntry.getName();
} catch (Exception ex) {
cn.rollback();
Logger.getLogger(TTL.class.getName()).log(Level.SEVERE, null, ex);
throw new WebApplicationException(ex, Response.Status.INTERNAL_SERVER_ERROR);
}
} catch (SQLException sqle) {
Logger.getLogger(TTL.class.getName()).log(Level.SEVERE, null, sqle);
throw new WebApplicationException(sqle, Response.Status.INTERNAL_SERVER_ERROR);
}
}
use of nl.uva.cs.lobcder.auth.Permissions in project lobcder by skoulouzis.
the class DRIDataResource method setSupervised.
/**
* Sets supervised flag for a resource.
*
* @param uid the resource's id
* @param flag the flag
*/
@Path("{uid}/supervised/{flag}/")
@PUT
public void setSupervised(@PathParam("uid") Long uid, @PathParam("flag") Boolean flag) {
try (Connection cn = catalogue.getConnection()) {
try {
LogicalData res = catalogue.getLogicalDataByUid(uid, cn);
if (res == null) {
throw new WebApplicationException(Response.Status.NOT_FOUND);
}
MyPrincipal mp = (MyPrincipal) request.getAttribute("myprincipal");
Permissions p = catalogue.getPermissions(uid, res.getOwner(), cn);
if (!mp.canWrite(p)) {
throw new WebApplicationException(Response.Status.UNAUTHORIZED);
}
catalogue.setLogicalDataSupervised(uid, flag, cn);
cn.commit();
} catch (SQLException ex) {
Logger.getLogger(DRIDataResource.class.getName()).log(Level.SEVERE, null, ex);
cn.rollback();
throw new WebApplicationException(Response.Status.INTERNAL_SERVER_ERROR);
}
} catch (SQLException ex) {
Logger.getLogger(DRIDataResource.class.getName()).log(Level.SEVERE, null, ex);
throw new WebApplicationException(Response.Status.INTERNAL_SERVER_ERROR);
}
}
use of nl.uva.cs.lobcder.auth.Permissions in project lobcder by skoulouzis.
the class DRIDataResource method getSupervised.
/**
* Gets supervised flag for a resource.
*
* @param uid the resource's id
* @return the supervised flag for a resource.
*/
@Path("{uid}/supervised/")
@GET
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
public JAXBElement<Boolean> getSupervised(@PathParam("uid") Long uid) {
try (Connection cn = catalogue.getConnection()) {
LogicalData res = catalogue.getLogicalDataByUid(uid, cn);
if (res == null) {
throw new WebApplicationException(Response.Status.NOT_FOUND);
}
MyPrincipal mp = (MyPrincipal) request.getAttribute("myprincipal");
Permissions p = catalogue.getPermissions(uid, res.getOwner(), cn);
if (!mp.canRead(p)) {
throw new WebApplicationException(Response.Status.UNAUTHORIZED);
}
return new JAXBElement<Boolean>(new QName("supervised"), Boolean.class, res.getSupervised());
} catch (SQLException ex) {
Logger.getLogger(DRIDataResource.class.getName()).log(Level.SEVERE, null, ex);
throw new WebApplicationException(Response.Status.INTERNAL_SERVER_ERROR);
}
}
use of nl.uva.cs.lobcder.auth.Permissions in project lobcder by skoulouzis.
the class DRIDataResource method setChecksum.
/**
* Sets checksum property for an item
*
* @param uid the resource's id
* @param checksum the checksum. This value is not check if it's correct by
* lobcder
*/
@Path("{uid}/checksum/{checksum}/")
@PUT
public void setChecksum(@PathParam("uid") Long uid, @PathParam("checksum") String checksum) {
try (Connection cn = catalogue.getConnection()) {
try {
LogicalData res = catalogue.getLogicalDataByUid(uid, cn);
if (res == null) {
throw new WebApplicationException(Response.Status.NOT_FOUND);
}
MyPrincipal mp = (MyPrincipal) request.getAttribute("myprincipal");
Permissions p = catalogue.getPermissions(uid, res.getOwner(), cn);
if (!mp.canWrite(p)) {
throw new WebApplicationException(Response.Status.UNAUTHORIZED);
}
catalogue.setFileChecksum(uid, checksum, cn);
cn.commit();
} catch (SQLException ex) {
Logger.getLogger(DRIDataResource.class.getName()).log(Level.SEVERE, null, ex);
cn.rollback();
throw new WebApplicationException(Response.Status.INTERNAL_SERVER_ERROR);
}
} catch (SQLException ex) {
Logger.getLogger(DRIDataResource.class.getName()).log(Level.SEVERE, null, ex);
throw new WebApplicationException(Response.Status.INTERNAL_SERVER_ERROR);
}
}
Aggregations