perfsonar-dev - [GEANT/SA2/ps-java-services] r5645 - in branches: . perfsonar-java-base2-stable-1.0.1/src/main/java/org/perfsonar/base2/servlets
Subject: perfsonar development work
List archive
[GEANT/SA2/ps-java-services] r5645 - in branches: . perfsonar-java-base2-stable-1.0.1/src/main/java/org/perfsonar/base2/servlets
Chronological Thread
- From:
- To:
- Subject: [GEANT/SA2/ps-java-services] r5645 - in branches: . perfsonar-java-base2-stable-1.0.1/src/main/java/org/perfsonar/base2/servlets
- Date: Fri, 14 May 2010 15:07:18 +0100
Author: psnc.trzaszczka
Date: 2010-05-14 15:07:18 +0100 (Fri, 14 May 2010)
New Revision: 5645
Added:
branches/perfsonar-java-base2-stable-1.0.1/
branches/perfsonar-java-base2-stable-1.0.1/src/main/java/org/perfsonar/base2/servlets/AuthServlet.java
branches/perfsonar-java-base2-stable-1.0.1/src/main/java/org/perfsonar/base2/servlets/ExistDBInitServlet.java
Removed:
branches/perfsonar-java-base2-stable-1.0.1/src/main/java/org/perfsonar/base2/servlets/AuthServlet.java
branches/perfsonar-java-base2-stable-1.0.1/src/main/java/org/perfsonar/base2/servlets/ExistDBInitServlet.java
Log:
Copied: branches/perfsonar-java-base2-stable-1.0.1 (from rev 5629,
trunk/perfsonar-java-base2)
Deleted:
branches/perfsonar-java-base2-stable-1.0.1/src/main/java/org/perfsonar/base2/servlets/AuthServlet.java
===================================================================
---
trunk/perfsonar-java-base2/src/main/java/org/perfsonar/base2/servlets/AuthServlet.java
2010-05-13 10:41:31 UTC (rev 5629)
+++
branches/perfsonar-java-base2-stable-1.0.1/src/main/java/org/perfsonar/base2/servlets/AuthServlet.java
2010-05-14 14:07:18 UTC (rev 5645)
@@ -1,91 +0,0 @@
-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.apache.commons.codec.binary.Base64;
-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);
-
- String userpassDecoded = new
String(Base64.decodeBase64(userpassEncoded.getBytes()));
-
- if (userpassDecoded.equals(username + ":" + password))
- return true;
- else
- return false;
- }
-}
Copied:
branches/perfsonar-java-base2-stable-1.0.1/src/main/java/org/perfsonar/base2/servlets/AuthServlet.java
(from rev 5637,
trunk/perfsonar-java-base2/src/main/java/org/perfsonar/base2/servlets/AuthServlet.java)
===================================================================
---
branches/perfsonar-java-base2-stable-1.0.1/src/main/java/org/perfsonar/base2/servlets/AuthServlet.java
(rev 0)
+++
branches/perfsonar-java-base2-stable-1.0.1/src/main/java/org/perfsonar/base2/servlets/AuthServlet.java
2010-05-14 14:07:18 UTC (rev 5645)
@@ -0,0 +1,103 @@
+package org.perfsonar.base2.servlets;
+
+import java.io.IOException;
+
+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 {
+
+ private String username;
+ private String password;
+
+ public String getUsername() {
+ return username;
+ }
+
+ public String getPassword() {
+ return password;
+ }
+
+ /*
+ * 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");
+ String[] credentials = receiveCredentials(auth);
+ if (credentials == null) {
+ resp.setHeader("WWW-Authenticate", "BASIC
realm=\"users\"");
+ resp.sendError(HttpServletResponse.SC_UNAUTHORIZED);
+ } else {
+ username = credentials[0];
+ password = credentials[1];
+ processRequest(req, resp);
+ }
+ }
+
+ private String[] receiveCredentials(String authHeader) {
+ String[] loginAndPassword = null;
+
+ if (authHeader != null) {
+ java.util.StringTokenizer st = new
java.util.StringTokenizer(
+ authHeader);
+ if (st.hasMoreTokens()) {
+ String basic = st.nextToken();
+
+ if (basic.equalsIgnoreCase("Basic")) {
+ String credentials = st.nextToken();
+
+ sun.misc.BASE64Decoder decoder = new
sun.misc.BASE64Decoder();
+ String userPass;
+ try {
+ userPass = new
String(decoder.decodeBuffer(credentials));
+ int p = userPass.indexOf(":");
+ if (p != -1) {
+ loginAndPassword =
new String[2];
+ loginAndPassword[0] =
userPass.substring(0, p);
+ loginAndPassword[1] =
userPass.substring(p + 1);
+ }
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+
+ }
+ }
+ }
+ return loginAndPassword;
+ }
+
+}
Deleted:
branches/perfsonar-java-base2-stable-1.0.1/src/main/java/org/perfsonar/base2/servlets/ExistDBInitServlet.java
===================================================================
---
trunk/perfsonar-java-base2/src/main/java/org/perfsonar/base2/servlets/ExistDBInitServlet.java
2010-05-13 10:41:31 UTC (rev 5629)
+++
branches/perfsonar-java-base2-stable-1.0.1/src/main/java/org/perfsonar/base2/servlets/ExistDBInitServlet.java
2010-05-14 14:07:18 UTC (rev 5645)
@@ -1,87 +0,0 @@
-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;
- }
-
-}
Copied:
branches/perfsonar-java-base2-stable-1.0.1/src/main/java/org/perfsonar/base2/servlets/ExistDBInitServlet.java
(from rev 5637,
trunk/perfsonar-java-base2/src/main/java/org/perfsonar/base2/servlets/ExistDBInitServlet.java)
===================================================================
---
branches/perfsonar-java-base2-stable-1.0.1/src/main/java/org/perfsonar/base2/servlets/ExistDBInitServlet.java
(rev 0)
+++
branches/perfsonar-java-base2-stable-1.0.1/src/main/java/org/perfsonar/base2/servlets/ExistDBInitServlet.java
2010-05-14 14:07:18 UTC (rev 5645)
@@ -0,0 +1,86 @@
+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,getUsername(), getPassword());
+ 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] r5645 - in branches: . perfsonar-java-base2-stable-1.0.1/src/main/java/org/perfsonar/base2/servlets, svn-noreply, 05/14/2010
Archive powered by MHonArc 2.6.16.