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