Commit 23ba20c1 authored by toaster's avatar toaster
Browse files

token store downloading, and proof viewing on browse

git-svn-id: https://subversion.umiacs.umd.edu/ace/trunk@26 f1b3a171-7291-4a19-a512-95ad0ad9394a
parent 0f8c0b1e
......@@ -30,10 +30,14 @@
// $Id$
package edu.umiacs.ace.monitor.access;
import edu.umiacs.ace.ims.api.TokenResponseStoreWriter;
import edu.umiacs.ace.ims.ws.TokenResponse;
import edu.umiacs.ace.monitor.audit.AuditThreadFactory;
import edu.umiacs.ace.monitor.core.MonitoredItem;
import edu.umiacs.ace.util.EntityManagerServlet;
import edu.umiacs.ace.util.PersistUtil;
import edu.umiacs.ace.monitor.core.Collection;
import edu.umiacs.ace.monitor.core.Token;
import edu.umiacs.sql.SQL;
import java.io.IOException;
import java.sql.Connection;
......@@ -41,7 +45,6 @@ import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import javax.persistence.EntityManager;
import javax.persistence.EntityNotFoundException;
import javax.servlet.ServletException;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletRequest;
......@@ -61,6 +64,7 @@ public class ListContentsServlet extends EntityManagerServlet {
public static final String TYPE_WGET = "wget";
public static final String TYPE_DIGEST = "digest";
public static final String TYPE_CHECKM = "checkm";
public static final String TYPE_STORE = "store";
/**
* Processes requests for both HTTP <code>GET</code> and <code>POST</code> methods.
......@@ -80,10 +84,12 @@ public class ListContentsServlet extends EntityManagerServlet {
response.setContentType("text/plain");
ServletOutputStream os = response.getOutputStream();
if ( !(TYPE_CHECKM.equals(output) || TYPE_DIGEST.equals(output) || TYPE_WGET.equals(output)) ) {
if ( !(TYPE_CHECKM.equals(output) || TYPE_DIGEST.equals(output)
|| TYPE_WGET.equals(output) || TYPE_STORE.equals(output)) ) {
throw new ServletException("Illegal type " + output);
}
try {
mi = getItem(request, em);
......@@ -107,14 +113,16 @@ public class ListContentsServlet extends EntityManagerServlet {
os.println("#Filename | Algorithm | Digest");
}
TokenResponseStoreWriter writer =
new TokenResponseStoreWriter(os, AuditThreadFactory.getIMS());
// query for items
try {
db = PersistUtil.getDataSource();
conn = db.getConnection();
if ( mi == null ) {
stmt = conn.prepareStatement(
"SELECT monitored_item.PATH, monitored_item.FILEDIGEST "
"SELECT monitored_item.PATH, monitored_item.FILEDIGEST, monitored_item.TOKEN_ID "
+ "FROM monitored_item "
+ "WHERE monitored_item.PARENTCOLLECTION_ID = ? "
+ "AND monitored_item.DIRECTORY = 0",
......@@ -122,7 +130,7 @@ public class ListContentsServlet extends EntityManagerServlet {
ResultSet.CONCUR_READ_ONLY);
} else {
stmt = conn.prepareStatement(
"SELECT monitored_item.PATH, monitored_item.FILEDIGEST "
"SELECT monitored_item.PATH, monitored_item.FILEDIGEST, monitored_item.TOKEN_ID "
+ "FROM monitored_item "
+ "WHERE monitored_item.PARENTCOLLECTION_ID = ? "
+ "AND monitored_item.DIRECTORY = 0 " + "AND monitored_item.PATH like ?",
......@@ -141,16 +149,24 @@ public class ListContentsServlet extends EntityManagerServlet {
String ctxPath = HttpUtils.getRequestURL(request).toString();
String prefix = ctxPath.substring(
0, ctxPath.lastIndexOf("/Sum"));
line = prefix + "/Path/" + c.getName() + rs.getString(1).replaceAll(
"\\n", "\\n");
line = prefix + "/Path/" + c.getName() + formatPath(rs.getString(1));
os.println(line);
} else if ( TYPE_CHECKM.equals(output) ) {
String digestAlg = checkmDigestAlgFormat(c.getDigestAlgorithm());
line = rs.getString(1).replaceAll("\\n", "\\n") + " | " + digestAlg + " | " + rs.getString(2);
line = formatPath(rs.getString(1)) + " | " + digestAlg + " | "
+ rs.getString(2);
os.println(line);
} else if ( TYPE_DIGEST.equals(output) ) {
line = rs.getString(2) + "\t" + rs.getString(1).replaceAll(
"\\n", "\\n");
line = rs.getString(2) + "\t" + formatPath(rs.getString(1));
os.println(line);
} else if ( TYPE_STORE.equals(output) ) {
Token tok = em.getReference(Token.class, rs.getLong(3));
if ( tok != null ) {
writer.startToken((TokenResponse) tok.getToken());
writer.addIdentifier(formatPath(rs.getString(1)));
writer.writeTokenEntry();
}
}
os.println(line);
}
rs.close();
......@@ -170,8 +186,11 @@ public class ListContentsServlet extends EntityManagerServlet {
}
private String checkmDigestAlgFormat(String s)
{
private String formatPath(String raw)
{
return raw.replaceAll("\\n", "\\n");
}
private String checkmDigestAlgFormat( String s ) {
return s.toLowerCase().replaceAll("[^a-z0-9]", "");
}
}
......@@ -31,6 +31,8 @@
package edu.umiacs.ace.monitor.access.browse;
import edu.umiacs.ace.ims.api.TokenValidator;
import edu.umiacs.ace.ims.ws.TokenResponse;
import edu.umiacs.ace.monitor.core.MonitoredItem;
import edu.umiacs.ace.util.EntityManagerServlet;
import edu.umiacs.ace.monitor.audit.AuditThreadFactory;
......@@ -38,6 +40,8 @@ import edu.umiacs.ace.monitor.audit.AuditTokens;
import edu.umiacs.ace.monitor.access.browse.DirectoryTree.DirectoryNode;
import edu.umiacs.ace.monitor.core.Collection;
import java.io.IOException;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import javax.persistence.EntityManager;
import javax.persistence.EntityNotFoundException;
import javax.servlet.RequestDispatcher;
......@@ -107,7 +111,7 @@ public class BrowseServlet extends EntityManagerServlet {
isRunning = true;
}
session.setAttribute(SESSION_FILE,
loadFileBean(dt.getDirectoryNode(itemId), em));
loadFileBean(dt.getDirectoryNode(itemId), em,c));
if ( dt.getDirectoryNode(itemId).isDirectory() ) {
dt.toggleItem(itemId);
......@@ -123,7 +127,7 @@ public class BrowseServlet extends EntityManagerServlet {
dispatcher.forward(request, response);
}
private FileBean loadFileBean( DirectoryNode node, EntityManager em ) {
private FileBean loadFileBean( DirectoryNode node, EntityManager em,Collection c ) {
FileBean retBean = new FileBean();
try {
......@@ -131,9 +135,20 @@ public class BrowseServlet extends EntityManagerServlet {
node.getId());
retBean.root = master;
retBean.name = node.getName();
if (master.getToken() != null)
{
TokenResponse resp = (TokenResponse)master.getToken().getToken();
MessageDigest digest = MessageDigest.getInstance(resp.getDigestService());
retBean.itemProof = TokenValidator.calculateRoot(digest, master.getFileDigest(), resp.getProofElements());
}
return retBean;
} catch ( EntityNotFoundException e ) {
return null;
} catch (NoSuchAlgorithmException e)
{
LOG.error("Cannot create ald",e);
return null;
}
......@@ -143,6 +158,11 @@ public class BrowseServlet extends EntityManagerServlet {
MonitoredItem root;
String name;
String itemProof;
public String getItemProof() {
return itemProof;
}
public String getName() {
return name;
......
......@@ -191,6 +191,8 @@ public final class AuditThread extends Thread implements CancelCallback {
}
performAudit();
// Let outstanding tokens finish, TODO, de-hackify this.
sleep(2000);
} catch ( Throwable e ) {
LOG.fatal("UNcaught exception in performAudit()", e);
if ( abortException != null ) {
......
......@@ -229,6 +229,7 @@ public class MonitoredItem implements Serializable, Comparable {
return lastVisited;
}
@Override
public int compareTo( Object o ) {
if ( equals(o) ) {
......
......@@ -77,6 +77,11 @@ public class Token implements Serializable {
@ManyToOne
private Collection parentCollection;
// private String fileDigest;
// New items, from token itself
// private String proofText;
// private String imsService;
// private String proofAlgorithm;
// private long round;
public void setId( Long id ) {
this.id = id;
......
......@@ -146,7 +146,8 @@ on Libraries node in Projects view can be used to add the JSTL 1.1 library.
<c:if test="${!selectedFile.root.directory}">
<tr><td>Last Change</td><td>${selectedFile.root.stateChange}</td></tr>
<tr><td>${selectedFile.root.parentCollection.digestAlgorithm} Digest</td><td style="font-size: 10px;">${selectedFile.root.fileDigest}</td></tr>
</c:if>
<tr><td>Token Proof:</td><td style="font-size: 10px;">${selectedFile.itemProof}</td></tr>
</c:if>
</table>
<c:if test="${!selectedFile.root.directory}">
......@@ -180,6 +181,7 @@ on Libraries node in Projects view can be used to add the JSTL 1.1 library.
</c:if>
<m:Auth role="Summary">
<c:if test="${selectedFile.root.directory}">
<a href="Summary?collectionid=${selectedFile.root.parentCollection.id}&amp;itemid=${selectedFile.root.id}&amp;output=store">Download&nbsp;Token Store</a>&nbsp;&nbsp;&nbsp;&nbsp;
<a href="Summary?collectionid=${selectedFile.root.parentCollection.id}&amp;itemid=${selectedFile.root.id}&amp;output=digest">Download&nbsp;Digests</a>&nbsp;&nbsp;&nbsp;&nbsp;
<a href="Summary?collectionid=${selectedFile.root.parentCollection.id}&amp;itemid=${selectedFile.root.id}&amp;output=checkm">Checkm&nbsp;Manifest</a>&nbsp;&nbsp;&nbsp;&nbsp;
......
......@@ -172,6 +172,7 @@
</um:Auth>
</c:if>
<um:Auth role="Summary">
<a href="Summary?collectionid=${workingCollection.collection.id}&amp;output=store" title="Download tokenstore for this collection">Download TokenStore</a><br>
<a href="Summary?collectionid=${workingCollection.collection.id}&amp;output=digest" title="Download a list of all digests in this collection">Download Digests</a><br>
<a href="Summary?collectionid=${workingCollection.collection.id}&amp;output=checkm" title="Download a checkm manifest of all items in this collection">Download checkm list</a><br>
<c:if test="${workingCollection.collection.proxyData}">
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment