Skip to content
Browse files

V-0.9.1-10/18/2012

  • Loading branch information...
1 parent 13ac618 commit a38136bf8f68d71d83e18fce08ea8c4fa9bcda32 @ngasiproj committed Oct 18, 2012
View
4 bin/deamon.sh
@@ -1,9 +1,5 @@
#!/bin/sh
-<<<<<<< HEAD
#cd $CAIMITO_HOME/bin
-=======
-cd $CAIMITO_HOME/bin
->>>>>>> 81b81b090d652d7b3c1de4359597c4836eb617da
export JAVA_OPTS="-Dsun.net.inetaddr.ttl=0 -Dnetworkaddress.cache.ttl=0"
View
13 bin/derby.log
@@ -1,17 +1,10 @@
----------------------------------------------------------------
-<<<<<<< HEAD
-Tue Sep 04 01:27:13 PDT 2012:
-Booting Derby version The Apache Software Foundation - Apache Derby - 10.8.2.2 - (1181258): instance a816c00e-0139-9063-f3d7-000002bafa60
+Tue Sep 04 07:22:39 PDT 2012:
+Booting Derby version The Apache Software Foundation - Apache Derby - 10.8.2.2 - (1181258): instance a816c00e-0139-91a9-5dc4-000002c125c8
on database directory /home/idrive/caimito/bin/caimito_db with class loader org.apache.catalina.loader.StandardClassLoader@1df5a8f
Loaded from file:/home/idrive/caimito/lib/derby.jar
-=======
-Mon Jun 18 07:38:38 EDT 2012:
-Booting Derby version The Apache Software Foundation - Apache Derby - 10.8.2.2 - (1181258): instance a816c00e-0137-ff63-2b87-000002f69fb8
-on database directory /usr/caimito/bin/caimito_db with class loader org.apache.catalina.loader.StandardClassLoader@2a4983
-Loaded from file:/usr/caimito/lib/derby.jar
->>>>>>> 81b81b090d652d7b3c1de4359597c4836eb617da
java.vendor=Sun Microsystems Inc.
java.runtime.version=1.6.0_24-b07
-user.dir=/usr/caimito/bin
+user.dir=/home/idrive/caimito/bin
derby.system.home=null
Database Class Loader started - derby.database.classpath=''
View
19 conf/server.xml
@@ -66,33 +66,20 @@
Java AJP Connector: /docs/config/ajp.html
APR (HTTP/AJP) Connector: /docs/apr.html
Define a non-SSL HTTP/1.1 Connector on port 8619
-<<<<<<< HEAD
--> <!--
<Connector port="8619" protocol="org.apache.coyote.http11.Http11NioProtocol"
connectionTimeout="20000"
redirectPort="8639" /> -->
<!-- A "Connector" using the shared thread pool
-=======
- -->
- <Connector port="8619" protocol="HTTP/1.1"
- connectionTimeout="20000"
- redirectPort="8639" />
- <!-- A "Connector" using the shared thread pool-->
- <!--
->>>>>>> 81b81b090d652d7b3c1de4359597c4836eb617da
<Connector executor="tomcatThreadPool"
port="8619" protocol="HTTP/1.1"
connectionTimeout="20000"
redirectPort="8639" />
-<<<<<<< HEAD
-->
<Connector port="8619" protocol="HTTP/1.1"
connectionTimeout="20000"
redirectPort="8639" />
-=======
- -->
->>>>>>> 81b81b090d652d7b3c1de4359597c4836eb617da
<!-- Define a SSL HTTP/1.1 Connector on port 8639
This connector uses the JSSE configuration, when using APR, the
connector should be using the OpenSSL style configuration
@@ -103,15 +90,9 @@
clientAuth="false" sslProtocol="TLS" />
-->
-<<<<<<< HEAD
<!-- Define an AJP 1.3 Connector on port 8659
<Connector port="8659" protocol="AJP/1.3" redirectPort="8639" />
-->
-=======
- <!-- Define an AJP 1.3 Connector on port 8659 -->
- <Connector port="8659" protocol="AJP/1.3" redirectPort="8639" />
-
->>>>>>> 81b81b090d652d7b3c1de4359597c4836eb617da
<!-- An Engine represents the entry point (within Catalina) that processes
every request. The Engine implementation for Tomcat stand alone
View
12 source/ngasi/caimito/CaimitoConfig.java
@@ -51,17 +51,13 @@
public static boolean cacheable = true;
public static String serverinfo = "Caimito";
public static String CAIMITO_CSS = null;
-<<<<<<< HEAD
- public static String version = "0.8";
- public static long requestTimeout = 30 * 60 * 1000;
+ public static String version = "0.9.1";
+ public static long requestTimeout = 130 * 60 * 1000L;
public static int single_cloud_account_with_single_storage = 1;
public static int cloud_accounts_for_administration_only = 2;
public static int cloud_setup=single_cloud_account_with_single_storage;
-=======
- public static String version = "0.4";
->>>>>>> 81b81b090d652d7b3c1de4359597c4836eb617da
public static void init()throws CaimitoException{
if (! new File(getConfigFile()).exists())
{
@@ -78,7 +74,9 @@ public static void init()throws CaimitoException{
shaftapp = getConfig().getString("shaft.app");
serverinfo = getConfig().getString("serverinfo");
CAIMITO_CSS = getConfig().getString("CAIMITO_CSS");
- requestTimeout = getConfig().getLong("request.timeout") * 60 * 1000;
+
+ if (getConfig().get("request.timeout") != null)
+ requestTimeout = getConfig().getLong("request.timeout") * 60 * 1000L;
if (getConfig().get("cachedir") != null)
cachedir = getConfig().getString("cachedir");
View
3,460 source/ngasi/caimito/CaimitoWebdavServlet.java
0 additions, 3,460 deletions not shown because the diff is too large. Please use a local Git client to view these changes.
View
794 source/ngasi/caimito/resource/OpenStackResourceObj.java
@@ -1,4 +1,3 @@
-<<<<<<< HEAD
/*
Copyright (c) 2011-2012, the Caimito project (http://caimito.ngasi.com/). All rights reserved.
Apache Software License 2.0
@@ -998,796 +997,3 @@ public long lastModified()throws Exception{
}*/
-=======
-/*
- Copyright (c) 2011-2012, the Caimito project (http://caimito.ngasi.com/). All rights reserved.
-Apache Software License 2.0
-Redistribution and use in source and binary forms, with or without
-modification, are permitted provided that the following conditions are met:
-
- 1. Redistributions of source code must retain the above copyright notice,
- this list of conditions and the following disclaimer.
-
- 2. Redistributions in binary form must reproduce the above copyright
- notice, this list of conditions and the following disclaimer in
- the documentation and/or other materials provided with the distribution.
-
- 3. The names of the authors may not be used to endorse or promote products
- derived from this software without specific prior written permission.
-
-THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
-INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
-FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL WebAppShowCase
-OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT,
-INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
-LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
-OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
-LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
-NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
-EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
-*/
-
-
-
-
-package ngasi.caimito.resource;
-import ngasi.caimito.*;
-
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileOutputStream;
-import java.io.InputStream;
-
-import tools.util.*;
-import java.util.Vector;
-import java.util.Hashtable;
-import com.google.gson.*;
-import java.lang.reflect.*;
-import com.google.gson.reflect.*;
-import java.util.List;
-import java.text.*;
-import java.util.Locale;
-import java.util.Date;
-import java.util.Enumeration;
-import java.util.Map;
-import java.io.ByteArrayInputStream;
-import java.util.Iterator;
-
-public class OpenStackResourceObj extends CloudResourceObj
- {
- protected static final int BUFFER_SIZE = 2048;
-
-
- static DateFormat dfm = null;
-
- static long maxautint = 0;
-
-
-
- static{
- try{
- maxautint = CaimitoConfig.getConfig().getLong("cloud.max_auth_interval") * 60* 1000L;
- }catch (Exception e){
- e.printStackTrace();
- }
- try{
-
- dfm = new SimpleDateFormat(CaimitoConfig.getConfig().getString("cloud.obj.details.dateformat"));
- }catch (Throwable e){
- e.printStackTrace();
- }
- }
-
-
- public void retrieveCloudFile(String path,String tf)throws CaimitoException{
- try{
- auth();
- Hashtable<String,String> h = new Hashtable<String,String>();
- h.put("X-Auth-Token",X_Auth_Token);
-
-
- HttpClientUtil.trustGetToFile(h,X_Storage_Url + "/" + CaimitoConfig.getConfig().getString("cloud.store") + CaimitoUtil.urlEncode(path),tf);
- }catch (Exception e){
- e.printStackTrace();
- CaimitoException.throwException(e);
-
- }
-
- }
-
-
- public void doWrite(InputStream dest)throws CaimitoException{
- try{
- if (dest.available() < 0)return;
-
-
- Hashtable<String,String> h = new Hashtable<String,String>();
- h.put("X-Auth-Token",X_Auth_Token);
- if (contentType != null)
- h.put("Content-Type",contentType);
-
- // if (contentLength > -1 )
- // h.put("Content-Length",String.valueOf(contentLength));
-
-
- String nv = null;
-
-
- nv = HttpClientUtil.trustPut(h,X_Storage_Url + "/" + CaimitoConfig.getConfig().getString("cloud.store") + CaimitoUtil.urlEncode(path),dest);
- //(path + " put me " + nv);
-
- }catch (Exception e){
- e.printStackTrace();
- CaimitoException.throwException(e);
-
- }
- }
-
-
-
-
-public void doCopy(ResourceObj dest)throws CaimitoException
- {
- String fs = path;
- String t = dest.path;
-// if (!isDirectory())
-// return;
- if ( !t.endsWith("/"))
- t = t + "/";
-
-// Vector<ResourceObj> flist = doList();
-
- //-----------
-
-
- auth();
-
- Hashtable<String,String> h = new Hashtable<String,String>();
- h.put("X-Auth-Token",X_Auth_Token);
- if (isDirectory())
- h.put("Content-Type","application/directory");
- //h.put("Content-Length","0");
-
- String tp = path;
- if (tp.endsWith("/"))
- tp = tp.substring(0,tp.length() -1);
- h.put("X_COPY_FROM",CaimitoConfig.getConfig().getString("cloud.store") + tp);
- String tp2 = dest.path;
- if (tp2.endsWith("/"))
- tp2 = tp2.substring(0,tp2.length() -1);
-try{
-
- String nv = HttpClientUtil.trustPut(h,X_Storage_Url + "/" + CaimitoConfig.getConfig().getString("cloud.store") + tp2);
- //(X_Storage_Url + "/" + CaimitoConfig.getConfig().getString("cloud.store") + tp + "-->" + h + " ******************X_COPY_FROM 1111 " + nv + ":" + tp2);
- }catch (Exception e){
- e.printStackTrace();
- CaimitoException.throwException(e);
-
- }
-
- if (!isDirectory())
- {
-
- return;
- }
- Vector<ResourceObj> flist = doList();
-
- if (flist == null || flist.size() < 1)
- return;
- for(int i = 0 ; i < flist.size() ; i++)
-{
- OpenStackResourceObj nf = (OpenStackResourceObj)flist.elementAt(i);
- String nt = t;
- boolean isd = false;
- if (nf.isDirectory())
- {
- nt = nt + nf.path.substring(path.length(),nf.path.length());
- OpenStackResourceObj dr = new OpenStackResourceObj();
- dr.path = nt;
- dr.doMkdir();
- isd = true;
- nf.doCopy(dr);
- }
- else
- try
- {
- ResourceObj dr = new OpenStackResourceObj();
- dr.path = t + nf.getName();
-
- nf.xCopy(dr);
- }catch (Exception e){
- e.printStackTrace();
- CaimitoException.throwException(e);
-
- }
-
-}
-
-
- }
-
- public void xCopy(ResourceObj dest)throws CaimitoException{
- try{
-
-
- auth();
-
- Hashtable<String,String> h = new Hashtable<String,String>();
- h.put("X-Auth-Token",X_Auth_Token);
- if (isDirectory())
- h.put("Content-Type","application/directory");
- //h.put("Content-Length","0");
-
- String tp = path;
- if (tp.endsWith("/"))
- tp = tp.substring(0,tp.length() -1);
- h.put("X_COPY_FROM",CaimitoConfig.getConfig().getString("cloud.store") + tp);
- String tp2 = dest.path;
- if (tp2.endsWith("/"))
- tp2 = tp2.substring(0,tp2.length() -1);
-
- String nv = HttpClientUtil.trustPut(h,X_Storage_Url + "/" + CaimitoConfig.getConfig().getString("cloud.store") + tp2);
- //(X_Storage_Url + "/" + CaimitoConfig.getConfig().getString("cloud.store") + tp + "-->" + h + " ******************X_COPY_FROM " + nv + ":" + tp2);
-
-
-
- }catch (Exception e){
- e.printStackTrace();
- CaimitoException.throwException(e);
-
- }
- }
-
-
- public void doMove(ResourceObj dest)throws CaimitoException{
- try{
-
- doCopy(dest);
- doDelete();
-
- }catch (Exception e){
- e.printStackTrace();
- CaimitoException.throwException(e);
-
- }
- }
-
- public boolean doExists()throws CaimitoException{
- if (path.equals("") || path.equals("/"))
- return true;
-
- //("OEXISTST " + path);
- init();
- return ex;
- //return new File(root + path).exists();
- }
- public void deleteCloudFile()throws CaimitoException{
-
-
-try{
-
- auth();
-
-
-
- if (isDirectory())
- {
-
- Vector<ResourceObj> flist = doList();
-
- if (flist != null && flist.size() > 0)
- for(int i = 0 ; i < flist.size() ; i++)
-{
- OpenStackResourceObj nf = (OpenStackResourceObj)flist.elementAt(i);
- nf.doDelete();
- /*String nt = t;
- boolean isd = false;
- if (nf.isDirectory())
- {
- nt = nt + nf.path.substring(path.length(),nf.path.length());
- OpenStackResourceObj dr = new OpenStackResourceObj();
- dr.path = nt;
- dr.doMkdir();
- isd = true;
- nf.doCopy(dr);
- }
- else
- try
- {
- ResourceObj dr = new OpenStackResourceObj();
- dr.path = t + nf.getName();
-
- nf.xCopy(dr);
- }catch (Exception e){
- e.printStackTrace();
- CaimitoException.throwException(e);
-
- }*/
-
-}
- }
-
-
-
-
- Hashtable<String,String> h = new Hashtable<String,String>();
- h.put("X-Auth-Token",X_Auth_Token);
- //( "DEO DELOET " + X_Storage_Url + "/" + CaimitoConfig.getConfig().getString("cloud.store") + CaimitoUtil.urlEncode(path) + "?format=json");
-
- String nv = null;
- String p2 = path;
- if (p2.endsWith("/"))
- p2 = p2.substring(0,p2.length() -1);
-
- nv = HttpClientUtil.trustDelete(h,X_Storage_Url + "/" + CaimitoConfig.getConfig().getString("cloud.store") + CaimitoUtil.urlEncode(p2) );
-
-
- //("DELETE OF he2 " + nv);
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- }catch (Exception e){
- e.printStackTrace();
- CaimitoException.throwException(e);
- }
- }
-
- protected void init(){
- if (init)return;
-try{
- init = true;
- if (path.equals("") || path.equals("/"))
- return ;
-
- auth();
-
- Hashtable<String,String> h = new Hashtable<String,String>();
- h.put("X-Auth-Token",X_Auth_Token);
-
-
- String p2 = path;
- if (p2.endsWith("/"))
- p2 = p2.substring(0,p2.length() -1);
- int nv = HttpClientUtil.trustHead(h,X_Storage_Url + "/" + CaimitoConfig.getConfig().getString("cloud.store") + CaimitoUtil.urlEncode(p2) + "?format=json");
- if (nv == 404)return;
-
-
- NameValuePairs nvp = new NameValuePairs(h);
-
-
- cl = nvp.getLong("Content-Length");
- lm = dfm.parse(nvp.getString("Last-Modified")).getTime();
- if (nvp.getString("Content-Type").equals("application/directory"))
- isd = true;
-
- //init = true;
- ex = true;
-}catch (Throwable e){
- e.printStackTrace();
-
- if (CaimitoConfig.cacheable){
- String tf = CaimitoConfig.cachedir + path;
- File ftf = new File(tf);
-
- if (ftf.exists())
- {
- cl = ftf.length();
- lm = ftf.lastModified();
- if (ftf.isDirectory())
- isd = true;
- }
- }
-
-
-
-}
-
-
- }
-
- protected boolean ex = false;
- protected boolean init = false;
- protected boolean isd = false;
- protected long lm = 0;
- protected long cl = 0;
- //protected OSRAttribute attributes = null;
-
- public void doMkdir()throws CaimitoException{
- try{
-
- //new File(root + path).mkdirs();
-
-
-
- auth();
-
- Hashtable<String,String> h = new Hashtable<String,String>();
- h.put("X-Auth-Token",X_Auth_Token);
- h.put("Content-Type","application/directory");
- String tp = path;
- if (tp.endsWith("/"))
- //tp = tp + "/";
- tp = tp.substring(0,tp.length() -1);
- String nv = HttpClientUtil.trustPut(h,X_Storage_Url + "/" + CaimitoConfig.getConfig().getString("cloud.store") + tp);
- //(X_Storage_Url + "/" + CaimitoConfig.getConfig().getString("cloud.store") + tp + "-->" + h + " THEY AUTHOiniyt " + nv);
-
-
- }catch (Exception e){
- e.printStackTrace();
- CaimitoException.throwException(e);
- }
- }
-
- public long getLastModified()throws CaimitoException{
- //return new File(root + path).lastModified();
- init();
- return lm;
- }
-
- public boolean isDirectory()throws CaimitoException{
- if (path.equals("") || path.equals("/"))
- return true;
- init();
- return isd;
- }
- public long getContentLength()throws CaimitoException{
- init();
- return cl;
- }
-
- protected static String X_Auth_Token = null; //"5bba5c21-3c8c-4f6b-8b17-9adb7c2ad4ea";
- protected static String X_Storage_Url = null; //"http://swift.rc.nectar.org.au:8888/v1/AUTH_793";
- protected static long authtime = 0;
- void auth()throws CaimitoException{
- try{
-
- if (X_Auth_Token != null && X_Storage_Url != null && !((System.currentTimeMillis() - authtime) > maxautint))return;
- X_Auth_Token = null;
- X_Storage_Url = null;
- Hashtable<String,String> h = new Hashtable<String,String>();
- //String curl = null;
- String nv = null;
- String curl = CaimitoConfig.getConfig().getString("cloud.url");
- if (curl.endsWith("/"))
- curl = curl.substring(0,curl.length() - 1);
-
- if (CaimitoConfig.getConfig().get("cloud.api.version") == null || CaimitoConfig.getConfig().getString("cloud.api.version").startsWith("1."))
- try{
- h.put("X-Auth-User",CaimitoConfig.getConfig().getString("cloud.username"));
- h.put("X-Auth-Key",CaimitoConfig.getConfig().getString("cloud.api.key_password"));
- //curl = CaimitoConfig.getConfig().getString("cloud.url");
- //if (curl.endsWith("/"))
- // curl = curl.substring(0,curl.length() - 1);
- nv = HttpClientUtil.trustGet(h,curl);
-
- X_Storage_Url = h.get("X-Storage-Url");
- X_Auth_Token = h.get("X-Auth-Token");
- }catch (Exception e){
- System.out.println(" Failed V1 Auth " + e.toString());
- if (CaimitoConfig.getConfig().getString("cloud.api.version").startsWith("1."))
- {
- if (e instanceof CaimitoException)
- throw (CaimitoException)e;
- else
- CaimitoException.throwException(e);
-
- }
- }
-
-
- if (X_Storage_Url == null || X_Auth_Token == null){
-
- if (!curl.endsWith("/tokens"))
- curl = curl + "/tokens";
- Hashtable<String,String> pc = new Hashtable<String,String>();
- pc.put("username",CaimitoConfig.getConfig().getString("cloud.username"));
- pc.put("password",CaimitoConfig.getConfig().getString("cloud.api.key_password"));
-
- Hashtable<String,Hashtable<String,String>> auh = new Hashtable<String,Hashtable<String,String>>();
- auh.put("passwordCredentials",pc);
-
- Hashtable tl = new Hashtable();
- tl.put("auth",auh);
-
- h = new Hashtable<String,String>();
- h.put("Content-type","application/json");
-
- Gson gson = new Gson();
- String json = gson.toJson(tl);
- ByteArrayInputStream dest = new ByteArrayInputStream(json.getBytes());
-
- nv = HttpClientUtil.trustPost(h,curl,dest);
- //Gson gson = new Gson();
- OSV2TokenResponse oa = gson.fromJson(nv, new TypeToken<OSV2TokenResponse>() {}.getType());
- Map<String,String> eps = oa.getResponse();
- if (CaimitoConfig.getConfig().getString("cloud.endpoint.access").equals("internal"))
- X_Storage_Url = eps.get("internalURL");
- else
- X_Storage_Url = eps.get("publicURL");
- X_Auth_Token = oa.access.token.id;
- if (X_Storage_Url == null || X_Auth_Token == null)
- CaimitoException.throwException("unable_to_auth");
-
-
- }
- authtime = System.currentTimeMillis();
- }catch (Throwable e){
- e.printStackTrace();
- CaimitoException.throwException(e);
- }
- }
-
- public Vector<ResourceObj> doList()throws CaimitoException{
- //doDelete();
- Vector<ResourceObj> l = new Vector<ResourceObj>();
-
- try{
-
- auth();
-
- Hashtable<String,String> h = new Hashtable<String,String>();
- h.put("X-Auth-Token",X_Auth_Token);
- String p2 = path;
- if (p2.endsWith("/"))
- p2 = p2.substring(0,p2.length() -1);
- //p2 = p2 + "/";
- // ?prefix=photos/&delimiter=/
- boolean isroot = (p2.equals("/") || p2.equals(""));
- String pars = "?delimiter=/";
- if (!isroot){
- String p2b = p2;
- if (p2b.startsWith("/"))
- p2b = p2b.substring(1,p2b.length());
- pars = pars + "&prefix=" + CaimitoUtil.urlEncode(p2b) + "/";
- }
- //pars = "";
- //("***doList1 " + X_Storage_Url + "/" + CaimitoConfig.getConfig().getString("cloud.store") + CaimitoUtil.urlEncode(p2) + pars + " --> " + h + " h <-->nv ");
-//+ CaimitoUtil.urlEncode(p2)
- String nv = HttpClientUtil.trustGet(h,X_Storage_Url + "/" + CaimitoConfig.getConfig().getString("cloud.store") + pars);
-
- if (nv == null || nv.length() < 1)return l;
- ByteArrayInputStream bin = new ByteArrayInputStream(nv.getBytes());
- EZArrayList lblv = new EZArrayList(bin);
- bin.close();
- String oa = null;
- OpenStackResourceObj ro = null;
- String dn = "";
- String ps = "";
-
- if (!path.endsWith("/"))
- ps = "/";
- for (int ct = 0;ct < lblv.size();ct++)
- {
- dn = lblv.elementAt(ct).toString();
- /*//("****************************DN= " + dn);
- ro = new OpenStackResourceObj();
-
- ro.path = "/" + dn;
- ro.user = user;
- ro.listing = listing;
- ro.ex = true;
- try{
-
- ro.doDelete();
- }catch (Exception e){
- e.printStackTrace();
- }*/
- if (dn.equals(".")){
- //("****************************DN= " + dn);
-
- continue;
- }
- if (dn.endsWith("/"))
- {
- //("****************************DN= " + dn);
-
- continue;
-
- }
- //(path + " OS LIST " + dn);
- ro = new OpenStackResourceObj();
-
- ro.path = "/" + dn;
- ro.user = user;
- ro.listing = listing;
- ro.ex = true;
-
-
- l.add(ro);
-
-
- }
-
-
-
- /* Gson gson = new Gson();
-
- List<OSRAttribute> attrs = gson.fromJson(nv, new TypeToken<List<OSRAttribute>>() {}.getType());
-
- Vector<OSRAttribute> lblv = new Vector<OSRAttribute>(attrs);
- OSRAttribute oa = null;
- OpenStackResourceObj ro = null;
- String ps = "";
- if (!path.endsWith("/"))
- ps = "/";
- String dn = null;
- for (int ct = 0;ct < lblv.size();ct++)
- {
- oa = lblv.elementAt(ct);
- //(path + " OS LIST " + oa);
- ro = new OpenStackResourceObj();
- dn = oa.name;
- if (dn.endsWith("/"))
- {
- dn = dn.substring(0,dn.length() -1);
- ro.isd = true;
-
- }
- ro.path = path + ps + dn;
- ro.user = user;
- ro.listing = listing;
- ro.cl = oa.bytes;
- ro.init = true;
- ro.ex = true;
- ro.lm = oa.lastModified();
- l.add(ro);
-
-
- }*/
-/*
- String[] dl = new File(root + path).list();
- String ps = "";
- if (!path.endsWith("/"))
- ps = "/";
- if (dl != null){
- FileResourceObj ro = null;
- for (int ct = 0; ct < dl.length;ct++){
- ro = new FileResourceObj();
- ro.path = path + ps + dl[ct];
- ro.user = user;
- ro.listing = listing;
- l.add(ro);
- }
- }*/
-
- }catch (Throwable e){
- e.printStackTrace();
- CaimitoException.throwException(e);
- }
- return l;
-
- }
-
-
-}
-
-class OSRAttribute{
-
- static DateFormat dfm = null;
- static boolean rmdend = false;
- static{
- try{
- //("DATE FORMAT " + CaimitoConfig.getConfig().getString("cloud.dateformat"));
- if (CaimitoConfig.getConfig().getBoolean("cloud.date.remove.end"))
- {
- rmdend = true;
- }
- dfm = new SimpleDateFormat(CaimitoConfig.getConfig().getString("cloud.dateformat"));
- }catch (Throwable e){
- e.printStackTrace();
- }
- }
-
-
- String name = null;
- String hash = null;
- long bytes = 0;
- String content_type = null;
- String last_modified = null;
- public long lastModified()throws Exception{
- if (rmdend)
- {
- String lm = last_modified;
- int i = lm.lastIndexOf(".");
- if (i > 0){
- lm = lm.substring(0,i);
- return dfm.parse(lm).getTime();
-
- }
- }
- return dfm.parse(last_modified).getTime();
- }
-
-}
-class OSV2TokenResponse {
- public TokenObj access = null;
-
- //public Hashtable<String,Hashtable<String,String>> access = null;
- public Map<String,String> getResponse(){
- Hashtable<String,String> res = new Hashtable<String,String>();
- Iterator<EndPoints> en = access.serviceCatalog.iterator();
- //String n = null;
- EndPoints v = null;
- while(en.hasNext()){
- v = en.next();
- if (v.type.equals("object-store") && v.name.equals("swift")){
- Iterator<Map<String,String>> enp = v.endpoints.iterator();
-
- if(enp.hasNext())
- return enp.next();
- }
- }
- return res;
- }
-
-}
- class TokenObj{
- public TokenObj2 token = null;
- public List<EndPoints> serviceCatalog = null;
-
- }
- class EndPoints{
- public List<Map<String,String>> endpoints = null;
- public String type = null;
- public String name = null;
-
- }
- class TokenObj2{
- public String id = null;
- }
-/*class OSRObjDetails{
-
- static DateFormat dfm = null;
- static boolean rmdend = false;
- static{
- try{
- //("DATE FORMAT " + CaimitoConfig.getConfig().getString("cloud.dateformat"));
- if (CaimitoConfig.getConfig().getBoolean("cloud.date.remove.end"))
- {
- rmdend = true;
- }
- dfm = new SimpleDateFormat(CaimitoConfig.getConfig().getString("cloud.dateformat"));
- }catch (Throwable e){
- e.printStackTrace();
- }
- }
-
-
-
-Last-Modified=Tue, 24 Apr 2012 00:05:15 GMT, Accept-Ranges=bytes, Content-Length=0, X-Trans-Id=txd7c65f16aa884af9a09266da2636daf5, Date=Tue, 24 Apr 2012 03:15:30 GMT, X-Auth-Token=AUTH_tke0c45f67d4fb47189ad41fc771b4b53f, Content-Type=application/x-www-form-urlencoded; charset=ISO-8859-1, Connection=keep-alive, Etag=d41d8cd98f00b204e9800998ecf8427e
-
-
-
- public long lastModified()throws Exception{
- if (rmdend)
- {
- String lm = last_modified;
- int i = lm.lastIndexOf(".");
- if (i > 0){
- lm = lm.substring(0,i);
- return dfm.parse(lm).getTime();
-
- }
- }
- return dfm.parse(last_modified).getTime();
- }
-
-}*/
-
->>>>>>> 81b81b090d652d7b3c1de4359597c4836eb617da
View
789 source/ngasi/caimito/resource/ResourceStore.java
@@ -1,4 +1,3 @@
-<<<<<<< HEAD
/*
Copyright (c) 2011-2012, the Caimito project (http://caimito.ngasi.com/). All rights reserved.
Apache Software License 2.0
@@ -790,791 +789,3 @@ public static void sendBasicError( HttpServletRequest request,HttpServletRespon
class CaimitoBooleanHolder{
public boolean value = false;
}
-=======
-/*
- Copyright (c) 2011-2012, the Caimito project (http://caimito.ngasi.com/). All rights reserved.
-Apache Software License 2.0
-Redistribution and use in source and binary forms, with or without
-modification, are permitted provided that the following conditions are met:
-
- 1. Redistributions of source code must retain the above copyright notice,
- this list of conditions and the following disclaimer.
-
- 2. Redistributions in binary form must reproduce the above copyright
- notice, this list of conditions and the following disclaimer in
- the documentation and/or other materials provided with the distribution.
-
- 3. The names of the authors may not be used to endorse or promote products
- derived from this software without specific prior written permission.
-
-THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
-INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
-FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL WebAppShowCase
-OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT,
-INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
-LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
-OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
-LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
-NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
-EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
-*/
-
-
-
-
-package ngasi.caimito.resource;
-import java.nio.charset.Charset;
-
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
-import ngasi.caimito.*;
-import org.shaft.server.auth.*;
-import tools.util.*;
-import java.security.MessageDigest;
-import java.security.NoSuchAlgorithmException;
-import java.util.Enumeration;
-import java.io.BufferedInputStream;
-import java.io.UnsupportedEncodingException;
-import org.shaft.server.utils.*;
-import tools.util.*;
-import java.sql.Connection;
-import java.sql.ResultSet;
-
-
-public class ResourceStore
- {
- public static int READ = 1;
- public static int WRITE = 2;
- protected static MessageDigest md5Helper = null;
-
- static{
-
- try {
- md5Helper = MessageDigest.getInstance("MD5");
- } catch (NoSuchAlgorithmException e) {
- e.printStackTrace();
- }
- }
-
- public static ResourceObj lookup(String path, HttpServletRequest request)
- throws CaimitoException {
- //("GET Z PAth " + path);
- String u = (String)request.getAttribute(CaimitoConfig.caimitouserreqobj);
- if (u == null)
- u = login(request);
- return lookup(path,u);
- }
-
- //public static ResourceObj lookup(String path, HttpServletRequest request,
- // HttpServletResponse response)
- //throws CaimitoException {
- //
- //}
- protected static Connection getConnection()throws Exception{
- return DBConMgr.getConnection(ShaftRestConfig.datasourceName);
- }
- public static boolean isPublicPath(String path,CaimitoBooleanHolder l,String u)
- throws CaimitoException {
- try{
- //("PUBLIC PATHS " + path);
- if (path.startsWith("/" + CaimitoConfig.shaftapp + "/") || path.equals("/favicon.ico"))
- return true;
- if (path.startsWith("/"))
- path = path.substring(1,path.length());
- if (path.endsWith("/"))
- path = path.substring(0,path.length() -1);
-
- return pathMatch(path,"publicpaths",l,u);
- }catch (Exception e){
- //e.printStackTrace();
- //(path + " isPublicPath.error " + e.toString());
- }
- return false;
- }
-
-
- public static boolean pathMatch(String path,String table,CaimitoBooleanHolder l,String u)throws Exception
- {
-
- if (doPathMatch(path,table,l,u))
- return true;
-
- int i = path.lastIndexOf("/");
- while (i > 0)
- {
- path = path.substring(0,i);
- if (doPathMatch(path,table,l,u))
- return true;
- i = path.lastIndexOf("/");
- }
- if (i < 0)
- return doPathMatch(path,table,l,u);
-
- return false;
- }
-
- protected static boolean doPathMatch(String path,String table,CaimitoBooleanHolder l,String u)throws Exception
- {
- SPQueryAndUpdate spq = new SPQueryAndUpdate(getConnection());
- try{
- String sql = "SELECT path,shaftowner,listing from " + CaimitoConfig.shaftapp + "_" + table + " where path = ?";
- spq.setTemplate(sql);
- spq.addVariable(path);
- ResultSet res = spq.query();
- //(path + " doPathMatch 1 " + table);
-
- if (res.next()){
- String su = res.getString(2);
- NameValuePairs nvp = getUserPriv(su);
- //(path + ":" + res.getString(2) + " doPathMatch 2 " + nvp);
- if (nvp == null || nvp.size() < 1)
- return false;
- if (!path.startsWith(nvp.getString("path") + "/") && !(path + "/").startsWith(nvp.getString("path") + "/"))
- return false;
- if (u == null || (!su.equals(u) && !UserMgr.getUserMgr(CaimitoConfig.shaftapp).isAdminOrOwnerOf(CaimitoConfig.shaftapp,u,su)))
- l.value = (res.getBoolean(3));
- else
- l.value = CaimitoConfig.getConfig().getBoolean("resource.dir.listing");
- return true;
- }
- }
-
- finally{
- if (spq != null)spq.close();
- }
- return false;
- }
-
-
-
- protected static NameValuePairs getUserPrivFromDB(String u)throws Exception
- {
- try{
-
- SPQueryAndUpdate spq = new SPQueryAndUpdate(getConnection());
- try{
- String sql = "SELECT * from " + CaimitoConfig.shaftapp + "_pathprivileges where resourceuser = ? AND shaftowner = ?";
-
- // username = UserMgr. (CaimitoConfig.shaftapp).getOwner(CaimitoConfig.shaftapp,username);
- // if (username == null)
- // break;
- boolean isadmin = false;
- if (RealmMgr.getRealmMgr(CaimitoConfig.shaftapp).isAdmin(CaimitoConfig.shaftapp,u)){
-sql = "SELECT * from " + CaimitoConfig.shaftapp + "_pathprivileges where resourceuser = ?";
-
- isadmin = true;
- }
-
- spq.setTemplate(sql);
- spq.addVariable(u);
- if (!isadmin)
- spq.addVariable(UserMgr.getUserMgr(CaimitoConfig.shaftapp).getOwner(CaimitoConfig.shaftapp,u));
-
- return spq.getHash();
- }
-
- finally{
- if (spq != null)spq.close();
- }
- }catch (Exception e){
- //(u + " getUserPrivFromDB " + e.toString() + ":" );
- e.printStackTrace();
-
- }
- return null;
- }
-
- protected static NameValuePairs getUserPriv(String u)throws Exception
- {
- try{
-
-
-
- NameValuePairs nvp = getUserPrivFromDB(u);
- if (nvp == null || nvp.size() < 1)
- return nvp;
- String path2 = null;
- String username = u;
- while (true){
- username = UserMgr.getUserMgr(CaimitoConfig.shaftapp).getOwner(CaimitoConfig.shaftapp,username);
- if (username == null)
- break;
- if (RealmMgr.getRealmMgr(CaimitoConfig.shaftapp).isAdmin(CaimitoConfig.shaftapp,username))
- break;
- if (path2 == null)path2 = "";
- path2 = getUserPrivFromDB(username).getString("path") + "/" + path2;
- }
- if (path2 != null){
- path2 = path2 + "/" + nvp.getString("path");
- //("ZEPATH@ A " + path2);
-
- path2 = CaimitoUtil.normalize(path2);
- //("ZEPATH@ " + path2);
-
- nvp.put("path",path2);
-
-
- }
- return nvp;
-
-
-
- }catch (Exception e){
- //(u + " getUserPriv.error " + e.toString() + ":" );
- e.printStackTrace();
-
- }
- return null;
- }
-
-
- public static ResourceObj lookup(String path, HttpServletRequest request,
- HttpServletResponse response,int action)
- throws CaimitoException {
- String u = null;
- //("GET Z PAth 2 " + path);
- if (path.equals("/") || path.equals(""))
- {
- if (CaimitoConfig.protectedRoot)
- {
-
- u = login(request,response);
- if (u == null)return null;
- }
- }
-
- if (u == null)
- {
- u = (String)request.getAttribute(CaimitoConfig.caimitouserreqobj);
- if (u == null)
- u = login(request);
- }
-try{
- //(action + ":" + path + " THE USER IS " + u);
- if (RealmMgr.getRealmMgr(CaimitoConfig.shaftapp).isAdmin(CaimitoConfig.shaftapp,u))
- return lookup(path,u);
-
-
- if (action == READ){
-
- CaimitoBooleanHolder l = new CaimitoBooleanHolder();
- if (isPublicPath(path,l,u)){
-
- ResourceObj ro = lookup(path,u);
- if (ro != null)
- ro.listing = l.value;
- return ro;
- }
- }
- if (u == null){
-
- u = login(request,response);
- if (u == null)return null;
- }
-
-
-
- NameValuePairs nvp = getUserPriv(u);
- //(u + " PRIVILEGE GO " + nvp);
- if (nvp == null || nvp.size() < 1)
- {
- response.sendError(HttpServletResponse.SC_FORBIDDEN);
- return null;
- }
-
-
- if (action == WRITE && (nvp.getInt("privilege") != WRITE ||(path.startsWith("/" + CaimitoConfig.shaftapp + "/") || path.equals("/favicon.ico"))))
- {
- //(u + " PRIVILEGE GO 2 " + nvp);
-
- response.sendError(HttpServletResponse.SC_FORBIDDEN);
- return null;
- }
- if (!path.startsWith("/" + nvp.getString("path") + "/") && !(path + "/").startsWith("/" + nvp.getString("path") + "/"))
- {
- //(path + " PRIVILEGE GO 3 " + nvp);
-
- response.sendError(HttpServletResponse.SC_FORBIDDEN);
- return null;
- }else lookup("/" + nvp.getString("path") + "/",u) .mkdir();
- return lookup(path,u);
-
- }catch (Exception e){
-
- e.printStackTrace();
- return null;
- }
- /*//(u + " WOWWW SD 1 " + CaimitoConfig.resource + ":" + path);
- if (CaimitoConfig.resource.equals("file")){
- ro = new FileResourceObj();
- }
- //(u + " WOWWW SD 2 " + ro);
-
- if (ro != null){
- ro.user = u;
- ro.path = path;
- }
- return ro;*/
-// return null;
- }
-
-
- public static ResourceObj lookup(String path,String u)
- throws CaimitoException {
- ResourceObj ro = null;
- //if (u == null)
- // Thread.dumpStack();
- //(u + " ***************WOWWW SD 1 " + CaimitoConfig.resource + ":" + path);
- if (path.startsWith("/" + CaimitoConfig.shaftapp + "/"))// || path.equals("/favicon.ico"))
- {
- //if (path.equals("/favicon.ico"))
- //path = "/" + CaimitoConfig.shaftapp + "/public/favicon.ico" ;
- if (!path.startsWith("/" + CaimitoConfig.shaftapp + "/public/"))
- path = "/" + CaimitoConfig.shaftapp + "/public/" + path.substring(CaimitoConfig.shaftapp.length() + 1,path.length());
- //(" FAV NEW PATH " + path);
- ro = new ShaftResourceObj();
-
- }
- else if (CaimitoConfig.resource.equals("file")){
- ro = new FileResourceObj();
- }
- else if (CaimitoConfig.resource.equals("openstack")){
- //(u + " WOWWW SD 2 " + CaimitoConfig.resource + ":" + path);
-
- ro = new OpenStackResourceObj();
- }
- //(u + " WOWWW SD 2 " + ro);
-
- if (ro != null){
- ro.user = u;
- ro.path = path;
- ro.listing = CaimitoConfig.getConfig().getBoolean("resource.dir.listing");
- }
-
- if (path.equals("/favicon.ico") && !ro.exists()){
- path = "/" + CaimitoConfig.shaftapp + "/public/favicon.ico" ;
- ro = new ShaftResourceObj();
- ro.user = u;
- ro.path = path;
- }
-
-
- return ro;
- }
-
-
- public static String login( HttpServletRequest request )
- throws CaimitoException {
- return login(request,null);
- }
-
-
-
-
- protected static String getDigest(String username, String realmName)throws CaimitoException {
-
-try{
-
- return UserMgr.getUserMgr(CaimitoConfig.shaftapp).getMD5Digest(CaimitoConfig.shaftapp,username);
- /*String digestValue = username + ":" + realmName + ":"
- + UserMgr. (CaimitoConfig.shaftapp).getPasswd(CaimitoConfig.shaftapp,username);
-
- byte[] valueBytes = null;
- valueBytes = digestValue.getBytes(Charset.defaultCharset());
-
- byte[] digest = null;
- synchronized(md5Helper) {
- digest = md5Helper.digest(valueBytes);
- }
-
- return md5Encode(digest);*/
-}catch (Exception e){
- e.printStackTrace();
- CaimitoException.throwException(e);
-}
-return null;
- }
-
-
-
- protected static String authenticate(NameValuePairs nvp) throws CaimitoException{
- // username="caimitoadmin", realm="Caimito", nonce="", uri="/", response="2fb52dbbcb7b25fd33840eac3027e9c5"
-
-String username = (String)nvp.get("username");
- String clientDigest = (String)nvp.get("response");
- String nonce = (String)nvp.get("nonce");
- String nc = (String)nvp.get("nc");
-String cnonce = (String)nvp.get("cnonce");
-String qop = (String)nvp.get("qop");
-String realm = (String)nvp.get("realm");
- String a2 = nvp.get("method") + ":" + nvp.get("uri");
-
- byte[] buffer;
- synchronized (md5Helper) {
- buffer = md5Helper.digest(a2.getBytes(Charset.defaultCharset()));
- }
- String md5a2 = md5Encode(buffer);
-
-
- String md5a1 = getDigest(username, realm);
- if (md5a1 == null)
- return null;
- String serverDigestValue;
- if (qop == null) {
- serverDigestValue = md5a1 + ":" + nonce + ":" + md5a2;
- } else {
- serverDigestValue = md5a1 + ":" + nonce + ":" + nc + ":" +
- cnonce + ":" + qop + ":" + md5a2;
- }
-
- byte[] valueBytes = null;
- // try {
- valueBytes = serverDigestValue.getBytes(Charset.defaultCharset());
- // } catch (UnsupportedEncodingException uee) {
- // log.error("Illegal digestEncoding: " + getDigestEncoding(), uee);
- // throw new IllegalArgumentException(uee.getMessage());
- //}
-
- String serverDigest = null;
- // Bugzilla 32137
- synchronized(md5Helper) {
- serverDigest = md5Encode(md5Helper.digest(valueBytes));
- }
-
- /*if (log.isDebugEnabled()) {
- log.debug("Digest : " + clientDigest + " Username:" + username
- + " ClientSigest:" + clientDigest + " nonce:" + nonce
- + " nc:" + nc + " cnonce:" + cnonce + " qop:" + qop
- + " realm:" + realm + "md5a2:" + md5a2
- + " Server digest:" + serverDigest);
- }*/
-
- if (serverDigest.equals(clientDigest)) {
- return (username);
- }
-
- return null;
- }
-
-
-
- public static String login( HttpServletRequest request,
- HttpServletResponse response
- )
- throws CaimitoException {
- String ua = request.getHeader("user-agent");
-
- /*java.util.Enumeration hs = request.getHeaderNames();
- while (hs.hasMoreElements())
- {
- String hn = (String)hs.nextElement();
- String hv = request.getHeader(hn);
- System.out.println(hn + " USER HEADER " + hv);
-
- }
-
-
- java.util.Enumeration hds = request.getParameterNames();
- while (hds.hasMoreElements())
- {
- String hd = (String)hds.nextElement();
- String hdv = request.getParameter(hd);
- //(hd + " PAR " + hdv);
- System.out.println(hd + " USER params " + hdv);
- }
-
- String ct = request.getContentType();
- if (ct != null && ct.equals("application/xml"))
- {
- int cl = request.getContentLength();
- if (cl > 0){
- byte[] transferBuffer = new byte[cl];
- try{
- BufferedInputStream requestBufInStream = new BufferedInputStream(request.getInputStream(), cl);
- requestBufInStream.read(transferBuffer);
- System.out.println(" XML VAL " + new String(transferBuffer));
- }catch (Exception e){
- e.printStackTrace();
- }
- }
- }
-
- //if (ua.equals("Microsoft Data Access Internet Publishing Provider DAV") || ua.indexOf("davfs2") > -1 || CaimitoConfig.getConfig().getString(ua + ".auth").equals("basic"))
- // return basicLogin(request,response);
- System.out.println("USER AGAENT " + ua);*/
- if (CaimitoConfig.getConfig().getString(ua + ".auth").equals("digest"))
- return digestLogin(request,response);
- return basicLogin(request,response);
- }
-
-
- public static String digestLogin( HttpServletRequest request,
- HttpServletResponse response
- )
- throws CaimitoException {
- //("DIGEST LOGIN 1");
- NameValuePairs nvp = new NameValuePairs();
- String hr = request.getHeader("Authorization");
- if (hr != null)
- {
- if (hr.startsWith("Digest "))
- {
-try{
- //hr = SharedMethods.replaceSubstring(hr,"Digest ","");
- hr = hr.trim();
- hr = hr.substring(7,hr.length());
- // username="caimitoadmin", realm="Caimito", nonce="", uri="/", response="2fb52dbbcb7b25fd33840eac3027e9c5"
- NameValuePairs nvp1 = NameValuePairs.toNameValuePair(hr,"=",",");
- Enumeration nvp1e = nvp1.keys();
- String k = null;
- String v = null;
- while(nvp1e.hasMoreElements())
- {
- k = (String)nvp1e.nextElement();
- v = nvp1.getString(k);
- nvp.put(k.trim(),StringUtil.getTrimmedValue(v.trim()));
- }
- nvp.put("method",request.getMethod());
- //(nvp + " DIGEST 1 " + hr);
- //byte[] b = Base64Decoder.fromBase64(hr.getBytes());
- //String auth = new String(b);
- //String name = auth.substring(0,auth.indexOf(":"));
- //String pass = auth.substring(auth.indexOf(":") + 1,auth.length());
-
-
- String name = authenticate(nvp);
- //if (UserMgr. (CaimitoConfig.shaftapp).login(CaimitoConfig.shaftapp,name,pass) != null)
- if (name != null)
- {
- //request.setPrincipal(RealmEngine.get().getPrincipal(name));
- //request.setAuthType("BASIC");
- // request.getSession()
- request.setAttribute(CaimitoConfig.caimitouserreqobj,name);
- return name;
- }
- }catch (Exception e){
- e.printStackTrace();
- //return null;
- }
- }
- }
- if (response != null)
- sendError(request,response,nvp.getString("nonce").trim());
- return null;
-
- }
-
-
-
- protected static boolean isNonceStale(String nonce){
-
-
- int i = nonce.indexOf(":");
- if (i < 0 || (i + 1) == nonce.length()) {
- return true;
- }
- long nonceTime;
- try {
- nonceTime = Long.parseLong(nonce.substring(0, i));
- } catch (NumberFormatException nfe) {
- return true;
- }
- //String md5clientIpTimeKey = nonce.substring(i + 1);
- long currentTime = System.currentTimeMillis();
- //(currentTime + ":" + nonceTime + ":" + CaimitoConfig.nonceValidity + ":IS NONE STALE ##########################");
- if ((currentTime - nonceTime) > CaimitoConfig.nonceValidity) {
- return true;
- }
- else return false;
-// return true;
-
- }
-
-
- public static void sendError( HttpServletRequest request,HttpServletResponse response,String nonce1)
- {
- try
- {
- String nonce = generateNonce(request);
- boolean isn = isNonceStale(nonce1);
- //(nonce1 + " IS NOT STALE " + isn);
- setAuthenticateHeader(request, response, nonce,
- isn);
- response.sendError(HttpServletResponse.SC_UNAUTHORIZED);
- }
- catch (Exception e)
- {
- e.printStackTrace();
-
- }
- }
-
-
- protected static String generateNonce(HttpServletRequest request) {
-
- long currentTime = System.currentTimeMillis();
-
-
- String ipTimeKey =
- request.getRemoteAddr() + ":" + currentTime + ":" + randomGenerate();
-
- byte[] buffer;
- synchronized (md5Helper) {
- buffer = md5Helper.digest(
- ipTimeKey.getBytes(Charset.defaultCharset()));
- }
-
- return currentTime + ":" + md5Encode(buffer);
- }
-
- private static final char[] hexadecimal =
- {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
- 'a', 'b', 'c', 'd', 'e', 'f'};
-
-
- // --------------------------------------------------------- Public Methods
-
-
- /**
- * Encodes the 128 bit (16 bytes) MD5 into a 32 character String.
- *
- * @param binaryData Array containing the digest
- * @return Encoded MD5, or null if encoding failed
- */
- protected static String md5Encode( byte[] binaryData ) {
-
- if (binaryData.length != 16)
- return null;
-
- char[] buffer = new char[32];
-
- for (int i=0; i<16; i++) {
- int low = binaryData[i] & 0x0f;
- int high = (binaryData[i] & 0xf0) >> 4;
- buffer[i*2] = hexadecimal[high];
- buffer[i*2 + 1] = hexadecimal[low];
- }
-
- return new String(buffer);
-
- }
-
-
-
- protected static String randomGenerate(){
-
- String tid = AlphaNumeric.generateRandomAlphNumeric(CaimitoConfig.digestLength);
-String dig = CaimitoConfig.defaultDigest;
-if (dig != null)
-tid = Crypto.digest(tid,dig);
- return tid;
- }
-
- protected static final String AUTH_HEADER_NAME = "WWW-Authenticate";
- protected static final String QOP = "auth";
-
- protected static void setAuthenticateHeader(HttpServletRequest request,
- HttpServletResponse response,
- String nonce,
- boolean isNonceStale) {
-
- // Get the realm name
- String realmName = CaimitoConfig.SecurityRealmName;
-
- String authenticateHeader;
- if (isNonceStale) {
- authenticateHeader = "Digest realm=\"" + realmName + "\", " +
- "qop=\"" + QOP + "\", nonce=\"" + nonce + "\", " + "opaque=\"" +
- randomGenerate() + "\", stale=true";
- } else {
- authenticateHeader = "Digest realm=\"" + realmName + "\", " +
- "qop=\"" + QOP + "\", nonce=\"" + nonce + "\", " + "opaque=\"" +
- randomGenerate() + "\"";
- }
-
-
-//("authenticateHeader 1 " + authenticateHeader);
- response.setHeader(AUTH_HEADER_NAME, authenticateHeader);
-
- }
-
-
-
- public static String basicLogin( HttpServletRequest request,
- HttpServletResponse response
- )
- throws CaimitoException {
-
- String hr = request.getHeader("Authorization");
- if (hr != null)
- {
- if (hr.startsWith("Basic "))
- {
-
- //hr = SharedMethods.replaceSubstring(hr,"Digest ","");
- hr = hr.trim();
- hr = hr.substring(6,hr.length());
- // username="caimitoadmin", realm="Caimito", nonce="", uri="/", response="2fb52dbbcb7b25fd33840eac3027e9c5"
- NameValuePairs nvp = NameValuePairs.toNameValuePair(hr,"=",",");
- //(nvp + " BASIC 1 " + hr);
- byte[] b = Base64Decoder.fromBase64(hr.getBytes());
- String auth = new String(b);
- String name = auth.substring(0,auth.indexOf(":"));
- String pass = auth.substring(auth.indexOf(":") + 1,auth.length());
- try{
-
- if (UserMgr.getUserMgr(CaimitoConfig.shaftapp).login(CaimitoConfig.shaftapp,name,pass,false) != null)
- {
- //request.setPrincipal(RealmEngine.get().getPrincipal(name));
- //request.setAuthType("BASIC");
- // request.getSession()
- request.setAttribute(CaimitoConfig.caimitouserreqobj,name);
- return name;
- }
- }catch (Exception e){
- e.printStackTrace();
- //return null;
- }
- }
- }
- if (response != null)
- sendBasicError(request,response);
- return null;
-
- }
-
- public static void sendBasicError( HttpServletRequest request,HttpServletResponse response)
- {
- try
- {
- /*
- if (DeploymentDescriptor.isSecureLoginRequired() && !request.getScheme().equalsIgnoreCase("https"))
- {
- String fau = request.getTrimmedRequestURI();
- if (request.getQueryString() != null)
- fau = fau + "?" + request.getQueryString();
- if (!fau.startsWith("/"))
- fau = "/" + fau;
- response.sendRedirect("https://" + request.getServerName() + fau);
- return;
- }*/
- String rn = CaimitoConfig.SecurityRealmName;
-
- //("BASIC ERROR SENT " + rn);
- response.setHeader("Content-Type","text/html");
- response.setHeader("WWW-Authenticate","Basic realm=\"" + rn + "\"");
- response.sendError(401);
- }
- catch (Exception e)
- {
- e.printStackTrace();
-
- }
- }
-}
-
-class CaimitoBooleanHolder{
- public boolean value = false;
-}
->>>>>>> 81b81b090d652d7b3c1de4359597c4836eb617da
View
6 webapps/WEB-INF/caimito/config.properties.sample
@@ -1,4 +1,3 @@
-<<<<<<< HEAD
#cloud_accounts_for_administration_only
cloud.setup=single_cloud_account_with_single_storage
#minutes
@@ -7,11 +6,6 @@ request.timeout=130
#cloud.api.version=
-=======
-#optional - 1.0,2.0
-#cloud.api.version=
-
->>>>>>> 81b81b090d652d7b3c1de4359597c4836eb617da
#file,openstack
resource=file
#A Container or Bucket
View
BIN webapps/WEB-INF/classes/ngasi/caimito/CaimitoConfig.class
Binary file not shown.
View
19 webapps/WEB-INF/web.xml
@@ -29,7 +29,6 @@
</description>
<filter>
<filter-name>shf</filter-name>
-<<<<<<< HEAD
<filter-class>org.shaft.ShaftAsyncFilter</filter-class>
<async-supported>true</async-supported>
</filter>
@@ -39,13 +38,6 @@
<url-pattern>/WEB-INF/*</url-pattern>
<url-pattern>/shaftapps/*</url-pattern>
<url-pattern>/ca/*</url-pattern>
-=======
- <filter-class>org.shaft.ShaftFilter</filter-class>
- </filter>
- <filter-mapping>
- <filter-name>shf</filter-name>
- <url-pattern>/*</url-pattern>
->>>>>>> 81b81b090d652d7b3c1de4359597c4836eb617da
</filter-mapping>
@@ -60,23 +52,15 @@
</servlet>
<servlet-mapping>
<servlet-name>Jersey Web Application</servlet-name>
-<<<<<<< HEAD
<url-pattern>/ca/shaftrest1/*</url-pattern>
<url-pattern>/shaftrest1/*</url-pattern>
-=======
- <url-pattern>/shaftrest/*</url-pattern>
->>>>>>> 81b81b090d652d7b3c1de4359597c4836eb617da
</servlet-mapping>
<servlet>
<servlet-name>webdav</servlet-name>
-<<<<<<< HEAD
<servlet-class>ngasi.caimito.CaimitoAsyncWebdavServlet</servlet-class>
<async-supported>true</async-supported>
-=======
- <servlet-class>ngasi.caimito.CaimitoWebdavServlet</servlet-class>
->>>>>>> 81b81b090d652d7b3c1de4359597c4836eb617da
<init-param>
<param-name>debug</param-name>
<param-value>0</param-value>
@@ -104,13 +88,10 @@
<location>/ca/401.html</location>
</error-page>
<error-page>
-<<<<<<< HEAD
<error-code>403</error-code>
<location>/ca/403.html</location>
</error-page>
<error-page>
-=======
->>>>>>> 81b81b090d652d7b3c1de4359597c4836eb617da
<error-code>500</error-code>
<location>/ca/500.html</location>
</error-page>

0 comments on commit a38136b

Please sign in to comment.
Something went wrong with that request. Please try again.