perfsonar-dev - [GEANT/SA2/ps-java-services] r5477 - in branches/new-structure-with-base2/ps-mdm-base2: . src/main/java/org/perfsonar/base2 src/main/java/org/perfsonar/base2/servlets
Subject: perfsonar development work
List archive
[GEANT/SA2/ps-java-services] r5477 - in branches/new-structure-with-base2/ps-mdm-base2: . src/main/java/org/perfsonar/base2 src/main/java/org/perfsonar/base2/servlets
Chronological Thread
- From:
- To:
- Subject: [GEANT/SA2/ps-java-services] r5477 - in branches/new-structure-with-base2/ps-mdm-base2: . src/main/java/org/perfsonar/base2 src/main/java/org/perfsonar/base2/servlets
- Date: Mon, 8 Feb 2010 10:19:41 GMT
Author: psnc.trzaszczka
Date: 2010-02-08 10:19:41 +0000 (Mon, 08 Feb 2010)
New Revision: 5477
Added:
branches/new-structure-with-base2/ps-mdm-base2/src/main/java/org/perfsonar/base2/servlets/
branches/new-structure-with-base2/ps-mdm-base2/src/main/java/org/perfsonar/base2/servlets/AuthServlet.java
branches/new-structure-with-base2/ps-mdm-base2/src/main/java/org/perfsonar/base2/servlets/ExistDBInitServlet.java
Modified:
branches/new-structure-with-base2/ps-mdm-base2/pom.xml
Log:
Init servlets added
Modified: branches/new-structure-with-base2/ps-mdm-base2/pom.xml
===================================================================
--- branches/new-structure-with-base2/ps-mdm-base2/pom.xml 2010-02-02
15:03:45 UTC (rev 5476)
+++ branches/new-structure-with-base2/ps-mdm-base2/pom.xml 2010-02-08
10:19:41 UTC (rev 5477)
@@ -1,263 +1,282 @@
<?xml version="1.0" encoding="UTF-8"?>
-<!--
+ <!--
- <description>
+ <description> $Id$ project: perfSONAR date: 2009/02/18
author: romradz
- $Id$
- project: perfSONAR
- date: 2009/02/18
- author: romradz
+ </description>
+ -->
- </description>
+<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/maven-v4_0_0.xsd">
--->
-
-<project xmlns="http://maven.apache.org/POM/4.0.0"
- xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/maven-v4_0_0.xsd">
-
- <modelVersion>4.0.0</modelVersion>
- <groupId>perfsonar</groupId>
- <artifactId>ps-mdm-base2</artifactId>
- <packaging>jar</packaging>
- <name>Perfsonar Base2 package</name>
- <version>0.0.3</version>
- <description>
+ <modelVersion>4.0.0</modelVersion>
+ <groupId>perfsonar</groupId>
+ <artifactId>ps-mdm-base2</artifactId>
+ <packaging>jar</packaging>
+ <name>Perfsonar Base2 package</name>
+ <version>0.0.3</version>
+ <description>
The perfSONAR base provides a number of common, shared classes which
can be used by
MA, MP and Clients.
</description>
- <url>
+ <url>
http://wiki.perfsonar.net/
</url>
- <issueManagement>
- <system>bugzilla</system>
- <url>http://bugzilla.perfsonar.net</url>
- </issueManagement>
+ <issueManagement>
+ <system>bugzilla</system>
+ <url>http://bugzilla.perfsonar.net</url>
+ </issueManagement>
- <inceptionYear>2009</inceptionYear>
+ <inceptionYear>2009</inceptionYear>
- <scm>
- <connection>scm:svn:http://anonsvn.internet2.edu/svn/</connection>
- <developerConnection>
+ <scm>
+
<connection>scm:svn:http://anonsvn.internet2.edu/svn/</connection>
+ <developerConnection>
scm:svn:http://svn.internet2.edu/svn/perfsonar/
</developerConnection>
- </scm>
+ </scm>
- <organization>
- <name>perfSONAR</name>
- <url>http://www.perfsonar.net</url>
- </organization>
+ <organization>
+ <name>perfSONAR</name>
+ <url>http://www.perfsonar.net</url>
+ </organization>
- <build>
- <sourceDirectory>${basedir}/src/main/java</sourceDirectory>
- <testSourceDirectory>${basedir}/src/test/java</testSourceDirectory>
- <outputDirectory>${basedir}/bin</outputDirectory>
- <directory>${basedir}/build</directory>
- <plugins>
- <plugin>
- <artifactId>maven-compiler-plugin</artifactId>
- <configuration>
- <source>1.5</source>
- <target>1.5</target>
- </configuration>
- </plugin>
- </plugins>
- </build>
+ <build>
+ <sourceDirectory>${basedir}/src/main/java</sourceDirectory>
+
<testSourceDirectory>${basedir}/src/test/java</testSourceDirectory>
+ <outputDirectory>${basedir}/bin</outputDirectory>
+ <directory>${basedir}/build</directory>
+ <plugins>
+ <plugin>
+ <artifactId>maven-compiler-plugin</artifactId>
+ <configuration>
+ <source>1.6</source>
+ <target>1.6</target>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
- <repositories>
- <repository>
- <id>ibiblio</id>
- <name>ibiblio repository</name>
- <url>http://www.ibiblio.org/maven2</url>
- </repository>
- <repository>
- <id>personar</id>
- <name>personar repository</name>
- <url>
+ <repositories>
+ <repository>
+ <id>ibiblio</id>
+ <name>ibiblio repository</name>
+ <url>http://www.ibiblio.org/maven2</url>
+ </repository>
+ <repository>
+ <id>personar</id>
+ <name>personar repository</name>
+ <url>
http://anonsvn.internet2.edu/svn/perfsonar/trunk/jar-repository/
</url>
- </repository>
- <repository>
- <id>personar_leg</id>
- <name>personar repository</name>
- <url>
+ </repository>
+ <repository>
+ <id>personar_leg</id>
+ <name>personar repository</name>
+ <url>
http://anonsvn.internet2.edu/svn/perfsonar/trunk/jar-repository/
</url>
- <layout>legacy</layout>
- </repository>
- <repository>
- <id>codehaus-release-repo</id>
- <name>Codehaus Release Repo</name>
- <url>http://repository.codehaus.org</url>
- </repository>
- </repositories>
+ <layout>legacy</layout>
+ </repository>
+ <repository>
+ <id>codehaus-release-repo</id>
+ <name>Codehaus Release Repo</name>
+ <url>http://repository.codehaus.org</url>
+ </repository>
+ </repositories>
- <dependencies>
- <dependency>
- <groupId>commons-digester</groupId>
- <artifactId>commons-digester</artifactId>
- <version>2.0</version>
- </dependency>
- <dependency>
- <groupId>org.apache.axis2</groupId>
- <artifactId>axis2-jaxws</artifactId>
- <version>1.4.1</version>
- </dependency>
+ <dependencies>
+ <dependency>
+ <groupId>commons-digester</groupId>
+ <artifactId>commons-digester</artifactId>
+ <version>2.0</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.axis2</groupId>
+ <artifactId>axis2-jaxws</artifactId>
+ <version>1.4.1</version>
+ </dependency>
- <!-- got for auth -->
- <dependency>
- <groupId>opensaml</groupId>
- <artifactId>opensaml1</artifactId>
- <version>1.1</version>
- </dependency>
- <dependency>
- <groupId>bouncycastle</groupId>
- <artifactId>bcprov-jdk15</artifactId>
- <version>124</version>
- </dependency>
- <dependency>
- <groupId>xml-security</groupId>
- <artifactId>xmlsec</artifactId>
- <version>1.3.0</version>
- </dependency>
- <dependency>
- <groupId>edugain</groupId>
- <artifactId>edugain</artifactId>
- <version>1.0-RC2</version>
- </dependency>
- <dependency>
- <groupId>perfsonar</groupId>
- <artifactId>perfsonar-authr</artifactId>
- <version>0.5</version>
- </dependency>
- <dependency>
- <groupId>sasl-ca</groupId>
- <artifactId>sasl-ca</artifactId>
- <version>1.0</version>
- </dependency>
- <dependency>
- <groupId>codec</groupId>
- <artifactId>codec</artifactId>
- <version>1.0</version>
- </dependency>
- <dependency>
- <groupId>org.slf4j</groupId>
- <artifactId>slf4j-log4j12</artifactId>
- <version>1.0.1</version>
- </dependency>
- <dependency>
- <groupId>opensaml</groupId>
- <artifactId>opensaml</artifactId>
- <version>2.2.3</version>
- </dependency>
- <dependency>
- <groupId>xmltooling</groupId>
- <artifactId>xmltooling</artifactId>
- <version>1.2.0</version>
- </dependency>
- <dependency>
- <groupId>wss4j</groupId>
- <artifactId>wss4j</artifactId>
- <version>1.5.1</version>
- </dependency>
- <dependency>
- <groupId>org.apache.rampart</groupId>
- <artifactId>rampart-core</artifactId>
- <version>1.4</version>
- </dependency>
- <dependency>
- <groupId>xerces</groupId>
- <artifactId>xercesImpl</artifactId>
- <version>2.8.0</version>
- </dependency>
- <dependency>
- <groupId>xerces</groupId>
- <artifactId>xerces-xml-apis</artifactId>
- <version>2.8.0</version>
- </dependency>
- <dependency>
- <groupId>xalan</groupId>
- <artifactId>xalan</artifactId>
- <version>2.7.0</version>
- </dependency>
- <dependency>
- <groupId>xalan</groupId>
- <artifactId>xalan-serializer</artifactId>
- <version>2.7.0</version>
- </dependency>
- <dependency>
- <groupId>com.sun.xacml</groupId>
- <artifactId>sunxacml</artifactId>
- <version>1.2</version>
- </dependency>
- </dependencies>
+ <!-- got for auth -->
+ <dependency>
+ <groupId>opensaml</groupId>
+ <artifactId>opensaml1</artifactId>
+ <version>1.1</version>
+ </dependency>
+ <dependency>
+ <groupId>bouncycastle</groupId>
+ <artifactId>bcprov-jdk15</artifactId>
+ <version>124</version>
+ </dependency>
+ <dependency>
+ <groupId>xml-security</groupId>
+ <artifactId>xmlsec</artifactId>
+ <version>1.3.0</version>
+ </dependency>
+ <dependency>
+ <groupId>edugain</groupId>
+ <artifactId>edugain</artifactId>
+ <version>1.0-RC2</version>
+ </dependency>
+ <dependency>
+ <groupId>perfsonar</groupId>
+ <artifactId>perfsonar-authr</artifactId>
+ <version>0.5</version>
+ </dependency>
+ <dependency>
+ <groupId>sasl-ca</groupId>
+ <artifactId>sasl-ca</artifactId>
+ <version>1.0</version>
+ </dependency>
+ <dependency>
+ <groupId>codec</groupId>
+ <artifactId>codec</artifactId>
+ <version>1.0</version>
+ </dependency>
+ <dependency>
+ <groupId>org.slf4j</groupId>
+ <artifactId>slf4j-log4j12</artifactId>
+ <version>1.0.1</version>
+ </dependency>
+ <dependency>
+ <groupId>opensaml</groupId>
+ <artifactId>opensaml</artifactId>
+ <version>2.2.3</version>
+ </dependency>
+ <dependency>
+ <groupId>xmltooling</groupId>
+ <artifactId>xmltooling</artifactId>
+ <version>1.2.0</version>
+ </dependency>
+ <dependency>
+ <groupId>wss4j</groupId>
+ <artifactId>wss4j</artifactId>
+ <version>1.5.1</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.rampart</groupId>
+ <artifactId>rampart-core</artifactId>
+ <version>1.4</version>
+ </dependency>
+ <dependency>
+ <groupId>xerces</groupId>
+ <artifactId>xercesImpl</artifactId>
+ <version>2.8.0</version>
+ </dependency>
+ <dependency>
+ <groupId>xerces</groupId>
+ <artifactId>xerces-xml-apis</artifactId>
+ <version>2.8.0</version>
+ </dependency>
+ <dependency>
+ <groupId>xalan</groupId>
+ <artifactId>xalan</artifactId>
+ <version>2.7.0</version>
+ </dependency>
+ <dependency>
+ <groupId>xalan</groupId>
+ <artifactId>xalan-serializer</artifactId>
+ <version>2.7.0</version>
+ </dependency>
+ <dependency>
+ <groupId>com.sun.xacml</groupId>
+ <artifactId>sunxacml</artifactId>
+ <version>1.2</version>
+ </dependency>
- <reporting>
- <excludeDefaults>true</excludeDefaults>
- <outputDirectory>${basedir}/doc/site</outputDirectory>
- <plugins>
- <plugin>
- <artifactId>
+
+
+ <!-- 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>
+
+
+ </dependencies>
+
+
+ <reporting>
+ <excludeDefaults>true</excludeDefaults>
+ <outputDirectory>${basedir}/doc/site</outputDirectory>
+ <plugins>
+ <plugin>
+ <artifactId>
maven-project-info-reports-plugin
</artifactId>
- <reportSets>
- <reportSet>
- <reports>
- <report>index</report>
- <report>summary</report>
- <report>dependencies</report>
- <report>mailing-list</report>
- <report>issue-tracking</report>
- <report>scm</report>
- </reports>
- </reportSet>
- </reportSets>
- </plugin>
- <plugin>
- <artifactId>maven-javadoc-plugin</artifactId>
- </plugin>
- <plugin>
- <artifactId>maven-jxr-plugin</artifactId>
- </plugin>
- <plugin>
- <groupId>org.codehaus.mojo</groupId>
- <artifactId>taglist-maven-plugin</artifactId>
- </plugin>
- <plugin>
- <groupId>org.codehaus.mojo</groupId>
- <artifactId>javancss-maven-plugin</artifactId>
- <configuration>
- <failOnViolation>false</failOnViolation>
- </configuration>
- </plugin>
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-pmd-plugin</artifactId>
- <configuration>
- <linkXref>true</linkXref>
- <sourceEncoding>utf-8</sourceEncoding>
- <minimumTokens>100</minimumTokens>
- <targetJdk>1.5</targetJdk>
- </configuration>
- </plugin>
- <plugin>
- <groupId>org.codehaus.mojo</groupId>
- <artifactId>findbugs-maven-plugin</artifactId>
- <version>1.2</version>
- <configuration>
- <findbugsXmlOutput>true</findbugsXmlOutput>
- <xmlOutput>true</xmlOutput>
- </configuration>
- </plugin>
- <!--
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-changelog-plugin</artifactId>
- </plugin>
- -->
- </plugins>
- </reporting>
+ <reportSets>
+ <reportSet>
+ <reports>
+ <report>index</report>
+
<report>summary</report>
+
<report>dependencies</report>
+
<report>mailing-list</report>
+
<report>issue-tracking</report>
+ <report>scm</report>
+ </reports>
+ </reportSet>
+ </reportSets>
+ </plugin>
+ <plugin>
+ <artifactId>maven-javadoc-plugin</artifactId>
+ </plugin>
+ <plugin>
+ <artifactId>maven-jxr-plugin</artifactId>
+ </plugin>
+ <plugin>
+ <groupId>org.codehaus.mojo</groupId>
+ <artifactId>taglist-maven-plugin</artifactId>
+ </plugin>
+ <plugin>
+ <groupId>org.codehaus.mojo</groupId>
+ <artifactId>javancss-maven-plugin</artifactId>
+ <configuration>
+
<failOnViolation>false</failOnViolation>
+ </configuration>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-pmd-plugin</artifactId>
+ <configuration>
+ <linkXref>true</linkXref>
+ <sourceEncoding>utf-8</sourceEncoding>
+ <minimumTokens>100</minimumTokens>
+ <targetJdk>1.5</targetJdk>
+ </configuration>
+ </plugin>
+ <plugin>
+ <groupId>org.codehaus.mojo</groupId>
+ <artifactId>findbugs-maven-plugin</artifactId>
+ <version>1.2</version>
+ <configuration>
+
<findbugsXmlOutput>true</findbugsXmlOutput>
+ <xmlOutput>true</xmlOutput>
+ </configuration>
+ </plugin>
+ <!--
+ <plugin>
<groupId>org.apache.maven.plugins</groupId>
+
<artifactId>maven-changelog-plugin</artifactId> </plugin>
+ -->
+ </plugins>
+ </reporting>
</project>
Added:
branches/new-structure-with-base2/ps-mdm-base2/src/main/java/org/perfsonar/base2/servlets/AuthServlet.java
===================================================================
---
branches/new-structure-with-base2/ps-mdm-base2/src/main/java/org/perfsonar/base2/servlets/AuthServlet.java
(rev 0)
+++
branches/new-structure-with-base2/ps-mdm-base2/src/main/java/org/perfsonar/base2/servlets/AuthServlet.java
2010-02-08 10:19:41 UTC (rev 5477)
@@ -0,0 +1,91 @@
+package org.perfsonar.base2.servlets;
+
+import java.io.IOException;
+import java.util.Locale;
+
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServlet;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import org.perfsonar.base2.service.configuration.ConfigurationManager;
+import org.perfsonar.base2.service.exceptions.PerfSONARException;
+
+/**
+ *
+ * this servlet requires login and password from user
+ *
+ * @author Slawomir Trzaszczka
+ */
+@SuppressWarnings("serial")
+public abstract class AuthServlet extends HttpServlet {
+
+ /*
+ * returns username for allowed user
+ */
+ protected abstract String getUsername(ConfigurationManager
configManager) throws PerfSONARException ;
+
+ /*
+ * returns password for allowed user;
+ */
+ protected abstract String getPassword(ConfigurationManager
configManager) throws PerfSONARException ;
+
+ /**
+ *
+ * this method is executed whether user privileges are correct
+ *
+ * @param req
+ * @param resp
+ */
+ protected abstract void processRequest(HttpServletRequest req,
HttpServletResponse resp);
+
+
+ @Override
+ protected void doGet(HttpServletRequest req, HttpServletResponse resp)
+ throws ServletException, IOException {
+
+ String auth = req.getHeader("Authorization");
+ try {
+ ConfigurationManager configManager =
ConfigurationManager.getInstance();
+ if
(!allowUser(auth,getUsername(configManager), getPassword(configManager))) {
+ resp.setHeader("WWW-Authenticate",
"BASIC realm=\"users\"");
+
resp.sendError(HttpServletResponse.SC_UNAUTHORIZED);
+ } else {
+ processRequest(req, resp);
+ }
+ } catch (PerfSONARException e) {
+ e.printStackTrace();
+ }
+
+ }
+
+ /**
+ * checks if the user is allowed to invoke this servlet
+ *
+ * @param auth
+ * @param username
+ * @param password
+ * @return
+ * @throws IOException
+ */
+ private 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);
+
+ 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;
+ }
+}
Added:
branches/new-structure-with-base2/ps-mdm-base2/src/main/java/org/perfsonar/base2/servlets/ExistDBInitServlet.java
===================================================================
---
branches/new-structure-with-base2/ps-mdm-base2/src/main/java/org/perfsonar/base2/servlets/ExistDBInitServlet.java
(rev 0)
+++
branches/new-structure-with-base2/ps-mdm-base2/src/main/java/org/perfsonar/base2/servlets/ExistDBInitServlet.java
2010-02-08 10:19:41 UTC (rev 5477)
@@ -0,0 +1,87 @@
+package org.perfsonar.base2.servlets;
+
+import java.io.File;
+
+import org.exist.security.User;
+import org.exist.xmldb.UserManagementService;
+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;
+
+/**
+ *
+ * Supports Initialization of ExistDB
+ *
+ * @author Slawomir Trzaszczka
+ *
+ */
+@SuppressWarnings("serial")
+public abstract class ExistDBInitServlet extends AuthServlet {
+
+ /**
+ *
+ * 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
+ */
+ protected 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);
+ }
+
+ @SuppressWarnings("unchecked")
+ protected Collection getMainCollection(String dbUrl) {
+ try {
+ Class cl =
Class.forName("org.exist.xmldb.DatabaseImpl");
+ Database database = (Database) cl.newInstance();
+ DatabaseManager.registerDatabase(database);
+ Collection collection =
DatabaseManager.getCollection(dbUrl,
+ "admin", "");
+ return collection;
+ } catch (ClassNotFoundException e) {
+ e.printStackTrace();
+ } catch (InstantiationException e) {
+ e.printStackTrace();
+ } catch (IllegalAccessException e) {
+ e.printStackTrace();
+ } catch (XMLDBException e) {
+ e.printStackTrace();
+ }
+ return null;
+ }
+
+ protected UserManagementService getUserManagmentService(
+ Collection collection) throws XMLDBException {
+ return (UserManagementService) collection.getService(
+ "UserManagementService", "1.0");
+ }
+
+ protected CollectionManagementService getCollectionManagmentService(
+ Collection collection) throws XMLDBException {
+ return (CollectionManagementService) collection.getService(
+ "CollectionManagementService", "1.0");
+ }
+
+ protected User createUser(String username,String password,String
group){
+ User user = new User(username,password);
+ user.addGroup(group);
+
+ return user;
+ }
+
+}
- [GEANT/SA2/ps-java-services] r5477 - in branches/new-structure-with-base2/ps-mdm-base2: . src/main/java/org/perfsonar/base2 src/main/java/org/perfsonar/base2/servlets, svn-noreply, 02/08/2010
Archive powered by MHonArc 2.6.16.