Search in sources :

Example 31 with MyPrincipal

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;
}
Also used : StorageSiteWrapper(nl.uva.cs.lobcder.rest.wrappers.StorageSiteWrapper) StorageSiteWrapperList(nl.uva.cs.lobcder.rest.wrappers.StorageSiteWrapperList) MyPrincipal(nl.uva.cs.lobcder.auth.MyPrincipal) WebApplicationException(javax.ws.rs.WebApplicationException) SQLException(java.sql.SQLException) Connection(java.sql.Connection) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 32 with MyPrincipal

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);
    }
}
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 33 with MyPrincipal

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);
    }
}
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 34 with MyPrincipal

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);
    }
}
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 35 with MyPrincipal

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);
    }
}
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)

Aggregations

MyPrincipal (nl.uva.cs.lobcder.auth.MyPrincipal)37 Connection (java.sql.Connection)23 SQLException (java.sql.SQLException)22 Permissions (nl.uva.cs.lobcder.auth.Permissions)20 LogicalData (nl.uva.cs.lobcder.resources.LogicalData)20 Path (javax.ws.rs.Path)11 ArrayList (java.util.ArrayList)8 GET (javax.ws.rs.GET)8 Produces (javax.ws.rs.Produces)7 WebApplicationException (javax.ws.rs.WebApplicationException)5 PreparedStatement (java.sql.PreparedStatement)4 Stack (java.util.Stack)4 ResultSet (java.sql.ResultSet)3 Date (java.util.Date)3 HashSet (java.util.HashSet)3 Consumes (javax.ws.rs.Consumes)3 PUT (javax.ws.rs.PUT)3 JAXBElement (javax.xml.bind.JAXBElement)3 QName (javax.xml.namespace.QName)3 PDRIDescr (nl.uva.cs.lobcder.resources.PDRIDescr)3