Skip to Content.
Sympa Menu

perfsonar-dev - perfsonar: r3465 - branches/testing/edugained-test-tool/src/es/rediris/perfsonar

Subject: perfsonar development work

List archive

perfsonar: r3465 - branches/testing/edugained-test-tool/src/es/rediris/perfsonar


Chronological Thread 
  • From:
  • To:
  • Subject: perfsonar: r3465 - branches/testing/edugained-test-tool/src/es/rediris/perfsonar
  • Date: Tue, 4 Mar 2008 09:41:11 -0500

Author: rodriguez
Date: 2008-03-04 09:41:10 -0500 (Tue, 04 Mar 2008)
New Revision: 3465

Modified:

branches/testing/edugained-test-tool/src/es/rediris/perfsonar/EduGAINed_ASTest.java

branches/testing/edugained-test-tool/src/es/rediris/perfsonar/EduGAINed_ClientTest.java
Log:
Adding some improvements

Modified:
branches/testing/edugained-test-tool/src/es/rediris/perfsonar/EduGAINed_ASTest.java
===================================================================
---
branches/testing/edugained-test-tool/src/es/rediris/perfsonar/EduGAINed_ASTest.java
2008-03-04 14:07:08 UTC (rev 3464)
+++
branches/testing/edugained-test-tool/src/es/rediris/perfsonar/EduGAINed_ASTest.java
2008-03-04 14:41:10 UTC (rev 3465)
@@ -14,9 +14,13 @@
import java.security.cert.CertificateFactory;
import java.security.cert.X509Certificate;
import java.security.spec.PKCS8EncodedKeySpec;
+import java.text.DateFormat;
+import java.text.SimpleDateFormat;
import java.util.ArrayList;
+import java.util.Calendar;
import java.util.Enumeration;
import java.util.List;
+import java.util.TimeZone;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
@@ -66,8 +70,8 @@
// add the security provider
BouncyCastleProvider bcp = new BouncyCastleProvider();
java.security.Security.addProvider((Provider)bcp);
- }
-
+ }
+
private boolean hasKeys() {
if
(getServletConfig().getInitParameter(EduGAINed_ASTest.PRIV_KEY_PARAM)==null||getServletConfig().getInitParameter(EduGAINed_ASTest.PUBLIC_KEY_PARAM)==null)
return false;
@@ -75,14 +79,14 @@
File f2=new
File(getServletContext().getRealPath(getServletConfig().getInitParameter(EduGAINed_ASTest.PUBLIC_KEY_PARAM)));
return f1.exists()&&f2.exists();
}
-
+
private boolean hasRequest() {
if
(getServletConfig().getInitParameter(EduGAINed_ASTest.QUERY_FILE_PARAM)==null)
return false;
File f1=new
File(getServletContext().getRealPath(getServletConfig().getInitParameter(EduGAINed_ASTest.QUERY_FILE_PARAM)));
return f1.exists();
}
-
+
private PrivateKey getPrivateKey() {
if (privKey!=null)
return privKey;
@@ -97,7 +101,7 @@
previousStr=str+"\n";
}
in.close();
-
+
byte[] bytes=Base64.decode(data);
PKCS8EncodedKeySpec keySpec = new PKCS8EncodedKeySpec(bytes);
KeyFactory keyFactory = KeyFactory.getInstance("RSA");
@@ -108,13 +112,13 @@
return null;
}
}
-
+
public X509Certificate getCertificate() {
if (certificate!=null)
return certificate;
try {
FileInputStream is = new FileInputStream(new
File(getServletContext().getRealPath(getServletConfig().getInitParameter(EduGAINed_ASTest.PUBLIC_KEY_PARAM))));
-
+
CertificateFactory cf =
CertificateFactory.getInstance("X.509");
X509Certificate cert =
(X509Certificate)cf.generateCertificate(is);
return cert;
@@ -123,39 +127,39 @@
return null;
}
}
-
+
private Document getQueryMessage() {
try {
Document request = null;
DocumentBuilderFactory factory =
DocumentBuilderFactory.newInstance();
factory.setNamespaceAware(true);
-
+
DocumentBuilder builder =
factory.newDocumentBuilder();
request = builder.parse(new
File(getServletContext().getRealPath(getServletConfig().getInitParameter(EduGAINed_ASTest.QUERY_FILE_PARAM))));
-
+
return request;
} catch (Exception e) {
e.printStackTrace();
return null;
}
}
-
+
private Document getDocumentFromString(String message) {
try {
Document request = null;
DocumentBuilderFactory factory =
DocumentBuilderFactory.newInstance();
factory.setNamespaceAware(true);
-
+
DocumentBuilder builder =
factory.newDocumentBuilder();
request = builder.parse(new
ByteArrayInputStream(message.getBytes()));
-
+
return request;
} catch (Exception e) {
e.printStackTrace();
return null;
}
}
-
+
protected void doPost(HttpServletRequest request, HttpServletResponse
response) throws ServletException, IOException {
response.setContentType("text/html");
PrintWriter writer = response.getWriter();
@@ -167,8 +171,14 @@
writer.println("</head>");
writer.println("<body>");

- showConfig(writer);
-
+ String ttlValue=request.getParameter("ttl");
+
+ if (ttlValue!=null&&!ttlValue.equals("")) {
+ ttlValue="900";
+ }
+
+ showConfig(writer,ttlValue);
+
showAttributes(request, writer);

String requestValue=request.getParameter("request");
@@ -176,24 +186,24 @@
showBox(writer,"Request message",requestValue,true);

Document reqDoc=getDocumentFromString(requestValue);
- showX509STMessage(writer,reqDoc);
+ showX509STMessage(writer,reqDoc,ttlValue);

reqDoc=getDocumentFromString(requestValue);
- showSAMLSTMessage(request,writer,reqDoc);
+ showSAMLSTMessage(request,writer,reqDoc,ttlValue);
}
else {
writer.println("<p>ERROR: Request not found or
invalid!");
}
-
+
writer.println("</body>");
writer.println("</html>");
- }
-
- protected void showX509STMessage(PrintWriter writer,Document reqDoc) {
+ }
+
+ protected void showX509STMessage(PrintWriter writer,Document
reqDoc,String ttl) {
try {
SOAPBodyElement requestMessage = new
SOAPBodyElement(reqDoc.getDocumentElement());
AuthNX509Data
x509data=AuthNDataFactory.getDefaultAuthNX509Data();
- Object reqRaw=x509data.addX509STInMessage(requestMessage,
getPrivateKey(), getCertificate());
+ Object reqRaw=x509data.addX509STInMessage(requestMessage,
getPrivateKey(), getCertificate(), Integer.parseInt(ttl));
SOAPEnvelope envelope=(SOAPEnvelope)reqRaw;
SOAPHeader header=envelope.getHeader();
showBox(writer, "SOAP Header for AC & UbC profiles",
formatDocument(new DOMSource(header)), true);
@@ -211,8 +221,8 @@
e.printStackTrace();
}
}
-
- protected void showSAMLSTMessage(HttpServletRequest request,
PrintWriter writer,Document reqDoc) {
+
+ protected void showSAMLSTMessage(HttpServletRequest request,
PrintWriter writer,Document reqDoc,String ttl) {
try {
SAMLAssertion
authStatementAssertion=EduGAINFilterHelper.getAuthenticationAssertion(request.getSession());
SOAPBodyElement requestMessage = new
SOAPBodyElement(reqDoc.getDocumentElement());
@@ -221,7 +231,7 @@
listCerts.add(getCertificate());
String
cID=getServletConfig().getInitParameter(EduGAINed_ASTest.COMPONENT_ID_PARAM);
String
cID_pSR=getServletConfig().getInitParameter(EduGAINed_ASTest.COMPONENT_ID_pSR_PARAM);
- SOAPEnvelope envelopeSAML =
(SOAPEnvelope)samldata.addSAMLSTInMessage(requestMessage,
authStatementAssertion, getPrivateKey(), listCerts, cID, cID_pSR);
+ SOAPEnvelope envelopeSAML =
(SOAPEnvelope)samldata.addSAMLSTInMessage(requestMessage,
authStatementAssertion, getPrivateKey(), listCerts, cID, cID_pSR,
Integer.parseInt(ttl));
SOAPHeader header=envelopeSAML.getHeader();
showBox(writer, "SOAP Header for WE profile", formatDocument(new
DOMSource(header)), true);

@@ -237,8 +247,8 @@
writer.println("<div
class='infoXML'>"+e.toString()+"</div>");
e.printStackTrace();
}
- }
-
+ }
+
protected void doGet(HttpServletRequest request, HttpServletResponse
response) throws ServletException, IOException {
response.setContentType("text/html");
PrintWriter writer = response.getWriter();
@@ -251,8 +261,8 @@
else {
showXMLMessages(request,writer);
}
- }
-
+ }
+
protected void showBox(PrintWriter writer,String title,String
content,boolean parseXML) {
writer.println("<div><h3>"+title+":</h3></div>");
String data=content;
@@ -262,7 +272,7 @@
data=data.replaceAll(" ", "&nbsp;&nbsp;");
writer.println("<div class='infoXML'>"+data+"</div>");
}
-
+
protected void showKeysError(PrintWriter writer) {
writer.println("<html>");
writer.println("<head>");
@@ -273,11 +283,11 @@
writer.println("<body>");

writer.println("<p>ERROR: Keys not found!");
-
+
writer.println("</body>");
writer.println("</html>");
}
-
+
private void showInputRequest(HttpServletRequest request, PrintWriter
writer) {
writer.println("<html>");
writer.println("<head>");
@@ -287,29 +297,30 @@
writer.println("</head>");
writer.println("<body>");

- showConfig(writer);
-
+ showConfig(writer,"900");
+
showAttributes(request, writer);

writer.println("<form method='post'>");
writer.println("<div><p>It hasn't been configured any request
file.</p></div>");
writer.println("<div><h3>Request message:</h3></div>");
+ writer.println("<div>Timelife in seconds of the security
token: <input type='text' name='ttl' value='900' /></div>");
writer.println("<div><textarea
name='request'></textarea></div>");
writer.println("<div><center><input type='submit'
value='Accept'/></center></div>");
writer.println("</form>");
-
+
writer.println("</body>");
writer.println("</html>");
}
-
+
private String getValue(String param) {
String res=getServletConfig().getInitParameter(param);
if (res==null)
res="";
return res;
}
-
- protected void showConfig(PrintWriter writer) {
+
+ protected void showConfig(PrintWriter writer,String ttl) {
writer.println("<div><h3>Configuration:</h3></div>");
writer.println("<ul>");
writer.println("<li><span class='attrName'>Read
message</span>: "+getValue(EduGAINed_ASTest.QUERY_FILE_PARAM)+"</li>");
@@ -317,9 +328,17 @@
writer.println("<li><span
class='attrName'>Certificate</span>:
"+getValue(EduGAINed_ASTest.PUBLIC_KEY_PARAM)+"</li>");
writer.println("<li><span class='attrName'>Component
ID</span>: "+getValue(EduGAINed_ASTest.COMPONENT_ID_PARAM)+"</li>");
writer.println("<li><span class='attrName'>Component ID
pSR</span>: "+getValue(EduGAINed_ASTest.COMPONENT_ID_pSR_PARAM)+"</li>");
- writer.println("</ul>");

+ writer.println("</ul>");
+ DateFormat zulu = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'");
+ zulu.setTimeZone(TimeZone.getTimeZone("UTC"));
+ Calendar cal=Calendar.getInstance();
+ writer.println("<div><h3>Configuration:</h3></div>");
+ writer.println("<ul>");
+ writer.println("<li><span class='attrName'>Timelife in
seconds of the security token</span>: "+ttl+"</li>");
+ writer.println("<li><span class='attrName'>Date
server</span>: "+zulu.format(cal.getTime())+"</li>");
+ writer.println("</ul>");
}
-
+
protected void showAttributes(HttpServletRequest request,PrintWriter
writer) {
writer.println("<div><h3>Attributes in the
session:</h3></div>");
writer.println("<ul>");
@@ -347,9 +366,9 @@
}
}

- writer.println("</ul>");
+ writer.println("</ul>");
}
-
+
protected void showXMLMessages(HttpServletRequest request,PrintWriter
writer) {
writer.println("<html>");
writer.println("<head>");
@@ -359,8 +378,8 @@
writer.println("</head>");
writer.println("<body>");

- showConfig(writer);
-
+ showConfig(writer,"900");
+
showAttributes(request, writer);

Document reqDoc=getQueryMessage();
@@ -370,23 +389,23 @@
e.printStackTrace();
}

- showX509STMessage(writer,reqDoc);
+ showX509STMessage(writer,reqDoc,"900");

reqDoc=getQueryMessage();
- showSAMLSTMessage(request,writer,reqDoc);
-
+ showSAMLSTMessage(request,writer,reqDoc,"900");
+
writer.println("</body>");
writer.println("</html>");
}
-
+
protected String formatDocument(Document doc) throws
TransformerConfigurationException, TransformerException {
Source source = new DOMSource(doc);
StringWriter stringWriter = new StringWriter();
Result result = new StreamResult(stringWriter);
TransformerFactory factory = TransformerFactory.newInstance();
Transformer transformer = factory.newTransformer();
- transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION,
"yes");
- transformer.setOutputProperty(OutputKeys.INDENT, "yes");
+ transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION,
"yes");
+ transformer.setOutputProperty(OutputKeys.INDENT, "yes");
transformer.transform(source, result);
return stringWriter.getBuffer().toString();
}
@@ -396,8 +415,8 @@
Result result = new StreamResult(stringWriter);
TransformerFactory factory = TransformerFactory.newInstance();
Transformer transformer = factory.newTransformer();
- transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION,
"yes");
- transformer.setOutputProperty(OutputKeys.INDENT, "yes");
+ transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION,
"yes");
+ transformer.setOutputProperty(OutputKeys.INDENT, "yes");
transformer.transform(source, result);
return stringWriter.getBuffer().toString();
}

Modified:
branches/testing/edugained-test-tool/src/es/rediris/perfsonar/EduGAINed_ClientTest.java
===================================================================
---
branches/testing/edugained-test-tool/src/es/rediris/perfsonar/EduGAINed_ClientTest.java
2008-03-04 14:07:08 UTC (rev 3464)
+++
branches/testing/edugained-test-tool/src/es/rediris/perfsonar/EduGAINed_ClientTest.java
2008-03-04 14:41:10 UTC (rev 3465)
@@ -160,12 +160,13 @@

writer.println("<form method='post'>");
writer.println("<div><h3>Set the end point</h3></div>");
- writer.println("<div>End Point: <select name='ep'>");
+ writer.println("<div>End Point: <input type='text' name='ep'
value='' style='width: 100%;'/></div>");
+/* writer.println("<div>End Point: <select name='ep'>");
String[] endPoints=getEndPoints();
for (int i=0; i<endPoints.length; i++) {
writer.println("<option
value='"+endPoints[i]+"'>"+endPoints[i]+"</option>");
}
- writer.println("</select></div>");
+ writer.println("</select></div>"); */
writer.println("<div><h3>Set the message</h3></div>");
writer.println("<div><textarea
name='request'></textarea></div>");
writer.println("<div><center><input type='submit'
value='Accept'/></center></div>");



  • perfsonar: r3465 - branches/testing/edugained-test-tool/src/es/rediris/perfsonar, svnlog, 03/04/2008

Archive powered by MHonArc 2.6.16.

Top of Page