Search in sources :

Example 26 with MyPrincipal

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

the class Items method getXml.

/**
 * Gets the resource's properties (length, owner, permitions etc.)
 *
 * @return the resource's properties
 * @throws Exception
 */
@Path("query/")
@GET
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
public List<LogicalDataWrapped> getXml() throws Exception {
    try (Connection cn = getCatalogue().getConnection()) {
        MyPrincipal mp = (MyPrincipal) request.getAttribute("myprincipal");
        List<LogicalDataWrapped> res = queryLogicalData(mp, cn);
        return res;
    } catch (SQLException ex) {
        Logger.getLogger(Items.class.getName()).log(Level.SEVERE, null, ex);
        throw new WebApplicationException(Response.Status.INTERNAL_SERVER_ERROR);
    }
}
Also used : MyPrincipal(nl.uva.cs.lobcder.auth.MyPrincipal) WebApplicationException(javax.ws.rs.WebApplicationException) SQLException(java.sql.SQLException) Connection(java.sql.Connection) LogicalDataWrapped(nl.uva.cs.lobcder.rest.wrappers.LogicalDataWrapped) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 27 with MyPrincipal

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

the class SDNService method setStats.

@Path("optimizeFlow")
@PUT
@Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
public void setStats(JAXBElement<Endpoints> jbEndpoints) throws IOException, InterruptedException {
    MyPrincipal mp = (MyPrincipal) request.getAttribute("myprincipal");
    if (mp.getRoles().contains("worker") || mp.isAdmin()) {
        Endpoints endpoints = jbEndpoints.getValue();
        if (sdnClient == null) {
            String uri = PropertiesHelper.getSDNControllerURL();
            sdnClient = new SDNControllerClient(uri);
        }
        Set<String> sources = new HashSet<>();
        sources.add(endpoints.source);
        List<DefaultWeightedEdge> shortestPath = sdnClient.getShortestPath(endpoints.destination, sources);
        sdnClient.pushFlow(shortestPath);
    }
}
Also used : DefaultWeightedEdge(org.jgrapht.graph.DefaultWeightedEdge) MyPrincipal(nl.uva.cs.lobcder.auth.MyPrincipal) SDNControllerClient(nl.uva.cs.lobcder.optimization.SDNControllerClient) HashSet(java.util.HashSet)

Example 28 with MyPrincipal

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

the class SetBulkPermissionsResource method setPermissions.

// @PUT
// @Consumes({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON})
public void setPermissions(@QueryParam("path") String path, JAXBElement<Permissions> jbPermissions) throws UnsupportedEncodingException {
    try (Connection connection = catalogue.getConnection()) {
        try {
            Permissions permissions = jbPermissions.getValue();
            MyPrincipal mp = (MyPrincipal) request.getAttribute("myprincipal");
            setPermissionsJava(path, permissions, mp, connection);
            connection.commit();
        } catch (SQLException ex) {
            Logger.getLogger(SetBulkPermissionsResource.class.getName()).log(Level.SEVERE, null, ex);
            connection.rollback();
            throw new WebApplicationException(Response.Status.INTERNAL_SERVER_ERROR);
        }
    } catch (SQLException ex) {
        Logger.getLogger(SetBulkPermissionsResource.class.getName()).log(Level.SEVERE, null, ex);
        throw new WebApplicationException(Response.Status.INTERNAL_SERVER_ERROR);
    }
}
Also used : MyPrincipal(nl.uva.cs.lobcder.auth.MyPrincipal) Permissions(nl.uva.cs.lobcder.auth.Permissions)

Example 29 with MyPrincipal

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

the class StatsService method setStats.

@Path("set")
@PUT
@Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
public void setStats(JAXBElement<Stats> jbStats) {
    MyPrincipal mp = (MyPrincipal) request.getAttribute("myprincipal");
    if (mp.getRoles().contains("worker") || mp.isAdmin()) {
        try {
            Stats stats = jbStats.getValue();
            getCatalogue().setSpeed(stats);
        } catch (SQLException ex) {
            Logger.getLogger(StatsService.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
}
Also used : MyPrincipal(nl.uva.cs.lobcder.auth.MyPrincipal) SQLException(java.sql.SQLException) Stats(nl.uva.cs.lobcder.rest.wrappers.Stats)

Example 30 with MyPrincipal

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

the class StorageSitesService method updateLogicalDataAndPdri.

@PUT
@Path("update_pdri/{uid}")
@Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
public void updateLogicalDataAndPdri(PDRIDescrWrapperList pdris, @PathParam("uid") Long uid) throws SQLException, IOException {
    MyPrincipal mp = (MyPrincipal) request.getAttribute("myprincipal");
    if (mp.isAdmin()) {
        try (Connection cn = getCatalogue().getConnection()) {
            for (PDRIDescr pdriDescr : pdris.getPdris()) {
                LogicalData logicalData = getCatalogue().getLogicalDataByUid(uid, cn);
                PDRI pdri = PDRIFactory.getFactory().createInstance(pdriDescr, false);
                logicalData.setLength(pdri.getLength());
                getCatalogue().updatePdri(logicalData, pdri, cn);
            }
            cn.commit();
            cn.close();
        }
    }
}
Also used : LogicalData(nl.uva.cs.lobcder.resources.LogicalData) MyPrincipal(nl.uva.cs.lobcder.auth.MyPrincipal) PDRIDescr(nl.uva.cs.lobcder.resources.PDRIDescr) Connection(java.sql.Connection) PDRI(nl.uva.cs.lobcder.resources.PDRI) Path(javax.ws.rs.Path) Consumes(javax.ws.rs.Consumes) PUT(javax.ws.rs.PUT)

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