Search in sources :

Example 6 with MyPrincipal

use of nl.uva.cs.lobcder.auth.MyPrincipal in project lobcder by skoulouzis.

the class DRIDataResource method setLastValidationDate.

/**
 * Sets lastvalidationdate property for a resource
 *
 * @param uid the resource's id
 * @param lastValidationDate the date last validated
 */
@Path("{uid}/lastValidationDate/{lastValidationDate}/")
@PUT
public void setLastValidationDate(@PathParam("uid") Long uid, @PathParam("lastValidationDate") Long lastValidationDate) {
    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.setLastValidationDate(uid, lastValidationDate, 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 7 with MyPrincipal

use of nl.uva.cs.lobcder.auth.MyPrincipal in project lobcder by skoulouzis.

the class DRIDataResource method getLastValidationDate.

/**
 * Gets lastvalidationdate property for a resource
 *
 * @param uid the resource's id
 * @return the date last validated
 */
@Path("{uid}/lastValidationDate/")
@GET
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
public JAXBElement<Long> getLastValidationDate(@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<Long>(new QName("lastValidationDate"), Long.class, res.getLastValidationDate());
    } 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 8 with MyPrincipal

use of nl.uva.cs.lobcder.auth.MyPrincipal in project lobcder by skoulouzis.

the class DRIDataResource method getChecksum.

/**
 * Gets checksum property for an item.
 *
 * @param uid the resource's id
 * @return the checksum. This value is not check if it's correct by lobcder
 */
@Path("{uid}/checksum/")
@GET
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
public JAXBElement<String> getChecksum(@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<String>(new QName("checksum"), String.class, res.getChecksum());
    } 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 9 with MyPrincipal

use of nl.uva.cs.lobcder.auth.MyPrincipal in project lobcder by skoulouzis.

the class DRItemsResource method setSupervised.

/**
 * Sets supervised flag for a resource.
 *
 * @param flag the flag
 * @param path the resource's path
 */
@Path("supervised/{flag}")
@PUT
public void setSupervised(@PathParam("flag") Boolean flag, @QueryParam("path") String path) throws UnsupportedEncodingException {
    try (Connection cn = catalogue.getConnection()) {
        MyPrincipal mp = (MyPrincipal) request.getAttribute("myprincipal");
        if (mp.isAdmin()) {
            try {
                LogicalData logicalData;
                if (path == null || path.isEmpty()) {
                    logicalData = catalogue.getLogicalDataByUid(1L, cn);
                } else {
                    logicalData = catalogue.getLogicalDataByPath(io.milton.common.Path.path(path), cn);
                }
                catalogue.setLogicalDataSupervised(logicalData.getUid(), flag, cn);
                if (logicalData.isFolder()) {
                    try (PreparedStatement ps1 = cn.prepareStatement("UPDATE ldata_table SET isSupervised=? WHERE parentRef = ?");
                        PreparedStatement ps2 = cn.prepareStatement("SELECT uid FROM ldata_table WHERE parentRef = ? AND datatype = '" + Constants.LOGICAL_FOLDER + "'")) {
                        setDirSupervised(logicalData.getUid(), flag, ps1, ps2);
                    }
                }
                cn.commit();
            } catch (SQLException e) {
                Logger.getLogger(DRItemsResource.class.getName()).log(Level.SEVERE, null, e);
                cn.rollback();
            }
        } else {
            Logger.getLogger(DRItemsResource.class.getName()).log(Level.WARNING, "NOT a superuser: want change DRI flag for {0}", path);
        }
    } catch (SQLException e) {
        Logger.getLogger(DRItemsResource.class.getName()).log(Level.SEVERE, null, e);
        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) PreparedStatement(java.sql.PreparedStatement)

Example 10 with MyPrincipal

use of nl.uva.cs.lobcder.auth.MyPrincipal in project lobcder by skoulouzis.

the class Item method getLogicalData.

/**
 * Gets the resource's properties (length, owner, permitions etc.)
 *
 * @param uid the id of the resource
 * @return the resource's properties
 * @throws FileNotFoundException
 * @throws IOException
 * @throws VlException
 * @throws URISyntaxException
 * @throws MalformedURLException
 * @throws Exception
 */
@Path("query/{uid}")
@GET
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
public LogicalDataWrapped getLogicalData(@PathParam("uid") Long uid) throws FileNotFoundException, IOException, VlException, URISyntaxException, MalformedURLException, Exception {
    MyPrincipal mp = (MyPrincipal) request.getAttribute("myprincipal");
    try {
        LogicalData resLD = getCatalogue().getLogicalDataByUid(uid);
        if (resLD == null) {
            throw new WebApplicationException(Response.Status.NOT_FOUND);
        }
        Permissions p = getCatalogue().getPermissions(uid, resLD.getOwner());
        if (!mp.canRead(p)) {
            throw new WebApplicationException(Response.Status.UNAUTHORIZED);
        }
        LogicalDataWrapped res = new LogicalDataWrapped();
        res.setGlobalID(getCatalogue().getGlobalID(uid));
        res.setLogicalData(resLD);
        res.setPermissions(p);
        res.setPath(getCatalogue().getPathforLogicalData(resLD));
        if (!resLD.isFolder()) {
            List<PDRIDescr> pdriDescr = getCatalogue().getPdriDescrByGroupId(resLD.getPdriGroupId());
            if (mp.isAdmin()) {
                for (PDRIDescr pdri : pdriDescr) {
                    if (pdri.getResourceUrl().startsWith("lfc") || pdri.getResourceUrl().startsWith("srm") || pdri.getResourceUrl().startsWith("gftp")) {
                        pdriDescr.remove(pdri);
                        GridHelper.initGridProxy(pdri.getUsername(), pdri.getPassword(), null, false);
                        pdri.setPassword(GridHelper.getProxyAsBase64String());
                        pdriDescr.add(pdri);
                    }
                }
            } else {
                for (PDRIDescr pdri : pdriDescr) {
                    pdriDescr.remove(pdri);
                    pdri.setPassword(null);
                    pdri.setUsername(null);
                    pdri.setKey(null);
                    pdri.setId(null);
                    pdri.setPdriGroupRef(null);
                    pdri.setStorageSiteId(null);
                    pdriDescr.add(pdri);
                }
            }
            res.setPdriList(pdriDescr);
        }
        return res;
    } catch (SQLException ex) {
        Logger.getLogger(Item.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) PDRIDescr(nl.uva.cs.lobcder.resources.PDRIDescr) Permissions(nl.uva.cs.lobcder.auth.Permissions) LogicalDataWrapped(nl.uva.cs.lobcder.rest.wrappers.LogicalDataWrapped) Path(javax.ws.rs.Path)

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