use of nl.uva.cs.lobcder.auth.MyPrincipal in project lobcder by skoulouzis.
the class StorageSitesService method getXml.
@GET
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
public StorageSiteWrapperList getXml() throws FileNotFoundException, VlException, URISyntaxException, IOException, MalformedURLException, Exception {
MyPrincipal mp = (MyPrincipal) request.getAttribute("myprincipal");
if (mp.isAdmin()) {
try (Connection cn = getCatalogue().getConnection()) {
List<StorageSiteWrapper> res = queryStorageSites(cn, mp.isAdmin());
StorageSiteWrapperList sswl = new StorageSiteWrapperList();
sswl.setSites(res);
return sswl;
} catch (SQLException ex) {
Logger.getLogger(StorageSitesService.class.getName()).log(Level.SEVERE, null, ex);
throw new WebApplicationException(Response.Status.INTERNAL_SERVER_ERROR);
}
}
return null;
}
use of nl.uva.cs.lobcder.auth.MyPrincipal 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.MyPrincipal 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.MyPrincipal 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.MyPrincipal 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);
}
}
Aggregations