perfsonar-dev - [GEANT/SA2/ps-java-services] r5478 - in branches/new-structure-with-base2/ps-mdm-ls: . src/main/java/org/perfsonar/service/lookupservice/servlets
Subject: perfsonar development work
List archive
[GEANT/SA2/ps-java-services] r5478 - in branches/new-structure-with-base2/ps-mdm-ls: . src/main/java/org/perfsonar/service/lookupservice/servlets
Chronological Thread
- From:
- To:
- Subject: [GEANT/SA2/ps-java-services] r5478 - in branches/new-structure-with-base2/ps-mdm-ls: . src/main/java/org/perfsonar/service/lookupservice/servlets
- Date: Mon, 8 Feb 2010 10:32:13 GMT
Author: psnc.trzaszczka
Date: 2010-02-08 10:32:13 +0000 (Mon, 08 Feb 2010)
New Revision: 5478
Modified:
branches/new-structure-with-base2/ps-mdm-ls/pom.xml
branches/new-structure-with-base2/ps-mdm-ls/src/main/java/org/perfsonar/service/lookupservice/servlets/ExistDbInitializerServlet.java
Log:
initialization Servlet changed
Modified: branches/new-structure-with-base2/ps-mdm-ls/pom.xml
===================================================================
--- branches/new-structure-with-base2/ps-mdm-ls/pom.xml 2010-02-08 10:19:41
UTC (rev 5477)
+++ branches/new-structure-with-base2/ps-mdm-ls/pom.xml 2010-02-08 10:32:13
UTC (rev 5478)
@@ -204,29 +204,7 @@
<version>0.0.3</version>
</dependency>
- <!-- ExistDB initalizer -->
-
<dependency>
- <groupId>xmldb</groupId>
- <artifactId>xmldb-api</artifactId>
- <version>20021118</version>
- </dependency>
- <dependency>
- <groupId>exist</groupId>
- <artifactId>exist-db</artifactId>
- <version>1.0rc</version>
- </dependency>
- <dependency>
- <groupId>exist</groupId>
- <artifactId>exist-xmlrpc</artifactId>
- <version>1.0rc</version>
- </dependency>
- <dependency>
- <artifactId>xmlrpc-client</artifactId>
- <groupId>org.apache.xmlrpc</groupId>
- <version>3.0</version>
- </dependency>
- <dependency>
<artifactId>xmlrpc-common</artifactId>
<groupId>org.apache.xmlrpc</groupId>
<version>3.0</version>
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
2010-02-08 10:19:41 UTC (rev 5477)
+++
branches/new-structure-with-base2/ps-mdm-ls/src/main/java/org/perfsonar/service/lookupservice/servlets/ExistDbInitializerServlet.java
2010-02-08 10:32:13 UTC (rev 5478)
@@ -4,10 +4,7 @@
import java.io.IOException;
import java.io.PrintWriter;
import java.net.URISyntaxException;
-import java.util.Locale;
-import javax.servlet.ServletException;
-import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
@@ -16,13 +13,11 @@
import org.exist.xmldb.XmldbURI;
import org.perfsonar.base2.service.configuration.ConfigurationManager;
import org.perfsonar.base2.service.exceptions.PerfSONARException;
+import org.perfsonar.base2.servlets.ExistDBInitServlet;
import org.perfsonar.service.lookupservice.components.DataSourceComponent;
-import org.xmldb.api.DatabaseManager;
import org.xmldb.api.base.Collection;
-import org.xmldb.api.base.Database;
import org.xmldb.api.base.XMLDBException;
import org.xmldb.api.modules.CollectionManagementService;
-import org.xmldb.api.modules.XMLResource;
/**
* This servlet initializes eXist database
@@ -31,33 +26,10 @@
*
*/
@SuppressWarnings("serial")
-public class ExistDbInitializerServlet extends HttpServlet {
+public class ExistDbInitializerServlet extends ExistDBInitServlet {
/**
*
- * 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
- * @throws XMLDBException
- */
- private void uploadFile(String fileName, String filePath,
- Collection collection) throws XMLDBException {
-
- XMLResource document = (XMLResource)
collection.createResource(
- fileName, "XMLResource");
- File f = new File(filePath + "/" + fileName);
- document.setContent(f);
- collection.storeResource(document);
- }
-
- /**
- *
* main function which initializes database
*
*
@@ -68,12 +40,9 @@
* @throws IOException
* @throws PerfSONARException
*/
- @SuppressWarnings("unchecked")
public boolean initializeDatabase(String dbContentDirPath,
ConfigurationManager configManager) throws
PerfSONARException {
try {
- Class cl =
Class.forName("org.exist.xmldb.DatabaseImpl");
- Database database = (Database) cl.newInstance();
DataSourceComponent existDbComponent =
(DataSourceComponent) configManager
.getConfiguration()
@@ -81,15 +50,12 @@
String dbUrl = existDbComponent.getUrl();
- DatabaseManager.registerDatabase(database);
- Collection collection =
DatabaseManager.getCollection(dbUrl,
- "admin", "");
- UserManagementService usrMngmtService =
(UserManagementService) collection
- .getService("UserManagementService",
"1.0");
- CollectionManagementService colMngmtService =
(CollectionManagementService) collection
-
.getService("CollectionManagementService", "1.0");
+ Collection collection = getMainCollection(dbUrl);
+ UserManagementService usrMngmtService =
getUserManagmentService(collection);
+ CollectionManagementService colMngmtService =
getCollectionManagmentService(collection);
+
Collection lsCollection =
colMngmtService.createCollection("ls");
Collection copyCollection = colMngmtService
.createCollection("copy");
@@ -104,15 +70,13 @@
.getResource(resourceName));
}
- User user = new User(existDbComponent.getUsername(),
- existDbComponent.getPassword());
- user.addGroup("dba");
+ User user=createUser(existDbComponent.getUsername(),
+ existDbComponent.getPassword(),
"dba");
user.setHome(XmldbURI.xmldbUriFor("ls"));
if (existDbComponent.hasReadOnlyUser()) {
- User userRO = new
User(existDbComponent.getUsernameRO(),
-
existDbComponent.getPasswordRO());
- userRO.addGroup("guest");
+ User
userRO=createUser(existDbComponent.getUsernameRO(),
+
existDbComponent.getPasswordRO(), "guest");
usrMngmtService.addUser(userRO);
}
@@ -126,12 +90,6 @@
uploadFile("LSStore-summary.xml", dbContentDirPath,
copyCollection);
return true;
- } catch (ClassNotFoundException e) {
- throw new PerfSONARException(e.getMessage());
- } catch (InstantiationException e) {
- throw new PerfSONARException(e.getMessage());
- } catch (IllegalAccessException e) {
- throw new PerfSONARException(e.getMessage());
} catch (PerfSONARException e) {
throw new PerfSONARException(e.getMessage());
} catch (XMLDBException e) {
@@ -141,67 +99,40 @@
}
}
- /**
- * 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;
- }
+ @Override
+ protected String getPassword(ConfigurationManager configManager)
+ throws PerfSONARException {
- if (!auth.toUpperCase(Locale.getDefault()).startsWith("BASIC
")) {
- return false;
- }
+ return ((DataSourceComponent) configManager.getConfiguration()
+
.getAuxiliaryComponent("existDataSource")).getPassword();
+ }
- 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;
+ @Override
+ protected String getUsername(ConfigurationManager configManager)
+ throws PerfSONARException {
+ return ((DataSourceComponent) configManager.getConfiguration()
+
.getAuxiliaryComponent("existDataSource")).getUsername();
}
- @SuppressWarnings("static-access")
@Override
- protected void doGet(HttpServletRequest req, HttpServletResponse resp)
- throws ServletException, IOException {
+ protected void processRequest(HttpServletRequest req,
+ HttpServletResponse resp) {
- PrintWriter out = resp.getWriter();
- ConfigurationManager configManager;
try {
+ PrintWriter out = resp.getWriter();
+ ConfigurationManager configManager;
configManager = ConfigurationManager.getInstance();
- DataSourceComponent dataSource =
(DataSourceComponent) configManager
- .getConfiguration()
-
.getAuxiliaryComponent("existDataSource");
-
- String auth = req.getHeader("Authorization");
-
- if (!allowUser(auth, dataSource.getUsername(),
dataSource
- .getPassword())) {
- resp.setHeader("WWW-Authenticate", "BASIC
realm=\"users\"");
- resp.sendError(resp.SC_UNAUTHORIZED);
- } else {
- File dir = new File(".");
- String dbContentDirPath =
dir.getCanonicalPath()
- + "/../webapps" +
req.getContextPath() + "/db";
- try {
- initializeDatabase(dbContentDirPath,
configManager);
- out.append("DbInitializer - success");
- } catch (PerfSONARException ex) {
- out.append(ex.getMessage());
- }
-
+ File dir = new File(".");
+ String dbContentDirPath = dir.getCanonicalPath() +
"/../webapps"
+ + req.getContextPath() + "/db";
+ try {
+ initializeDatabase(dbContentDirPath,
configManager);
+ out.append("DbInitializer - success");
+ } catch (PerfSONARException ex) {
+ out.append(ex.getMessage());
}
+ } catch (IOException e) {
+ e.printStackTrace();
} catch (PerfSONARException e) {
e.printStackTrace();
}
- [GEANT/SA2/ps-java-services] r5478 - in branches/new-structure-with-base2/ps-mdm-ls: . src/main/java/org/perfsonar/service/lookupservice/servlets, svn-noreply, 02/08/2010
Archive powered by MHonArc 2.6.16.