perfsonar-dev - perfsonar: r5334 - in branches/new-structure-with-base2/ps-mdm-ls: resources/axis2-1.4.1/webapp/WEB-INF src/main/java/org/perfsonar/service/lookupservice/servlets
Subject: perfsonar development work
List archive
perfsonar: r5334 - in branches/new-structure-with-base2/ps-mdm-ls: resources/axis2-1.4.1/webapp/WEB-INF src/main/java/org/perfsonar/service/lookupservice/servlets
Chronological Thread
- From:
- To:
- Subject: perfsonar: r5334 - in branches/new-structure-with-base2/ps-mdm-ls: resources/axis2-1.4.1/webapp/WEB-INF src/main/java/org/perfsonar/service/lookupservice/servlets
- Date: Tue, 3 Nov 2009 05:55:07 -0500
Author: trzaszcz
Date: 2009-11-03 05:55:07 -0500 (Tue, 03 Nov 2009)
New Revision: 5334
Modified:
branches/new-structure-with-base2/ps-mdm-ls/resources/axis2-1.4.1/webapp/WEB-INF/web.xml
branches/new-structure-with-base2/ps-mdm-ls/src/main/java/org/perfsonar/service/lookupservice/servlets/ExistDbInitializerServlet.java
Log:
init db servlet improvement
Modified:
branches/new-structure-with-base2/ps-mdm-ls/resources/axis2-1.4.1/webapp/WEB-INF/web.xml
===================================================================
---
branches/new-structure-with-base2/ps-mdm-ls/resources/axis2-1.4.1/webapp/WEB-INF/web.xml
2009-11-02 13:57:19 UTC (rev 5333)
+++
branches/new-structure-with-base2/ps-mdm-ls/resources/axis2-1.4.1/webapp/WEB-INF/web.xml
2009-11-03 10:55:07 UTC (rev 5334)
@@ -89,6 +89,7 @@
</welcome-file-list>
<!--
+ commented - better to print stack trace to web page
<error-page>
<error-code>404</error-code>
<location>/axis2-web/Error/error404.jsp</location>
Modified:
branches/new-structure-with-base2/ps-mdm-ls/src/main/java/org/perfsonar/service/lookupservice/servlets/ExistDbInitializerServlet.java
===================================================================
---
branches/new-structure-with-base2/ps-mdm-ls/src/main/java/org/perfsonar/service/lookupservice/servlets/ExistDbInitializerServlet.java
2009-11-02 13:57:19 UTC (rev 5333)
+++
branches/new-structure-with-base2/ps-mdm-ls/src/main/java/org/perfsonar/service/lookupservice/servlets/ExistDbInitializerServlet.java
2009-11-03 10:55:07 UTC (rev 5334)
@@ -2,6 +2,7 @@
import java.io.File;
import java.io.IOException;
+import java.io.PrintWriter;
import java.net.URISyntaxException;
import javax.servlet.ServletException;
@@ -23,11 +24,10 @@
import org.xmldb.api.modules.XMLResource;
/**
- *
* This servlet initializes eXist database
*
* @author trzaszcz
- *
+ *
*/
@SuppressWarnings("serial")
public class ExistDbInitializerServlet extends HttpServlet {
@@ -36,32 +36,35 @@
*
* upload file to eXistDatabase
*
- * @param fileName - name of the file which contains content of the
database element
- * @param filePath - path to file
- * @param collection - collection where new database element will be
added in
+ * @param fileName
+ * - name of the file which contains content of the
database
+ * element
+ * @param filePath
+ * - path to file
+ * @param collection
+ * - collection where new database element will be added in
* @throws XMLDBException
*/
- private void uploadFile(String fileName,String filePath,Collection
collection) throws XMLDBException{
+ private void uploadFile(String fileName, String filePath,
+ Collection collection) throws XMLDBException {
- XMLResource document = (XMLResource)
collection.createResource(fileName,
- "XMLResource");
+ XMLResource document = (XMLResource)
collection.createResource(
+ fileName, "XMLResource");
File f = new File(filePath + "/" + fileName);
document.setContent(f);
collection.storeResource(document);
}
-
+
@SuppressWarnings("unchecked")
- @Override
- protected void doGet(HttpServletRequest req, HttpServletResponse resp)
- throws ServletException, IOException {
-
+ private void initializeDatabase(HttpServletRequest req, PrintWriter
writer,
+ ConfigurationManager configManager) throws
IOException {
try {
Class cl =
Class.forName("org.exist.xmldb.DatabaseImpl");
Database database = (Database) cl.newInstance();
- ConfigurationManager configManager =
ConfigurationManager
- .getInstance();
+
XMLDBComponent existDbComponent = (XMLDBComponent)
configManager
.getConfiguration().getAuxiliaryComponent("exist");
+
XMLDBComponent existRODbComponent = (XMLDBComponent)
configManager
.getConfiguration().getAuxiliaryComponent("exist-ro");
@@ -81,50 +84,112 @@
Collection copyCollection = colMngmtService
.createCollection("copy");
- User user = new
User(existDbComponent.getCredential().getUsername(),
existDbComponent.getCredential().getPassword());
+ User user = new User(
+
existDbComponent.getCredential().getUsername(),
+
existDbComponent.getCredential().getPassword());
user.addGroup("dba");
user.setHome(XmldbURI.xmldbUriFor("ls"));
User userRO = new
User(existRODbComponent.getCredential()
- .getUsername(),
existRODbComponent.getCredential().getPassword());
+ .getUsername(),
existRODbComponent.getCredential()
+ .getPassword());
userRO.addGroup("guest");
usrMngmtService.addUser(user);
-
+
usrMngmtService.addUser(userRO);
-
File dir = new File(".");
String dbPath = dir.getCanonicalPath() + "/../webapps"
+ req.getContextPath() + "/db";
- resp.getWriter().append("DbInitializer");
+ writer.append("DbInitializer - success");
- uploadFile("LSStore.xml",dbPath,lsCollection);
- uploadFile("LSStore-control.xml",dbPath,lsCollection);
- uploadFile("LSStore-summary.xml",dbPath,lsCollection);
-
-
uploadFile("LSStore-summary.xml",dbPath,copyCollection);
-
+ uploadFile("LSStore.xml", dbPath, lsCollection);
+ uploadFile("LSStore-control.xml", dbPath,
lsCollection);
+ uploadFile("LSStore-summary.xml", dbPath,
lsCollection);
+
+ uploadFile("LSStore-summary.xml", dbPath,
copyCollection);
+
} catch (ClassNotFoundException e) {
e.printStackTrace();
- resp.getWriter().append("error :" + e.getMessage());
+ writer.append("error :" + e.getMessage());
} catch (InstantiationException e) {
- resp.getWriter().append("error :" + e.getMessage());
+ writer.append("error :" + e.getMessage());
e.printStackTrace();
} catch (IllegalAccessException e) {
- resp.getWriter().append("error :" + e.getMessage());
+ writer.append("error :" + e.getMessage());
e.printStackTrace();
} catch (PerfSONARException e) {
- resp.getWriter().append("error :" + e.getMessage());
+ writer.append("error :" + e.getMessage());
e.printStackTrace();
} catch (XMLDBException e) {
- resp.getWriter().append("error :" + e.getMessage());
+ writer.append("error :" + e.getMessage());
e.printStackTrace();
} catch (URISyntaxException e) {
- resp.getWriter().append("error :" + e.getMessage());
+ writer.append("error :" + e.getMessage());
e.printStackTrace();
+ } catch (IOException e) {
+ e.printStackTrace();
}
}
+
+ /**
+ * 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().startsWith("BASIC "))
+ return false;
+
+ String userpassEncoded = auth.substring(6);
+
+ sun.misc.BASE64Decoder dec = new sun.misc.BASE64Decoder();
+ String userpassDecoded = new
String(dec.decodeBuffer(userpassEncoded));
+
+ if (userpassDecoded.equals(username + ":" + password))
+ return true;
+ else
+ return false;
+ }
+
+
+ @SuppressWarnings("static-access")
+ @Override
+ protected void doGet(HttpServletRequest req, HttpServletResponse resp)
+ throws ServletException, IOException {
+
+ PrintWriter out = resp.getWriter();
+ ConfigurationManager configManager;
+ try {
+ configManager = ConfigurationManager.getInstance();
+ XMLDBComponent existDbComponent = (XMLDBComponent)
configManager
+
.getConfiguration().getAuxiliaryComponent("exist");
+
+ String auth = req.getHeader("Authorization");
+
+ if (!allowUser(auth,
existDbComponent.getCredential().getUsername(),
+
existDbComponent.getCredential().getPassword())) {
+ resp.setHeader("WWW-Authenticate", "BASIC
realm=\"users\"");
+ resp.sendError(resp.SC_UNAUTHORIZED);
+ } else {
+ initializeDatabase(req, out, configManager);
+ }
+ } catch (PerfSONARException e) {
+ e.printStackTrace();
+ }
+
+
+
+ }
}
- perfsonar: r5334 - in branches/new-structure-with-base2/ps-mdm-ls: resources/axis2-1.4.1/webapp/WEB-INF src/main/java/org/perfsonar/service/lookupservice/servlets, svnlog, 11/03/2009
Archive powered by MHonArc 2.6.16.