perfsonar-dev - perfsonar: r5406 - in branches/new-structure-with-base2/ps-mdm-web-admin: . ant src/main/java/org/perfsonar/webadmin/base2/servlet src/main/java/org/perfsonar/webadmin/base2/servlet/util src/main/java/org/perfsonar/webadmin/base2/util tomcat/html
Subject: perfsonar development work
List archive
perfsonar: r5406 - in branches/new-structure-with-base2/ps-mdm-web-admin: . ant src/main/java/org/perfsonar/webadmin/base2/servlet src/main/java/org/perfsonar/webadmin/base2/servlet/util src/main/java/org/perfsonar/webadmin/base2/util tomcat/html
Chronological Thread
- From:
- To:
- Subject: perfsonar: r5406 - in branches/new-structure-with-base2/ps-mdm-web-admin: . ant src/main/java/org/perfsonar/webadmin/base2/servlet src/main/java/org/perfsonar/webadmin/base2/servlet/util src/main/java/org/perfsonar/webadmin/base2/util tomcat/html
- Date: Fri, 11 Dec 2009 08:59:47 -0500
Author: trzaszcz
Date: 2009-12-11 08:59:47 -0500 (Fri, 11 Dec 2009)
New Revision: 5406
Added:
branches/new-structure-with-base2/ps-mdm-web-admin/src/main/java/org/perfsonar/webadmin/base2/util/HTMLUtilStringBuffer.java
Modified:
branches/new-structure-with-base2/ps-mdm-web-admin/.classpath
branches/new-structure-with-base2/ps-mdm-web-admin/ant/build.xml
branches/new-structure-with-base2/ps-mdm-web-admin/src/main/java/org/perfsonar/webadmin/base2/servlet/BasicConfigurationServlet.java
branches/new-structure-with-base2/ps-mdm-web-admin/src/main/java/org/perfsonar/webadmin/base2/servlet/util/Base64.java
branches/new-structure-with-base2/ps-mdm-web-admin/src/main/java/org/perfsonar/webadmin/base2/servlet/util/ConfigurationServletHelper.java
branches/new-structure-with-base2/ps-mdm-web-admin/tomcat/html/index.jsp
Log:
login/password window added, refactoring
Modified: branches/new-structure-with-base2/ps-mdm-web-admin/.classpath
===================================================================
--- branches/new-structure-with-base2/ps-mdm-web-admin/.classpath
2009-12-11 12:18:45 UTC (rev 5405)
+++ branches/new-structure-with-base2/ps-mdm-web-admin/.classpath
2009-12-11 13:59:47 UTC (rev 5406)
@@ -2,7 +2,7 @@
<classpath>
<classpathentry kind="src" path="src/main/java"/>
<classpathentry kind="src" path="src/test/java"/>
- <classpathentry kind="con"
path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/>
+ <classpathentry kind="con"
path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry kind="lib"
path="lib/repository/tomcat/servlet-api/5.0.28/servlet-api-5.0.28.jar"/>
<classpathentry kind="lib"
path="lib/repository/Validation/isorelax/1.0/isorelax-1.0.jar"/>
<classpathentry kind="lib"
path="lib/repository/Validation/msv/1.0/msv-1.0.jar"/>
Modified: branches/new-structure-with-base2/ps-mdm-web-admin/ant/build.xml
===================================================================
--- branches/new-structure-with-base2/ps-mdm-web-admin/ant/build.xml
2009-12-11 12:18:45 UTC (rev 5405)
+++ branches/new-structure-with-base2/ps-mdm-web-admin/ant/build.xml
2009-12-11 13:59:47 UTC (rev 5406)
@@ -246,7 +246,6 @@
</target>
-
<!-- ======================= tomcat deployment =================== -->
<path id="tomcat.deployer.classpath">
Modified:
branches/new-structure-with-base2/ps-mdm-web-admin/src/main/java/org/perfsonar/webadmin/base2/servlet/BasicConfigurationServlet.java
===================================================================
---
branches/new-structure-with-base2/ps-mdm-web-admin/src/main/java/org/perfsonar/webadmin/base2/servlet/BasicConfigurationServlet.java
2009-12-11 12:18:45 UTC (rev 5405)
+++
branches/new-structure-with-base2/ps-mdm-web-admin/src/main/java/org/perfsonar/webadmin/base2/servlet/BasicConfigurationServlet.java
2009-12-11 13:59:47 UTC (rev 5406)
@@ -1,6 +1,7 @@
package org.perfsonar.webadmin.base2.servlet;
import java.io.IOException;
+import java.util.Locale;
import java.util.logging.Logger;
import javax.servlet.ServletConfig;
@@ -9,13 +10,14 @@
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
+import org.perfsonar.webadmin.base2.servlet.util.Base64;
import org.perfsonar.webadmin.base2.servlet.util.ConfigurationServletHelper;
@SuppressWarnings("serial")
public class BasicConfigurationServlet extends HttpServlet {
- private final Logger logger=Logger.getAnonymousLogger();
-
+ private final Logger logger = Logger.getAnonymousLogger();
+
public void init(ServletConfig arg0) throws ServletException {
super.init(arg0);
logger.info("Servlet initialized");
@@ -29,10 +31,28 @@
*/
protected void doGet(HttpServletRequest request,
HttpServletResponse response) throws
ServletException, IOException {
+
- logger.info("WA --- DO READ");
- ConfigurationServletHelper config=new
ConfigurationServletHelper(request, response, getServletContext());
- config.displayPage();
+ String auth = request.getHeader("Authorization");
+
+ if (!allowUser(auth, "a","a")) {
+ response.setHeader("WWW-Authenticate", "BASIC
realm=\"users\"");
+ response.sendError(response.SC_UNAUTHORIZED);
+ }else{
+ logger.info("WA --- DO READ");
+
+ ConfigurationServletHelper config = new
ConfigurationServletHelper(request,getServletContext());
+ String htmlContent=config.getHTMLContent();
+ if(htmlContent!=null){
+ request.setAttribute("form", htmlContent);
+ }else{
+ logger.warning("form html content is null !");
+ }
+
getServletConfig().getServletContext().getRequestDispatcher(
+
"/index.jsp?page=form").forward(request, response);
+ }
+
+
}
/**
@@ -42,18 +62,49 @@
*/
protected void doPost(HttpServletRequest request,
HttpServletResponse response) throws
ServletException, IOException {
-
- ConfigurationServletHelper config=new
ConfigurationServletHelper(request, response, getServletContext());
+
+ ConfigurationServletHelper config = new
ConfigurationServletHelper(
+ request, response, getServletContext());
logger.info("WA --- DO WRITE");
-
- String urlPath="index.jsp?page=save";
-
- if(config.processData()){
- urlPath+="&ok";
+
+ String urlPath = "index.jsp?page=save";
+
+ if (config.processData()) {
+ urlPath += "&ok";
}
-
+
response.sendRedirect(urlPath);
}
-
+ /**
+ * checks if the user is allowed to invoke this servlet
+ *
+ * @param auth
+ * @param username
+ * @param password
+ * @return
+ * @throws IOException
+ */
+ protected boolean allowUser(String auth, String username, String
password)
+ throws IOException {
+ if (auth == null){
+ return false;
+ }
+
+ if (!auth.toUpperCase(Locale.getDefault()).startsWith("BASIC
")){
+ return false;
+ }
+
+ String userpassEncoded = auth.substring(6);
+
+ Base64 dec=new Base64();
+ String userpassDecoded = new
String(dec.decodeString(userpassEncoded));
+
+ if (userpassDecoded.equals(username + ":" + password))
+ return true;
+ else
+ return false;
+ }
+
+
};
Modified:
branches/new-structure-with-base2/ps-mdm-web-admin/src/main/java/org/perfsonar/webadmin/base2/servlet/util/Base64.java
===================================================================
---
branches/new-structure-with-base2/ps-mdm-web-admin/src/main/java/org/perfsonar/webadmin/base2/servlet/util/Base64.java
2009-12-11 12:18:45 UTC (rev 5405)
+++
branches/new-structure-with-base2/ps-mdm-web-admin/src/main/java/org/perfsonar/webadmin/base2/servlet/util/Base64.java
2009-12-11 13:59:47 UTC (rev 5406)
@@ -23,7 +23,12 @@
for (int i = 0; i < 64; i++)
map2[map1[i]] = (byte) i;
}
+
+
+ public Base64() {
+ }
+
/**
* Encodes a string into Base64 format. No blanks or line breaks are
* inserted.
@@ -156,7 +161,4 @@
return out;
}
- // Dummy constructor.
- private Base64() {
- }
}
Modified:
branches/new-structure-with-base2/ps-mdm-web-admin/src/main/java/org/perfsonar/webadmin/base2/servlet/util/ConfigurationServletHelper.java
===================================================================
---
branches/new-structure-with-base2/ps-mdm-web-admin/src/main/java/org/perfsonar/webadmin/base2/servlet/util/ConfigurationServletHelper.java
2009-12-11 12:18:45 UTC (rev 5405)
+++
branches/new-structure-with-base2/ps-mdm-web-admin/src/main/java/org/perfsonar/webadmin/base2/servlet/util/ConfigurationServletHelper.java
2009-12-11 13:59:47 UTC (rev 5406)
@@ -14,6 +14,7 @@
import org.perfsonar.webadmin.base2.config.HTMLGenerator;
import org.perfsonar.webadmin.base2.config.ObjectMap;
import org.perfsonar.webadmin.base2.util.HTMLUtil;
+import org.perfsonar.webadmin.base2.util.HTMLUtilStringBuffer;
import org.perfsonar.webadmin.base2.util.StringOutputStream;
import org.perfsonar.webadmin.base2.util.Tuple;
@@ -76,7 +77,20 @@
}
}
+
+ public ConfigurationServletHelper(HttpServletRequest
request,ServletContext context) {
+ this.request = request;
+ this.session=request.getSession(true);
+ this.context=context;
+ this.gen = new HTMLGenerator();
+
+ // Set max interval to session
+ if (session.isNew()) {
+ session.setMaxInactiveInterval(SESSION_INTERVAL);
+ }
+ }
+
public ObjectMap objectMap() {
return objectMap(context);
}
@@ -91,6 +105,12 @@
*/
displayPage(pageParameterValue);
}
+
+
+ public String getHTMLContent() {
+ String pageParameterValue = getHttpParameter("page");
+ return getHTMLContent(pageParameterValue);
+ }
/**
*
@@ -126,7 +146,37 @@
}
}
+
+
+ private String getHTMLContent(String pageType) {
+ Tuple<String, String> ret = renderPage(pageType);
+ StringBuffer sb=new StringBuffer();
+
+ if (ret != null) {
+ try {
+ HTMLUtilStringBuffer u = new
HTMLUtilStringBuffer(sb);
+
+ u.preamble();
+ u.form_begin("form_key", ret.first(),
"config?page="
+ + ret.first(), 1);
+ u.simplelineoftext("Please fill in the
following fields:",
+ "green");
+ sb.append(ret.second());
+ u.form_end();
+ u.postscript();
+ String htmlContent=u.getContent();
+ return htmlContent;
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ } else {
+ return null;
+ }
+
+ return null;
+ }
+
@SuppressWarnings("unchecked")
public boolean processData() {
boolean saved=false;
Added:
branches/new-structure-with-base2/ps-mdm-web-admin/src/main/java/org/perfsonar/webadmin/base2/util/HTMLUtilStringBuffer.java
Modified:
branches/new-structure-with-base2/ps-mdm-web-admin/tomcat/html/index.jsp
===================================================================
--- branches/new-structure-with-base2/ps-mdm-web-admin/tomcat/html/index.jsp
2009-12-11 12:18:45 UTC (rev 5405)
+++ branches/new-structure-with-base2/ps-mdm-web-admin/tomcat/html/index.jsp
2009-12-11 13:59:47 UTC (rev 5406)
@@ -1,11 +1,15 @@
-<%@page
import="org.perfsonar.webadmin.base2.servlet.util.ConfigurationServletHelper"%><html>
+<%@page
import="org.perfsonar.webadmin.base2.servlet.util.ConfigurationServletHelper"%>
+<%@page
import="java.util.Enumeration"%>
+<html>
<head>
<title>perfSONAR Service Web Administration page</title>
<link rel="stylesheet" type="text/css" href="main.css"/>
+ <link rel="stylesheet" type="text/css" href="default.css"/>
<meta http-equiv="Content-Type" content="text/html;
charset=iso-8859-1">
<script src="Service_Admin.js"></script>
<style type="text/css">
+
<!--
a {
@@ -64,17 +68,15 @@
</div>
<div class="centerWindow">
<%
- String save = request.getParameter("page");
- System.out.println("page :"+save);
+ String pageParam =
request.getParameter("page");
+ System.out.println("page
:"+pageParam);
if(map==null){
%>
<jsp:include page="parts/error.jsp"/>
<%
-
-
- }else if(save != null && save.equals("save")){
+ }else if(pageParam != null &&
pageParam.equals("save")){
%>
<% if(request.getParameter("ok")!=null){ %>
@@ -82,6 +84,12 @@
<% }else { %>
<jsp:include
page="parts/savedFailed.jsp"/>
<% } %>
+
+ <%
+ }else if(pageParam != null &&
pageParam.equals("form")){
+
out.println(request.getAttribute("form"));
+ %>
+
<%
}else{
%>
- perfsonar: r5406 - in branches/new-structure-with-base2/ps-mdm-web-admin: . ant src/main/java/org/perfsonar/webadmin/base2/servlet src/main/java/org/perfsonar/webadmin/base2/servlet/util src/main/java/org/perfsonar/webadmin/base2/util tomcat/html, svnlog, 12/11/2009
Archive powered by MHonArc 2.6.16.