Search in sources :

Example 21 with MyPrincipal

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

the class PathReservationService method request.

@Path("{commID}/request/")
@GET
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
public ReservationInfo request(@PathParam("commID") String communicationID) throws MalformedURLException, IOException {
    // rest/reservation/5455/request/?dataPath=/sbuiifv/dsudsuds&storageSiteHost=sps1&storageSiteHost=sps2&storageSiteHost=sps3
    MyPrincipal mp = (MyPrincipal) request.getAttribute("myprincipal");
    MultivaluedMap<String, String> queryParameters = info.getQueryParameters();
    if (mp.getRoles().contains("planner") || mp.isAdmin() && queryParameters != null && !queryParameters.isEmpty()) {
        String dataName = queryParameters.getFirst("dataName");
        if (dataName != null && dataName.length() > 0) {
            List<String> storageList = queryParameters.get("storageSiteHost");
            String storageSiteHost = null;
            int index = -1;
            if (storageList != null && storageList.size() > 0) {
                storageSiteHost = getStorageSiteHost(storageList);
                index = storageList.indexOf(storageSiteHost);
            } else {
            }
            LogicalData ld;
            Permissions p = null;
            try (Connection cn = getCatalogue().getConnection()) {
                // -----------------THIS IS TEMPORARY IT'S ONLY FOR THE DEMO!!!!!!!!!!
                String fileNameWithOutExt = FilenameUtils.removeExtension(dataName);
                fileNameWithOutExt += ".webm";
                List<LogicalData> ldList = getCatalogue().getLogicalDataByName(io.milton.common.Path.path(fileNameWithOutExt), cn);
                if (ldList == null || ldList.isEmpty()) {
                    ldList = getCatalogue().getLogicalDataByName(io.milton.common.Path.path(dataName), cn);
                }
                // --------------------------------------------------------------
                if (ldList == null || ldList.isEmpty()) {
                    Response.status(Response.Status.NOT_FOUND);
                    return null;
                }
                // Should be only one
                ld = ldList.get(0);
                if (ld != null) {
                    p = getCatalogue().getPermissions(ld.getUid(), ld.getOwner(), cn);
                }
            } catch (SQLException ex) {
                log.log(Level.SEVERE, null, ex);
                throw new WebApplicationException(Response.Status.INTERNAL_SERVER_ERROR);
            }
            // Integer alocationStrategy = Integer.valueOf(queryParameters.getFirst("allocationStrategy"));
            ReservationInfo info = new ReservationInfo();
            if (p != null && mp.canRead(p)) {
                info.setCommunicationID(communicationID);
                String workerURL = scheduleWorker(storageSiteHost, ld);
                info.setCommunicationID(communicationID);
                storageSiteHost = Network.replaceIP(storageSiteHost);
                info.setStorageHost(storageSiteHost);
                info.setStorageHostIndex(index);
                workerURL = Network.replaceIP(workerURL);
                info.setWorkerDataAccessURL(workerURL);
            }
            return info;
        }
    }
    return null;
}
Also used : LogicalData(nl.uva.cs.lobcder.resources.LogicalData) MyPrincipal(nl.uva.cs.lobcder.auth.MyPrincipal) WebApplicationException(javax.ws.rs.WebApplicationException) SQLException(java.sql.SQLException) ReservationInfo(nl.uva.cs.lobcder.rest.wrappers.ReservationInfo) Permissions(nl.uva.cs.lobcder.auth.Permissions) Connection(java.sql.Connection) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 22 with MyPrincipal

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

the class StorageSitesService method set.

@Path("set/")
@PUT
@Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
public void set(JAXBElement<StorageSiteWrapperList> jbSites) throws SQLException {
    MyPrincipal mp = (MyPrincipal) request.getAttribute("myprincipal");
    if (mp.isAdmin()) {
        try (Connection connection = getCatalogue().getConnection()) {
            StorageSiteWrapperList sitesWL = jbSites.getValue();
            List<StorageSiteWrapper> sswl = sitesWL.getSites();
            if (sswl != null && sswl.size() > 0) {
                Collection<StorageSite> sites = new ArrayList<>();
                for (StorageSiteWrapper ssw : sswl) {
                    StorageSite site = new StorageSite();
                    Credential cred = new Credential();
                    cred.setStorageSitePassword(ssw.getCredential().getStorageSitePassword());
                    cred.setStorageSiteUsername(ssw.getCredential().getStorageSiteUsername());
                    site.setCredential(cred);
                    site.setCurrentNum(ssw.getCurrentNum());
                    site.setCurrentSize(ssw.getCurrentSize());
                    site.setResourceURI(ssw.getResourceURI());
                    site.setEncrypt(ssw.isEncrypt());
                    site.setCache(ssw.isCache());
                    site.setQuotaNum(ssw.getQuotaNum());
                    site.setQuotaSize(ssw.getQuotaSize());
                    sites.add(site);
                }
                getCatalogue().insertOrUpdateStorageSites(sites, connection);
                connection.commit();
            }
        }
    }
}
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) Credential(nl.uva.cs.lobcder.resources.Credential) StorageSite(nl.uva.cs.lobcder.resources.StorageSite) Connection(java.sql.Connection) ArrayList(java.util.ArrayList) Path(javax.ws.rs.Path) Consumes(javax.ws.rs.Consumes) PUT(javax.ws.rs.PUT)

Example 23 with MyPrincipal

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

the class UsersService method getXml.

@Path("query/")
@GET
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
public UsersWrapperList getXml() throws FileNotFoundException, VlException, URISyntaxException, IOException, MalformedURLException, Exception {
    MyPrincipal mp = (MyPrincipal) request.getAttribute("myprincipal");
    if (mp.isAdmin()) {
        try (Connection cn = getCatalogue().getConnection()) {
            List<UsersWrapper> res = queryUsers(cn);
            UsersWrapperList uwl = new UsersWrapperList();
            uwl.setUsers(res);
            return uwl;
        } catch (SQLException ex) {
            log.log(Level.SEVERE, null, ex);
            throw new WebApplicationException(Response.Status.INTERNAL_SERVER_ERROR);
        }
    }
    return null;
}
Also used : MyPrincipal(nl.uva.cs.lobcder.auth.MyPrincipal) WebApplicationException(javax.ws.rs.WebApplicationException) SQLException(java.sql.SQLException) Connection(java.sql.Connection) UsersWrapperList(nl.uva.cs.lobcder.rest.wrappers.UsersWrapperList) UsersWrapper(nl.uva.cs.lobcder.rest.wrappers.UsersWrapper) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 24 with MyPrincipal

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

the class WebDataResource method getPriviledges.

@Override
public List<Priviledge> getPriviledges(Auth auth) {
    final MyPrincipal currentPrincipal = getPrincipal();
    List<Priviledge> perm = new ArrayList<>();
    if (currentPrincipal.getUserId().equals(getLogicalData().getOwner())) {
        perm.add(Priviledge.ALL);
        return perm;
    }
    Set<String> currentRoles = currentPrincipal.getRoles();
    // We are supposed to get permissions for this resource for the current user
    Permissions p;
    try {
        p = getPermissions();
    } catch (SQLException e) {
        Logger.getLogger(WebDataResource.class.getName()).log(Level.SEVERE, "Could not get Permissions for resource " + getPath(), e);
        return perm;
    }
    Set<String> readRoles = p.getRead();
    Set<String> writeRoles = p.getWrite();
    readRoles.retainAll(currentRoles);
    if (!readRoles.isEmpty()) {
        perm.add(Priviledge.READ);
        perm.add(Priviledge.READ_ACL);
        perm.add(Priviledge.READ_CONTENT);
        perm.add(Priviledge.READ_CURRENT_USER_PRIVILEDGE);
        perm.add(Priviledge.READ_PROPERTIES);
    }
    writeRoles.retainAll(currentRoles);
    if (!writeRoles.isEmpty()) {
        perm.add(Priviledge.WRITE);
        perm.add(Priviledge.BIND);
        perm.add(Priviledge.UNBIND);
        perm.add(Priviledge.UNLOCK);
        perm.add(Priviledge.WRITE_ACL);
        perm.add(Priviledge.WRITE_CONTENT);
        perm.add(Priviledge.WRITE_PROPERTIES);
    }
    return perm;
}
Also used : MyPrincipal(nl.uva.cs.lobcder.auth.MyPrincipal) Permissions(nl.uva.cs.lobcder.auth.Permissions)

Example 25 with MyPrincipal

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

the class WebDataResource method authenticate.

@Override
public Object authenticate(String user, String password) {
    String token = password;
    MyPrincipal principal = null;
    for (AuthI a : authList) {
        principal = a.checkToken(user, token);
        if (principal != null) {
            break;
        }
    }
    // }
    if (principal != null) {
        principalHolder.set(principal);
        // Logger.getLogger(WebDataResource.class.getName()).log(Level.FINE, "getUserId: {0}", principal.getUserId());
        // Logger.getLogger(WebDataResource.class.getName()).log(Level.FINE, "getRolesStr: {0}", principal.getRolesStr());
        String msg = "From: " + fromAddress + " user: " + principal.getUserId() + " password: XXXX";
        Logger.getLogger(WebDataResource.class.getName()).log(Level.INFO, msg);
    }
    try {
        getCatalogue().updateAccessTime(getLogicalData().getUid());
    } catch (SQLException ex) {
        Logger.getLogger(WebDataResource.class.getName()).log(Level.SEVERE, null, ex);
    }
    return principal;
}
Also used : MyPrincipal(nl.uva.cs.lobcder.auth.MyPrincipal) AuthI(nl.uva.cs.lobcder.auth.AuthI)

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