Search in sources :

Example 36 with Permissions

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);
    }
}
Also used : LogicalData(nl.uva.cs.lobcder.resources.LogicalData) MyPrincipal(nl.uva.cs.lobcder.auth.MyPrincipal) SQLException(java.sql.SQLException) Connection(java.sql.Connection) Permissions(nl.uva.cs.lobcder.auth.Permissions)

Example 37 with Permissions

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);
    }
}
Also used : LogicalData(nl.uva.cs.lobcder.resources.LogicalData) MyPrincipal(nl.uva.cs.lobcder.auth.MyPrincipal) SQLException(java.sql.SQLException) Connection(java.sql.Connection) Permissions(nl.uva.cs.lobcder.auth.Permissions) SQLException(java.sql.SQLException)

Example 38 with Permissions

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);
    }
}
Also used : LogicalData(nl.uva.cs.lobcder.resources.LogicalData) MyPrincipal(nl.uva.cs.lobcder.auth.MyPrincipal) SQLException(java.sql.SQLException) Connection(java.sql.Connection) Permissions(nl.uva.cs.lobcder.auth.Permissions)

Example 39 with Permissions

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);
    }
}
Also used : LogicalData(nl.uva.cs.lobcder.resources.LogicalData) MyPrincipal(nl.uva.cs.lobcder.auth.MyPrincipal) SQLException(java.sql.SQLException) QName(javax.xml.namespace.QName) Connection(java.sql.Connection) Permissions(nl.uva.cs.lobcder.auth.Permissions) JAXBElement(javax.xml.bind.JAXBElement)

Example 40 with Permissions

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);
    }
}
Also used : LogicalData(nl.uva.cs.lobcder.resources.LogicalData) MyPrincipal(nl.uva.cs.lobcder.auth.MyPrincipal) SQLException(java.sql.SQLException) Connection(java.sql.Connection) Permissions(nl.uva.cs.lobcder.auth.Permissions)

Aggregations

Permissions (nl.uva.cs.lobcder.auth.Permissions)40 LogicalData (nl.uva.cs.lobcder.resources.LogicalData)29 SQLException (java.sql.SQLException)23 Connection (java.sql.Connection)22 MyPrincipal (nl.uva.cs.lobcder.auth.MyPrincipal)21 ArrayList (java.util.ArrayList)7 BadRequestException (io.milton.http.exceptions.BadRequestException)6 NotAuthorizedException (io.milton.http.exceptions.NotAuthorizedException)6 PDRIDescr (nl.uva.cs.lobcder.resources.PDRIDescr)5 PreparedStatement (java.sql.PreparedStatement)4 ResultSet (java.sql.ResultSet)4 Stack (java.util.Stack)4 Path (io.milton.common.Path)3 Path (javax.ws.rs.Path)3 JAXBElement (javax.xml.bind.JAXBElement)3 QName (javax.xml.namespace.QName)3 LogicalDataWrapped (nl.uva.cs.lobcder.rest.wrappers.LogicalDataWrapped)3 ConflictException (io.milton.http.exceptions.ConflictException)2 IOException (java.io.IOException)2 URISyntaxException (java.net.URISyntaxException)2