You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mina.apache.org by be...@apache.org on 2013/07/08 11:51:40 UTC

[1/9] git commit: prepare HBase storage module

Updated Branches:
  refs/heads/master 090ab1e7d -> 9ffe7f302


prepare HBase storage module


Project: http://git-wip-us.apache.org/repos/asf/mina-vysper/repo
Commit: http://git-wip-us.apache.org/repos/asf/mina-vysper/commit/b055a22a
Tree: http://git-wip-us.apache.org/repos/asf/mina-vysper/tree/b055a22a
Diff: http://git-wip-us.apache.org/repos/asf/mina-vysper/diff/b055a22a

Branch: refs/heads/master
Commit: b055a22ac480c1119ad71d316381ed92578bee3e
Parents: 090ab1e
Author: Bernd Fondermann <be...@brainlounge.de>
Authored: Thu Jul 4 13:42:11 2013 +0200
Committer: Bernd Fondermann <be...@brainlounge.de>
Committed: Thu Jul 4 13:42:11 2013 +0200

----------------------------------------------------------------------
 server/storage/hbase/pom.xml | 70 +++++++++++++++++++++++++++++++++++++++
 server/storage/pom.xml       |  1 +
 2 files changed, 71 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mina-vysper/blob/b055a22a/server/storage/hbase/pom.xml
----------------------------------------------------------------------
diff --git a/server/storage/hbase/pom.xml b/server/storage/hbase/pom.xml
new file mode 100644
index 0000000..0a9ba92
--- /dev/null
+++ b/server/storage/hbase/pom.xml
@@ -0,0 +1,70 @@
+<?xml version="1.0" encoding="UTF-8"?>
+  <!--
+    Licensed to the Apache Software Foundation (ASF) under one or more
+    contributor license agreements. See the NOTICE file distributed with
+    this work for additional information regarding copyright ownership.
+    The ASF licenses this file to you under the Apache License, Version
+    2.0 (the "License"); you may not use this file except in compliance
+    with the License. You may obtain a copy of the License at
+
+    http://www.apache.org/licenses/LICENSE-2.0 
+    
+    Unless required by applicable law or agreed to in writing, software 
+    distributed under the License is distributed on an "AS IS" BASIS, 
+    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
+    See the License for the specific language governing permissions and 
+    limitations under the License.
+  -->
+
+<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">
+  <parent>
+    <artifactId>vysper-storage</artifactId>
+    <groupId>org.apache.vysper</groupId>
+    <version>0.8-SNAPSHOT</version>
+  </parent>
+  <modelVersion>4.0.0</modelVersion>
+  <groupId>org.apache.vysper.storage</groupId>
+  <artifactId>vysper-hbase</artifactId>
+  <name>Apache Vysper HBase Storage Binding</name>
+  <version>0.8-SNAPSHOT</version>
+  
+  
+  <dependencies>
+    <dependency>
+      <groupId>org.apache.vysper</groupId>
+      <artifactId>spec-compliance</artifactId>
+      <optional>true</optional>
+    </dependency>
+    
+    <dependency>
+      <groupId>org.apache.vysper</groupId>
+      <artifactId>vysper-core</artifactId>
+    </dependency>
+
+    <dependency>
+      <groupId>org.apache.hbase</groupId>
+      <artifactId>hbase</artifactId>
+      <version>0.94.7</version>
+    </dependency>
+
+      <!-- Runtime dependencies -->
+    <dependency>
+      <groupId>org.slf4j</groupId>
+      <artifactId>slf4j-log4j12</artifactId>
+      <scope>runtime</scope>
+    </dependency>
+    
+    <dependency>
+      <groupId>log4j</groupId>
+      <artifactId>log4j</artifactId>
+      <scope>runtime</scope>
+    </dependency>
+      
+    <!-- Test dependencies -->
+    <dependency>
+      <groupId>junit</groupId>
+      <artifactId>junit</artifactId>
+      <scope>test</scope>
+    </dependency>
+  </dependencies>
+</project>

http://git-wip-us.apache.org/repos/asf/mina-vysper/blob/b055a22a/server/storage/pom.xml
----------------------------------------------------------------------
diff --git a/server/storage/pom.xml b/server/storage/pom.xml
index a49fc36..3c94cf1 100644
--- a/server/storage/pom.xml
+++ b/server/storage/pom.xml
@@ -33,6 +33,7 @@
 
   <modules>
     <module>jcr</module>
+    <module>hbase</module>
   </modules>
 
   <profiles>


[7/9] git commit: HBase storage: add private data persistence

Posted by be...@apache.org.
HBase storage: add private data persistence


Project: http://git-wip-us.apache.org/repos/asf/mina-vysper/repo
Commit: http://git-wip-us.apache.org/repos/asf/mina-vysper/commit/5317a44a
Tree: http://git-wip-us.apache.org/repos/asf/mina-vysper/tree/5317a44a
Diff: http://git-wip-us.apache.org/repos/asf/mina-vysper/diff/5317a44a

Branch: refs/heads/master
Commit: 5317a44a772927034bcc87021b3f662b2d40820e
Parents: 472093c
Author: Bernd Fondermann <be...@brainlounge.de>
Authored: Mon Jul 8 10:28:36 2013 +0200
Committer: Bernd Fondermann <be...@brainlounge.de>
Committed: Mon Jul 8 10:28:36 2013 +0200

----------------------------------------------------------------------
 .../vysper/storage/hbase/HBaseStorage.java      |  9 +-
 .../HBasePrivateDataPersistenceManager.java     | 95 ++++++++++++++++++++
 2 files changed, 103 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mina-vysper/blob/5317a44a/server/storage/hbase/src/main/java/org/apache/vysper/storage/hbase/HBaseStorage.java
----------------------------------------------------------------------
diff --git a/server/storage/hbase/src/main/java/org/apache/vysper/storage/hbase/HBaseStorage.java b/server/storage/hbase/src/main/java/org/apache/vysper/storage/hbase/HBaseStorage.java
index b2faeb9..2e0b16f 100644
--- a/server/storage/hbase/src/main/java/org/apache/vysper/storage/hbase/HBaseStorage.java
+++ b/server/storage/hbase/src/main/java/org/apache/vysper/storage/hbase/HBaseStorage.java
@@ -39,6 +39,10 @@ import static org.apache.vysper.storage.hbase.HBaseUtils.*;
 
 /**
  * back-end adaptor for HBase
+ * 
+ * prepare HBase by creating table vysper_user:
+ * create 'vysper_user', {NAME => 'bsc', VERSIONS => 1}, {NAME => 'cct', VERSIONS => 1}, {NAME => 'rst', VERSIONS => 1}, {NAME => 'xep', VERSIONS => 5}
+ * 
  * @author The Apache MINA Project (dev@mina.apache.org)
  */
 public class HBaseStorage {
@@ -51,6 +55,8 @@ public class HBaseStorage {
     public static final byte[] COLUMN_FAMILY_NAME_CONTACT_BYTES = COLUMN_FAMILY_NAME_CONTACT.getBytes();
     public static final String COLUMN_FAMILY_NAME_ROSTER = "rst";
     public static final byte[] COLUMN_FAMILY_NAME_ROSTER_BYTES = COLUMN_FAMILY_NAME_ROSTER.getBytes();
+    public static final String COLUMN_FAMILY_NAME_XEP = "xep";
+    public static final byte[] COLUMN_FAMILY_NAME_XEP_BYTES = COLUMN_FAMILY_NAME_XEP.getBytes();
     
     protected static HBaseStorage hbaseStorageSingleton;
 
@@ -111,8 +117,9 @@ public class HBaseStorage {
             columnFamilyNames = new String[]{COLUMN_FAMILY_NAME_CONTACT};
         }
 
-        final HTableInterface userTable = getTable(TABLE_NAME_USER);
+        HTableInterface userTable = null;
         try {
+            userTable = getTable(TABLE_NAME_USER);
             final Get get = new Get(entityAsBytes(entity.getBareJID()));
             for (String columnFamilyName : columnFamilyNames) {
                 get.addFamily(asBytes(columnFamilyName));

http://git-wip-us.apache.org/repos/asf/mina-vysper/blob/5317a44a/server/storage/hbase/src/main/java/org/apache/vysper/storage/hbase/privatedata/HBasePrivateDataPersistenceManager.java
----------------------------------------------------------------------
diff --git a/server/storage/hbase/src/main/java/org/apache/vysper/storage/hbase/privatedata/HBasePrivateDataPersistenceManager.java b/server/storage/hbase/src/main/java/org/apache/vysper/storage/hbase/privatedata/HBasePrivateDataPersistenceManager.java
new file mode 100644
index 0000000..1f80063
--- /dev/null
+++ b/server/storage/hbase/src/main/java/org/apache/vysper/storage/hbase/privatedata/HBasePrivateDataPersistenceManager.java
@@ -0,0 +1,95 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ *
+ */
+package org.apache.vysper.storage.hbase.privatedata;
+
+import org.apache.commons.lang.StringUtils;
+import org.apache.hadoop.hbase.client.HTableInterface;
+import org.apache.hadoop.hbase.client.Put;
+import org.apache.hadoop.hbase.client.Result;
+import org.apache.vysper.storage.hbase.HBaseStorage;
+import org.apache.vysper.xmpp.addressing.Entity;
+import org.apache.vysper.xmpp.modules.extension.xep0049_privatedata.PrivateDataPersistenceManager;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.io.IOException;
+
+import static org.apache.vysper.storage.hbase.HBaseStorage.*;
+import static org.apache.vysper.storage.hbase.HBaseUtils.*;
+
+/**
+ * @author The Apache MINA Project (dev@mina.apache.org)
+ */
+public class HBasePrivateDataPersistenceManager implements PrivateDataPersistenceManager {
+
+    final Logger logger = LoggerFactory.getLogger(HBasePrivateDataPersistenceManager.class);
+
+    public static final String COLUMN_PREFIX_NAME = "xep_priv_data:";
+    
+    protected HBaseStorage hbaseStorage;
+
+    public HBasePrivateDataPersistenceManager(HBaseStorage hbaseStorage) {
+        this.hbaseStorage = hbaseStorage;
+    }
+
+    public boolean isAvailable() {
+        HTableInterface table = null;
+        try {
+            table = hbaseStorage.getTable(TABLE_NAME_USER);
+            return table != null;
+        } finally {
+            hbaseStorage.putTable(table);
+        }
+    }
+
+    public String getPrivateData(Entity entity, String key) {
+        final Result entityRow = hbaseStorage.getEntityRow(entity, COLUMN_FAMILY_NAME_XEP);
+
+        String column = COLUMN_PREFIX_NAME + key;
+        String value = toStr(entityRow.getValue(COLUMN_FAMILY_NAME_XEP_BYTES, asBytes(column)));
+        
+        return value;
+    }
+
+    public boolean setPrivateData(Entity entity, String key, String xml) {
+
+        if (key == null || StringUtils.isBlank(key)) {
+            throw new IllegalArgumentException("private data key must not be blank");
+        }
+        String column = COLUMN_PREFIX_NAME + key;
+        
+        final Put put = new Put(entityAsBytes(entity.getBareJID()));
+        put.add(COLUMN_FAMILY_NAME_XEP_BYTES, asBytes(column), asBytes(xml));
+
+        HTableInterface table = null;
+        try {
+            table = hbaseStorage.getTable(TABLE_NAME_USER);
+            table.put(put);
+            logger.debug("stored private data for {} with key {}", entity, key);
+            return true;
+        } catch (IOException e) {
+            logger.warn("failed to save private data for {} with key {}", entity, key);
+            return false;
+        } finally {
+            hbaseStorage.putTable(table);
+        }
+    }
+
+}


[8/9] git commit: private data storage: use proper namespace in column family 'xep'

Posted by be...@apache.org.
private data storage: use proper namespace in column family 'xep'


Project: http://git-wip-us.apache.org/repos/asf/mina-vysper/repo
Commit: http://git-wip-us.apache.org/repos/asf/mina-vysper/commit/1b50d19c
Tree: http://git-wip-us.apache.org/repos/asf/mina-vysper/tree/1b50d19c
Diff: http://git-wip-us.apache.org/repos/asf/mina-vysper/diff/1b50d19c

Branch: refs/heads/master
Commit: 1b50d19c984c79382dc5d87f1a98e460677c868d
Parents: 5317a44
Author: Bernd Fondermann <be...@brainlounge.de>
Authored: Mon Jul 8 11:26:51 2013 +0200
Committer: Bernd Fondermann <be...@brainlounge.de>
Committed: Mon Jul 8 11:26:51 2013 +0200

----------------------------------------------------------------------
 .../HBasePrivateDataPersistenceManager.java          | 15 +++++++++++----
 1 file changed, 11 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mina-vysper/blob/1b50d19c/server/storage/hbase/src/main/java/org/apache/vysper/storage/hbase/privatedata/HBasePrivateDataPersistenceManager.java
----------------------------------------------------------------------
diff --git a/server/storage/hbase/src/main/java/org/apache/vysper/storage/hbase/privatedata/HBasePrivateDataPersistenceManager.java b/server/storage/hbase/src/main/java/org/apache/vysper/storage/hbase/privatedata/HBasePrivateDataPersistenceManager.java
index 1f80063..4024b59 100644
--- a/server/storage/hbase/src/main/java/org/apache/vysper/storage/hbase/privatedata/HBasePrivateDataPersistenceManager.java
+++ b/server/storage/hbase/src/main/java/org/apache/vysper/storage/hbase/privatedata/HBasePrivateDataPersistenceManager.java
@@ -26,6 +26,7 @@ import org.apache.hadoop.hbase.client.Result;
 import org.apache.vysper.storage.hbase.HBaseStorage;
 import org.apache.vysper.xmpp.addressing.Entity;
 import org.apache.vysper.xmpp.modules.extension.xep0049_privatedata.PrivateDataPersistenceManager;
+import org.apache.vysper.xmpp.protocol.NamespaceURIs;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -41,14 +42,16 @@ public class HBasePrivateDataPersistenceManager implements PrivateDataPersistenc
 
     final Logger logger = LoggerFactory.getLogger(HBasePrivateDataPersistenceManager.class);
 
-    public static final String COLUMN_PREFIX_NAME = "xep_priv_data:";
-    
     protected HBaseStorage hbaseStorage;
 
     public HBasePrivateDataPersistenceManager(HBaseStorage hbaseStorage) {
         this.hbaseStorage = hbaseStorage;
     }
 
+    protected String getNamespace() {
+        return NamespaceURIs.PRIVATE_DATA;
+    }
+    
     public boolean isAvailable() {
         HTableInterface table = null;
         try {
@@ -62,18 +65,22 @@ public class HBasePrivateDataPersistenceManager implements PrivateDataPersistenc
     public String getPrivateData(Entity entity, String key) {
         final Result entityRow = hbaseStorage.getEntityRow(entity, COLUMN_FAMILY_NAME_XEP);
 
-        String column = COLUMN_PREFIX_NAME + key;
+        String column = getColumnForKey(key);
         String value = toStr(entityRow.getValue(COLUMN_FAMILY_NAME_XEP_BYTES, asBytes(column)));
         
         return value;
     }
 
+    protected String getColumnForKey(String key) {
+        return getNamespace() + "#"+ key;
+    }
+
     public boolean setPrivateData(Entity entity, String key, String xml) {
 
         if (key == null || StringUtils.isBlank(key)) {
             throw new IllegalArgumentException("private data key must not be blank");
         }
-        String column = COLUMN_PREFIX_NAME + key;
+        String column = getColumnForKey(key);
         
         final Put put = new Put(entityAsBytes(entity.getBareJID()));
         put.add(COLUMN_FAMILY_NAME_XEP_BYTES, asBytes(column), asBytes(xml));


[5/9] git commit: HBase roster manager: support groups

Posted by be...@apache.org.
HBase roster manager: support groups


Project: http://git-wip-us.apache.org/repos/asf/mina-vysper/repo
Commit: http://git-wip-us.apache.org/repos/asf/mina-vysper/commit/0636dc93
Tree: http://git-wip-us.apache.org/repos/asf/mina-vysper/tree/0636dc93
Diff: http://git-wip-us.apache.org/repos/asf/mina-vysper/diff/0636dc93

Branch: refs/heads/master
Commit: 0636dc936315a6095d1d974799a436ec32217b3b
Parents: 9bbab82
Author: Bernd Fondermann <be...@brainlounge.de>
Authored: Sat Jul 6 17:40:26 2013 +0200
Committer: Bernd Fondermann <be...@brainlounge.de>
Committed: Sat Jul 6 17:40:26 2013 +0200

----------------------------------------------------------------------
 .../hbase/roster/HBaseRosterManager.java        | 20 +++++++++++++++++---
 1 file changed, 17 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mina-vysper/blob/0636dc93/server/storage/hbase/src/main/java/org/apache/vysper/storage/hbase/roster/HBaseRosterManager.java
----------------------------------------------------------------------
diff --git a/server/storage/hbase/src/main/java/org/apache/vysper/storage/hbase/roster/HBaseRosterManager.java b/server/storage/hbase/src/main/java/org/apache/vysper/storage/hbase/roster/HBaseRosterManager.java
index 0396e2d..0ec3e21 100644
--- a/server/storage/hbase/src/main/java/org/apache/vysper/storage/hbase/roster/HBaseRosterManager.java
+++ b/server/storage/hbase/src/main/java/org/apache/vysper/storage/hbase/roster/HBaseRosterManager.java
@@ -25,7 +25,6 @@ import org.apache.hadoop.hbase.client.Put;
 import org.apache.hadoop.hbase.client.Result;
 import org.apache.vysper.storage.hbase.HBaseStorage;
 import org.apache.vysper.xmpp.addressing.Entity;
-import org.apache.vysper.xmpp.addressing.EntityFormatException;
 import org.apache.vysper.xmpp.addressing.EntityImpl;
 import org.apache.vysper.xmpp.modules.roster.AskSubscriptionType;
 import org.apache.vysper.xmpp.modules.roster.MutableRoster;
@@ -58,6 +57,7 @@ public class HBaseRosterManager extends AbstractRosterManager {
     public static final String COLUMN_PREFIX_NAME = "n:";
     public static final String COLUMN_PREFIX_TYPE = "t:";
     public static final String COLUMN_PREFIX_ASKTYPE = "a:";
+    public static final String COLUMN_PREFIX_GROUP = "g:";
 
     protected HBaseStorage hBaseStorage;
 
@@ -67,7 +67,7 @@ public class HBaseRosterManager extends AbstractRosterManager {
 
     @Override
     protected Roster retrieveRosterInternal(Entity bareJid) {
-        final Result entityRow = hBaseStorage.getEntityRow(bareJid);
+        final Result entityRow = hBaseStorage.getEntityRow(bareJid, COLUMN_FAMILY_NAME_CONTACT, COLUMN_FAMILY_NAME_ROSTER);
 
         MutableRoster roster = new MutableRoster();
 
@@ -108,7 +108,15 @@ public class HBaseRosterManager extends AbstractRosterManager {
             }
 
             List<RosterGroup> groups = new ArrayList<RosterGroup>();
-            // TODO read groups
+            int i = 1;
+            while (true) {
+                String columnName = COLUMN_PREFIX_GROUP + i + ":" + contactAsString;
+                String groupName = toStr(contactDetails.get(asBytes(columnName)));
+                if (groupName == null) break;
+
+                groups.add(new RosterGroup(groupName));
+                i++;
+            }
 
             RosterItem item = new RosterItem(contactJID, name, subscriptionType, askSubscriptionType, groups);
             LOG.info("item loaded for " + bareJid.getFullQualifiedName() + ": " + item.toString());
@@ -138,6 +146,12 @@ public class HBaseRosterManager extends AbstractRosterManager {
         put.add(COLUMN_FAMILY_NAME_ROSTER_BYTES, asBytes(COLUMN_PREFIX_NAME + contactIdentifier), asBytes(rosterItem.getName()));
         put.add(COLUMN_FAMILY_NAME_ROSTER_BYTES, asBytes(COLUMN_PREFIX_TYPE + contactIdentifier), asBytes(rosterItem.getSubscriptionType().value()));
         put.add(COLUMN_FAMILY_NAME_ROSTER_BYTES, asBytes(COLUMN_PREFIX_ASKTYPE + contactIdentifier), asBytes(rosterItem.getAskSubscriptionType().value()));
+        int i = 1;
+        for (RosterGroup rosterGroup : rosterItem.getGroups()) {
+            String columnName = COLUMN_PREFIX_GROUP + i + ":" + contactIdentifier; 
+            put.add(COLUMN_FAMILY_NAME_ROSTER_BYTES, asBytes(columnName), asBytes(rosterGroup.getName()));
+            i++;
+        }
 
         final HTableInterface userTable = hBaseStorage.getTable(TABLE_NAME_USER);
         try {


[2/9] git commit: first try of a HBase storage for Vysper

Posted by be...@apache.org.
first try of a HBase storage for Vysper


Project: http://git-wip-us.apache.org/repos/asf/mina-vysper/repo
Commit: http://git-wip-us.apache.org/repos/asf/mina-vysper/commit/843a6d6c
Tree: http://git-wip-us.apache.org/repos/asf/mina-vysper/tree/843a6d6c
Diff: http://git-wip-us.apache.org/repos/asf/mina-vysper/diff/843a6d6c

Branch: refs/heads/master
Commit: 843a6d6c1ee63a08d5830722e9c8f4607eb122c9
Parents: b055a22
Author: Bernd Fondermann <be...@brainlounge.de>
Authored: Fri Jul 5 22:11:45 2013 +0200
Committer: Bernd Fondermann <be...@brainlounge.de>
Committed: Fri Jul 5 22:11:45 2013 +0200

----------------------------------------------------------------------
 server/storage/hbase/pom.xml                    |   6 +
 .../vysper/storage/hbase/HBaseStorage.java      | 145 +++++++++++++++
 .../storage/hbase/HBaseStorageException.java    |  21 +++
 .../hbase/HBaseStorageProviderRegistry.java     |  37 ++++
 .../apache/vysper/storage/hbase/HBaseUtils.java |  34 ++++
 .../hbase/roster/HBaseRosterManager.java        | 177 +++++++++++++++++++
 .../storage/hbase/user/HBaseUserManagement.java | 144 +++++++++++++++
 7 files changed, 564 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mina-vysper/blob/843a6d6c/server/storage/hbase/pom.xml
----------------------------------------------------------------------
diff --git a/server/storage/hbase/pom.xml b/server/storage/hbase/pom.xml
index 0a9ba92..480bd57 100644
--- a/server/storage/hbase/pom.xml
+++ b/server/storage/hbase/pom.xml
@@ -42,6 +42,12 @@
     </dependency>
 
     <dependency>
+      <groupId>org.apache.hadoop</groupId>
+      <artifactId>hadoop-core</artifactId>
+      <version>1.0.4</version>
+    </dependency>
+      
+    <dependency>
       <groupId>org.apache.hbase</groupId>
       <artifactId>hbase</artifactId>
       <version>0.94.7</version>

http://git-wip-us.apache.org/repos/asf/mina-vysper/blob/843a6d6c/server/storage/hbase/src/main/java/org/apache/vysper/storage/hbase/HBaseStorage.java
----------------------------------------------------------------------
diff --git a/server/storage/hbase/src/main/java/org/apache/vysper/storage/hbase/HBaseStorage.java b/server/storage/hbase/src/main/java/org/apache/vysper/storage/hbase/HBaseStorage.java
new file mode 100644
index 0000000..b2faeb9
--- /dev/null
+++ b/server/storage/hbase/src/main/java/org/apache/vysper/storage/hbase/HBaseStorage.java
@@ -0,0 +1,145 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ *
+ */
+package org.apache.vysper.storage.hbase;
+
+import org.apache.hadoop.conf.Configuration;
+import org.apache.hadoop.hbase.HBaseConfiguration;
+import org.apache.hadoop.hbase.MasterNotRunningException;
+import org.apache.hadoop.hbase.ZooKeeperConnectionException;
+import org.apache.hadoop.hbase.client.Get;
+import org.apache.hadoop.hbase.client.HBaseAdmin;
+import org.apache.hadoop.hbase.client.HTableInterface;
+import org.apache.hadoop.hbase.client.HTablePool;
+import org.apache.hadoop.hbase.client.Result;
+import org.apache.vysper.xmpp.addressing.Entity;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.io.IOException;
+import java.io.UnsupportedEncodingException;
+
+import static org.apache.vysper.storage.hbase.HBaseUtils.*;
+
+/**
+ * back-end adaptor for HBase
+ * @author The Apache MINA Project (dev@mina.apache.org)
+ */
+public class HBaseStorage {
+
+    final Logger LOG = LoggerFactory.getLogger(HBaseStorage.class);
+
+    public static final String TABLE_NAME_USER = "vysper_user";
+    public static final String COLUMN_FAMILY_NAME_BASIC = "bsc";
+    public static final String COLUMN_FAMILY_NAME_CONTACT = "cct";
+    public static final byte[] COLUMN_FAMILY_NAME_CONTACT_BYTES = COLUMN_FAMILY_NAME_CONTACT.getBytes();
+    public static final String COLUMN_FAMILY_NAME_ROSTER = "rst";
+    public static final byte[] COLUMN_FAMILY_NAME_ROSTER_BYTES = COLUMN_FAMILY_NAME_ROSTER.getBytes();
+    
+    protected static HBaseStorage hbaseStorageSingleton;
+
+    protected HBaseStorage() {
+        super();
+        // protected
+    }
+
+    public static HBaseStorage getInstance() throws HBaseStorageException {
+        if (hbaseStorageSingleton != null) return hbaseStorageSingleton;
+        synchronized (HBaseStorage.class) {
+            if (hbaseStorageSingleton == null) hbaseStorageSingleton = new HBaseStorage();
+            hbaseStorageSingleton.init();
+            return hbaseStorageSingleton;
+        }
+    }
+
+    protected Configuration hbaseConfiguration = null;
+    protected HBaseAdmin hbaseAdmin;
+    protected HTablePool tablePool;
+
+    public void init() throws HBaseStorageException {
+        try {
+            hbaseConfiguration = HBaseConfiguration.create();
+        } catch (Exception e) {
+            throw new HBaseStorageException("failed to load HBase configuration from file hbase-site.xml");
+        }
+        final int size = hbaseConfiguration.size();
+        if (size == 0) throw new HBaseStorageException("HBase configuration is empty");
+
+        try {
+            connectHBase();
+        } catch (HBaseStorageException e) {
+            LOG.error("connection to HBase failed", e);
+            throw e;
+        }
+    }
+
+    protected void connectHBase() throws HBaseStorageException {
+        try {
+            LOG.info("connecting to HBase...");
+            hbaseAdmin = new HBaseAdmin(hbaseConfiguration);
+            tablePool = new HTablePool(hbaseConfiguration, Integer.MAX_VALUE);
+            LOG.info("HBase connected.");
+        } catch (MasterNotRunningException e) {
+            throw new HBaseStorageException("failed connecting to HBase Master Server", e);
+        } catch (ZooKeeperConnectionException e) {
+            throw new HBaseStorageException("failed connecting to HBase Zookeeper Cluster", e);
+        }
+    }
+
+    public HTableInterface getTable(String tableName) {
+        return tablePool.getTable(tableName);
+    }
+
+    public Result getEntityRow(Entity entity, String... columnFamilyNames) {
+        if (columnFamilyNames == null || columnFamilyNames.length == 0) {
+            columnFamilyNames = new String[]{COLUMN_FAMILY_NAME_CONTACT};
+        }
+
+        final HTableInterface userTable = getTable(TABLE_NAME_USER);
+        try {
+            final Get get = new Get(entityAsBytes(entity.getBareJID()));
+            for (String columnFamilyName : columnFamilyNames) {
+                get.addFamily(asBytes(columnFamilyName));
+            }
+            final Result result = userTable.get(get);
+            return result;
+        } catch (IOException e) {
+            e.printStackTrace();  //To change body of catch statement use File | Settings | File Templates.
+            return null;
+        } finally {
+            putTable(userTable);
+        }
+    }
+
+    public void putTable(HTableInterface userTable) {
+        if (userTable == null) return;
+        try {
+            userTable.close();
+        } catch (IOException e) {
+            String tableName = "unknown";
+            try {
+                tableName = new String(userTable.getTableName(), "UTF-8");
+            } catch (UnsupportedEncodingException e1) {
+                e1.printStackTrace();  // encoding exceptions are killing me
+            }
+            LOG.warn("failed to return table " + tableName + " to pool");
+        }
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/mina-vysper/blob/843a6d6c/server/storage/hbase/src/main/java/org/apache/vysper/storage/hbase/HBaseStorageException.java
----------------------------------------------------------------------
diff --git a/server/storage/hbase/src/main/java/org/apache/vysper/storage/hbase/HBaseStorageException.java b/server/storage/hbase/src/main/java/org/apache/vysper/storage/hbase/HBaseStorageException.java
new file mode 100644
index 0000000..86ad141
--- /dev/null
+++ b/server/storage/hbase/src/main/java/org/apache/vysper/storage/hbase/HBaseStorageException.java
@@ -0,0 +1,21 @@
+package org.apache.vysper.storage.hbase;
+
+/**
+ */
+public class HBaseStorageException extends Exception {
+    public HBaseStorageException() {
+        super();
+    }
+
+    public HBaseStorageException(String s) {
+        super(s);
+    }
+
+    public HBaseStorageException(String s, Throwable throwable) {
+        super(s, throwable);
+    }
+
+    public HBaseStorageException(Throwable throwable) {
+        super(throwable);
+    }
+}

http://git-wip-us.apache.org/repos/asf/mina-vysper/blob/843a6d6c/server/storage/hbase/src/main/java/org/apache/vysper/storage/hbase/HBaseStorageProviderRegistry.java
----------------------------------------------------------------------
diff --git a/server/storage/hbase/src/main/java/org/apache/vysper/storage/hbase/HBaseStorageProviderRegistry.java b/server/storage/hbase/src/main/java/org/apache/vysper/storage/hbase/HBaseStorageProviderRegistry.java
new file mode 100644
index 0000000..32ad50a
--- /dev/null
+++ b/server/storage/hbase/src/main/java/org/apache/vysper/storage/hbase/HBaseStorageProviderRegistry.java
@@ -0,0 +1,37 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ *
+ */
+package org.apache.vysper.storage.hbase;
+
+import org.apache.vysper.storage.OpenStorageProviderRegistry;
+import org.apache.vysper.storage.hbase.roster.HBaseRosterManager;
+import org.apache.vysper.storage.hbase.user.HBaseUserManagement;
+
+/**
+ *
+ * @author The Apache MINA Project (dev@mina.apache.org)
+ */
+public class HBaseStorageProviderRegistry extends OpenStorageProviderRegistry {
+
+    public HBaseStorageProviderRegistry() throws HBaseStorageException {
+        add(new HBaseUserManagement(HBaseStorage.getInstance()));
+        add(new HBaseRosterManager(HBaseStorage.getInstance()));
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/mina-vysper/blob/843a6d6c/server/storage/hbase/src/main/java/org/apache/vysper/storage/hbase/HBaseUtils.java
----------------------------------------------------------------------
diff --git a/server/storage/hbase/src/main/java/org/apache/vysper/storage/hbase/HBaseUtils.java b/server/storage/hbase/src/main/java/org/apache/vysper/storage/hbase/HBaseUtils.java
new file mode 100644
index 0000000..a0d8f49
--- /dev/null
+++ b/server/storage/hbase/src/main/java/org/apache/vysper/storage/hbase/HBaseUtils.java
@@ -0,0 +1,34 @@
+package org.apache.vysper.storage.hbase;
+
+import org.apache.vysper.xmpp.addressing.Entity;
+
+import java.io.UnsupportedEncodingException;
+
+/**
+ */
+public class HBaseUtils {
+
+    public static byte[] asBytes(String str) {
+        if (str == null) return null;
+        try {
+            return str.getBytes("UTF-8");
+        } catch (UnsupportedEncodingException e) {
+            e.printStackTrace();  // won't happen! UTF-8 is supported
+            return null;
+        }
+    }
+
+    public static byte[] entityAsBytes(Entity entity) {
+        if (entity == null) return null;
+        return asBytes(entity.getFullQualifiedName());
+    }
+
+    public static String toStr(byte[] bytes) {
+        if (bytes == null) return null;
+        try {
+            return new String(bytes, "UTF-8");
+        } catch (UnsupportedEncodingException e) {
+            return null; // will not happen for UTF-8
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/mina-vysper/blob/843a6d6c/server/storage/hbase/src/main/java/org/apache/vysper/storage/hbase/roster/HBaseRosterManager.java
----------------------------------------------------------------------
diff --git a/server/storage/hbase/src/main/java/org/apache/vysper/storage/hbase/roster/HBaseRosterManager.java b/server/storage/hbase/src/main/java/org/apache/vysper/storage/hbase/roster/HBaseRosterManager.java
new file mode 100644
index 0000000..a7417d6
--- /dev/null
+++ b/server/storage/hbase/src/main/java/org/apache/vysper/storage/hbase/roster/HBaseRosterManager.java
@@ -0,0 +1,177 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ *
+ */
+package org.apache.vysper.storage.hbase.roster;
+
+import org.apache.hadoop.hbase.client.Delete;
+import org.apache.hadoop.hbase.client.HTableInterface;
+import org.apache.hadoop.hbase.client.Put;
+import org.apache.hadoop.hbase.client.Result;
+import org.apache.vysper.storage.hbase.HBaseStorage;
+import org.apache.vysper.xmpp.addressing.Entity;
+import org.apache.vysper.xmpp.addressing.EntityFormatException;
+import org.apache.vysper.xmpp.addressing.EntityImpl;
+import org.apache.vysper.xmpp.modules.roster.AskSubscriptionType;
+import org.apache.vysper.xmpp.modules.roster.MutableRoster;
+import org.apache.vysper.xmpp.modules.roster.Roster;
+import org.apache.vysper.xmpp.modules.roster.RosterException;
+import org.apache.vysper.xmpp.modules.roster.RosterGroup;
+import org.apache.vysper.xmpp.modules.roster.RosterItem;
+import org.apache.vysper.xmpp.modules.roster.SubscriptionType;
+import org.apache.vysper.xmpp.modules.roster.persistence.AbstractRosterManager;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.NavigableMap;
+
+import static org.apache.vysper.storage.hbase.HBaseStorage.*;
+import static org.apache.vysper.storage.hbase.HBaseUtils.asBytes;
+import static org.apache.vysper.storage.hbase.HBaseUtils.entityAsBytes;
+import static org.apache.vysper.storage.hbase.HBaseUtils.toStr;
+
+/**
+ * @author The Apache MINA Project (dev@mina.apache.org)
+ */
+public class HBaseRosterManager extends AbstractRosterManager {
+
+    final Logger LOG = LoggerFactory.getLogger(HBaseRosterManager.class);
+    
+    public static final String COLUMN_PREFIX_NAME = "n:";
+    public static final String COLUMN_PREFIX_TYPE = "t:";
+    public static final String COLUMN_PREFIX_ASKTYPE = "a:";
+
+    protected HBaseStorage hBaseStorage;
+
+    public HBaseRosterManager(HBaseStorage hBaseStorage) {
+        this.hBaseStorage = hBaseStorage;
+    }
+
+    @Override
+    protected Roster retrieveRosterInternal(Entity bareJid) {
+        final Result entityRow = hBaseStorage.getEntityRow(bareJid);
+
+        MutableRoster roster = new MutableRoster();
+
+        final NavigableMap<byte[],byte[]> contacts = entityRow.getFamilyMap(COLUMN_FAMILY_NAME_CONTACT_BYTES);
+        for (byte[] contactBytes : contacts.keySet()) {
+            String contactAsString = null;
+            EntityImpl contactJID = null;
+            try {
+                contactAsString = new String(contactBytes, "UTF-8");
+                contactJID = EntityImpl.parse(contactAsString);
+            } catch (Exception e) {
+                LOG.warn("failed to read contact identified by '{}' for user {}", bareJid, contactAsString);
+                continue;
+            }
+
+            final NavigableMap<byte[],byte[]> contactDetails = entityRow.getFamilyMap(COLUMN_FAMILY_NAME_ROSTER_BYTES);
+            String name = toStr(contactDetails.get(asBytes(COLUMN_PREFIX_NAME + contactAsString)));
+            String typeString = toStr(contactDetails.get(asBytes(COLUMN_PREFIX_TYPE + contactAsString)));
+            String askTypeString = toStr(contactDetails.get(asBytes(COLUMN_PREFIX_ASKTYPE + contactAsString)));
+
+            SubscriptionType subscriptionType = null;
+            try {
+                subscriptionType = SubscriptionType.valueOf(typeString == null ? "NONE" : typeString.toUpperCase());
+            } catch (IllegalArgumentException e) {
+                LOG.warn("when loading roster for user " + bareJid + ", contact " + contactJID + " misses a subscription type");
+            }
+
+            AskSubscriptionType askSubscriptionType = AskSubscriptionType.NOT_SET;
+            try {
+                if (askTypeString != null)
+                    askSubscriptionType = AskSubscriptionType.valueOf(askTypeString);
+            } catch (IllegalArgumentException e) {
+                LOG.warn("when loading roster for user " + bareJid.getFullQualifiedName() + ", contact "
+                        + contactJID.getFullQualifiedName() + ", the ask subscription type is unparsable. skipping!");
+                continue; // don't return it, don't set a default!
+            }
+
+            List<RosterGroup> groups = new ArrayList<RosterGroup>();
+            // TODO read groups
+
+            RosterItem item = new RosterItem(contactJID, name, subscriptionType, askSubscriptionType, groups);
+            LOG.info("item loaded for " + bareJid.getFullQualifiedName() + ": " + item.toString());
+            roster.addItem(item);
+        }
+        return roster;
+    }
+
+    @Override
+    protected Roster addNewRosterInternal(Entity jid) {
+        return new MutableRoster();
+    }
+
+    @Override
+    public void addContact(Entity jid, RosterItem rosterItem) throws RosterException {
+        if (jid == null)
+            throw new RosterException("jid not provided");
+        if (rosterItem.getJid() == null)
+            throw new RosterException("contact jid not provided");
+
+        Entity contactJid = rosterItem.getJid().getBareJID();
+        final String contactIdentifier = contactJid.getFullQualifiedName();
+        
+        // prepare contact entries
+        final Put put = new Put(entityAsBytes(jid.getBareJID()));
+        put.add(COLUMN_FAMILY_NAME_CONTACT_BYTES, asBytes(contactIdentifier), asBytes(rosterItem.getSubscriptionType().value()));
+        put.add(COLUMN_FAMILY_NAME_ROSTER_BYTES, asBytes(COLUMN_PREFIX_NAME + contactIdentifier), asBytes(rosterItem.getName()));
+        put.add(COLUMN_FAMILY_NAME_ROSTER_BYTES, asBytes(COLUMN_PREFIX_TYPE + contactIdentifier), asBytes(rosterItem.getSubscriptionType().value()));
+        put.add(COLUMN_FAMILY_NAME_ROSTER_BYTES, asBytes(COLUMN_PREFIX_ASKTYPE + contactIdentifier), asBytes(rosterItem.getAskSubscriptionType().value()));
+
+        final HTableInterface userTable = hBaseStorage.getTable(TABLE_NAME_USER);
+        try {
+            userTable.put(put);
+            LOG.info("contact {} saved to HBase for user {}", rosterItem.getJid(), jid);
+        } catch (IOException e) {
+            throw new RosterException("failed to add contact node to roster for user = " + jid.getFullQualifiedName()
+                    + " and contact jid = " + rosterItem.getJid().getFullQualifiedName(), e);
+        } finally {
+            hBaseStorage.putTable(userTable);
+        }
+    }
+
+    @Override
+    public void removeContact(Entity jidUser, Entity jidContact) throws RosterException {
+        if (jidUser == null)
+            throw new RosterException("jid not provided");
+        if (jidContact == null)
+            throw new RosterException("contact jid not provided");
+
+        final String contactIdentifier = jidContact.getFullQualifiedName();
+        final Delete delete = new Delete(entityAsBytes(jidUser.getBareJID()));
+        delete.deleteColumns(COLUMN_FAMILY_NAME_CONTACT_BYTES, asBytes(contactIdentifier));
+        delete.deleteColumns(COLUMN_FAMILY_NAME_ROSTER_BYTES, asBytes(COLUMN_PREFIX_NAME + contactIdentifier));
+        delete.deleteColumns(COLUMN_FAMILY_NAME_ROSTER_BYTES, asBytes(COLUMN_PREFIX_TYPE + contactIdentifier));
+        delete.deleteColumns(COLUMN_FAMILY_NAME_ROSTER_BYTES, asBytes(COLUMN_PREFIX_ASKTYPE + contactIdentifier));
+        
+        final HTableInterface userTable = hBaseStorage.getTable(TABLE_NAME_USER);
+        try {
+            userTable.delete(delete);
+            LOG.info("contact {} removed from HBase for user {}", jidContact, jidUser);
+        } catch (IOException e) {
+            throw new RosterException("failed to add contact node to roster for user = " + jidUser.getFullQualifiedName()
+                    + " and contact jid = " + jidContact.getFullQualifiedName(), e);
+        } finally {
+            hBaseStorage.putTable(userTable);
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/mina-vysper/blob/843a6d6c/server/storage/hbase/src/main/java/org/apache/vysper/storage/hbase/user/HBaseUserManagement.java
----------------------------------------------------------------------
diff --git a/server/storage/hbase/src/main/java/org/apache/vysper/storage/hbase/user/HBaseUserManagement.java b/server/storage/hbase/src/main/java/org/apache/vysper/storage/hbase/user/HBaseUserManagement.java
new file mode 100644
index 0000000..72a2b0e
--- /dev/null
+++ b/server/storage/hbase/src/main/java/org/apache/vysper/storage/hbase/user/HBaseUserManagement.java
@@ -0,0 +1,144 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ *
+ */
+package org.apache.vysper.storage.hbase.user;
+
+import org.apache.hadoop.hbase.client.Put;
+import org.apache.hadoop.hbase.client.Result;
+import org.apache.vysper.storage.hbase.HBaseStorage;
+import org.apache.vysper.xmpp.addressing.Entity;
+import org.apache.vysper.xmpp.addressing.EntityFormatException;
+import org.apache.vysper.xmpp.addressing.EntityImpl;
+import org.apache.vysper.xmpp.authentication.AccountCreationException;
+import org.apache.vysper.xmpp.authentication.AccountManagement;
+import org.apache.vysper.xmpp.authentication.UserAuthentication;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.io.IOException;
+import java.security.MessageDigest;
+
+import static org.apache.vysper.storage.hbase.HBaseStorage.COLUMN_FAMILY_NAME_BASIC;
+import static org.apache.vysper.storage.hbase.HBaseUtils.entityAsBytes;
+
+/**
+ *
+ * @author The Apache MINA Project (dev@mina.apache.org)
+ */
+public class HBaseUserManagement implements UserAuthentication, AccountManagement {
+
+    final Logger logger = LoggerFactory.getLogger(HBaseUserManagement.class);
+
+    public static final byte[] PASSWORD_COLUMN = "pwd".getBytes();
+    
+    protected HBaseStorage hBaseStorage;
+
+    /**
+     * the salt before encrypting all passwords
+     * change once before creating the first account
+     */
+    private String encryptionSalt = "saltetForVysper";
+
+    /**
+     * the number of hashing rounds for encrypting all passwords
+     * change once before creating the first account
+     */
+    private int hashingRounds = 5;
+    
+    public HBaseUserManagement(HBaseStorage hBaseStorage) {
+        this.hBaseStorage = hBaseStorage;
+    }
+
+    public boolean verifyCredentials(Entity jid, String passwordCleartext, Object credentials) {
+        if (passwordCleartext == null)
+            return false;
+        try {
+            final Result entityRow = hBaseStorage.getEntityRow(jid, COLUMN_FAMILY_NAME_BASIC);
+            if (entityRow == null) return false;
+
+            final String encryptedGivenPassword = encryptPassword(passwordCleartext);
+            final byte[] passwordSavedBytes = entityRow.getValue(COLUMN_FAMILY_NAME_BASIC.getBytes(), PASSWORD_COLUMN);
+            return new String(passwordSavedBytes, "UTF-8").equals(encryptedGivenPassword);
+        } catch (Exception e) {
+            return false;
+        }
+    }
+
+    protected String encryptPassword(String passwordCleartext) {
+        if (passwordCleartext == null) passwordCleartext = "";
+        try {
+            passwordCleartext = passwordCleartext + encryptionSalt;
+            MessageDigest digest = MessageDigest.getInstance("SHA-256");
+
+            int rounds = Math.max(1, hashingRounds);
+            byte[] pwdBytes = passwordCleartext.getBytes("UTF-8");
+            for (int i = 0; i < rounds; i++) {
+                pwdBytes = digest.digest(pwdBytes);
+            }
+            return new String(pwdBytes, "UTF-8");
+        } catch (Exception e) {
+            throw new RuntimeException(e);
+        }
+    }
+
+    public boolean verifyCredentials(String username, String passwordCleartext, Object credentials) {
+        try {
+            return verifyCredentials(EntityImpl.parse(username), passwordCleartext, credentials);
+        } catch (EntityFormatException e) {
+            return false;
+        }
+    }
+
+    public boolean verifyAccountExists(Entity jid) {
+        final Result entityRow = hBaseStorage.getEntityRow(jid, COLUMN_FAMILY_NAME_BASIC);
+        return !entityRow.isEmpty();
+    }
+
+    public void addUser(Entity username, String password) throws AccountCreationException {
+        // if already existent, don't create, throw error
+        if (verifyAccountExists(username)) {
+            throw new AccountCreationException("account already exists: " + username.getFullQualifiedName());
+        }
+
+        // now, finally, create
+        try {
+            // row is created when first column for it is created.
+            setPasswordInHBase(username, password);
+            logger.info("account created in HBase for " + username);
+        } catch (Exception e) {
+            throw new AccountCreationException("failed to creating in HBase account " + username, e);
+        }
+
+    }
+
+    private void setPasswordInHBase(Entity username, String password) throws IOException {
+        final Put put = new Put(entityAsBytes(username));
+        put.add(COLUMN_FAMILY_NAME_BASIC.getBytes(), PASSWORD_COLUMN, encryptPassword(password).getBytes("UTF-8"));
+        hBaseStorage.getTable(HBaseStorage.TABLE_NAME_USER).put(put);
+    }
+
+    public void changePassword(Entity username, String password) throws AccountCreationException {
+        try {
+            setPasswordInHBase(username, password);
+            logger.info("password changed for " + username);
+        } catch (Exception e) {
+            throw new AccountCreationException("failed to change password for " + username, e);
+        }
+    }
+}


[4/9] git commit: fix HBase storage stuff

Posted by be...@apache.org.
fix HBase storage stuff


Project: http://git-wip-us.apache.org/repos/asf/mina-vysper/repo
Commit: http://git-wip-us.apache.org/repos/asf/mina-vysper/commit/9bbab821
Tree: http://git-wip-us.apache.org/repos/asf/mina-vysper/tree/9bbab821
Diff: http://git-wip-us.apache.org/repos/asf/mina-vysper/diff/9bbab821

Branch: refs/heads/master
Commit: 9bbab82127be14a53a28c1605b64168978eb7f82
Parents: 39f8518
Author: Bernd Fondermann <be...@brainlounge.de>
Authored: Fri Jul 5 23:12:40 2013 +0200
Committer: Bernd Fondermann <be...@brainlounge.de>
Committed: Fri Jul 5 23:12:40 2013 +0200

----------------------------------------------------------------------
 .../vysper/storage/hbase/roster/HBaseRosterManager.java  |  2 ++
 .../vysper/storage/hbase/user/HBaseUserManagement.java   | 11 ++++++-----
 2 files changed, 8 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mina-vysper/blob/9bbab821/server/storage/hbase/src/main/java/org/apache/vysper/storage/hbase/roster/HBaseRosterManager.java
----------------------------------------------------------------------
diff --git a/server/storage/hbase/src/main/java/org/apache/vysper/storage/hbase/roster/HBaseRosterManager.java b/server/storage/hbase/src/main/java/org/apache/vysper/storage/hbase/roster/HBaseRosterManager.java
index a7417d6..0396e2d 100644
--- a/server/storage/hbase/src/main/java/org/apache/vysper/storage/hbase/roster/HBaseRosterManager.java
+++ b/server/storage/hbase/src/main/java/org/apache/vysper/storage/hbase/roster/HBaseRosterManager.java
@@ -72,6 +72,8 @@ public class HBaseRosterManager extends AbstractRosterManager {
         MutableRoster roster = new MutableRoster();
 
         final NavigableMap<byte[],byte[]> contacts = entityRow.getFamilyMap(COLUMN_FAMILY_NAME_CONTACT_BYTES);
+        if (contacts == null) return roster;
+        
         for (byte[] contactBytes : contacts.keySet()) {
             String contactAsString = null;
             EntityImpl contactJID = null;

http://git-wip-us.apache.org/repos/asf/mina-vysper/blob/9bbab821/server/storage/hbase/src/main/java/org/apache/vysper/storage/hbase/user/HBaseUserManagement.java
----------------------------------------------------------------------
diff --git a/server/storage/hbase/src/main/java/org/apache/vysper/storage/hbase/user/HBaseUserManagement.java b/server/storage/hbase/src/main/java/org/apache/vysper/storage/hbase/user/HBaseUserManagement.java
index 72a2b0e..99d6995 100644
--- a/server/storage/hbase/src/main/java/org/apache/vysper/storage/hbase/user/HBaseUserManagement.java
+++ b/server/storage/hbase/src/main/java/org/apache/vysper/storage/hbase/user/HBaseUserManagement.java
@@ -33,6 +33,7 @@ import org.slf4j.LoggerFactory;
 
 import java.io.IOException;
 import java.security.MessageDigest;
+import java.util.Arrays;
 
 import static org.apache.vysper.storage.hbase.HBaseStorage.COLUMN_FAMILY_NAME_BASIC;
 import static org.apache.vysper.storage.hbase.HBaseUtils.entityAsBytes;
@@ -72,15 +73,15 @@ public class HBaseUserManagement implements UserAuthentication, AccountManagemen
             final Result entityRow = hBaseStorage.getEntityRow(jid, COLUMN_FAMILY_NAME_BASIC);
             if (entityRow == null) return false;
 
-            final String encryptedGivenPassword = encryptPassword(passwordCleartext);
+            final byte[] encryptedGivenPassword = encryptPassword(passwordCleartext);
             final byte[] passwordSavedBytes = entityRow.getValue(COLUMN_FAMILY_NAME_BASIC.getBytes(), PASSWORD_COLUMN);
-            return new String(passwordSavedBytes, "UTF-8").equals(encryptedGivenPassword);
+            return Arrays.equals(passwordSavedBytes, encryptedGivenPassword);
         } catch (Exception e) {
             return false;
         }
     }
 
-    protected String encryptPassword(String passwordCleartext) {
+    protected byte[] encryptPassword(String passwordCleartext) {
         if (passwordCleartext == null) passwordCleartext = "";
         try {
             passwordCleartext = passwordCleartext + encryptionSalt;
@@ -91,7 +92,7 @@ public class HBaseUserManagement implements UserAuthentication, AccountManagemen
             for (int i = 0; i < rounds; i++) {
                 pwdBytes = digest.digest(pwdBytes);
             }
-            return new String(pwdBytes, "UTF-8");
+            return pwdBytes;
         } catch (Exception e) {
             throw new RuntimeException(e);
         }
@@ -129,7 +130,7 @@ public class HBaseUserManagement implements UserAuthentication, AccountManagemen
 
     private void setPasswordInHBase(Entity username, String password) throws IOException {
         final Put put = new Put(entityAsBytes(username));
-        put.add(COLUMN_FAMILY_NAME_BASIC.getBytes(), PASSWORD_COLUMN, encryptPassword(password).getBytes("UTF-8"));
+        put.add(COLUMN_FAMILY_NAME_BASIC.getBytes(), PASSWORD_COLUMN, encryptPassword(password));
         hBaseStorage.getTable(HBaseStorage.TABLE_NAME_USER).put(put);
     }
 


[9/9] git commit: HBase storage: extract generic persistence manager for XEPs like vcard and private data, add vcard storage for HBase

Posted by be...@apache.org.
HBase storage: extract generic persistence manager for XEPs like vcard and private data, add vcard storage for HBase


Project: http://git-wip-us.apache.org/repos/asf/mina-vysper/repo
Commit: http://git-wip-us.apache.org/repos/asf/mina-vysper/commit/9ffe7f30
Tree: http://git-wip-us.apache.org/repos/asf/mina-vysper/tree/9ffe7f30
Diff: http://git-wip-us.apache.org/repos/asf/mina-vysper/diff/9ffe7f30

Branch: refs/heads/master
Commit: 9ffe7f302900bad22c52e90cb098f31c4f19b0ad
Parents: 1b50d19
Author: Bernd Fondermann <be...@brainlounge.de>
Authored: Mon Jul 8 11:40:57 2013 +0200
Committer: Bernd Fondermann <be...@brainlounge.de>
Committed: Mon Jul 8 11:40:57 2013 +0200

----------------------------------------------------------------------
 .../hbase/HBaseGenericXEPDataManager.java       | 76 ++++++++++++++++++++
 .../hbase/HBaseStorageProviderRegistry.java     |  2 +
 .../HBasePrivateDataPersistenceManager.java     | 59 ++-------------
 .../vcard/HBaseVcardTempPersistenceManager.java | 56 +++++++++++++++
 4 files changed, 140 insertions(+), 53 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mina-vysper/blob/9ffe7f30/server/storage/hbase/src/main/java/org/apache/vysper/storage/hbase/HBaseGenericXEPDataManager.java
----------------------------------------------------------------------
diff --git a/server/storage/hbase/src/main/java/org/apache/vysper/storage/hbase/HBaseGenericXEPDataManager.java b/server/storage/hbase/src/main/java/org/apache/vysper/storage/hbase/HBaseGenericXEPDataManager.java
new file mode 100644
index 0000000..54416a2
--- /dev/null
+++ b/server/storage/hbase/src/main/java/org/apache/vysper/storage/hbase/HBaseGenericXEPDataManager.java
@@ -0,0 +1,76 @@
+package org.apache.vysper.storage.hbase;
+
+import org.apache.commons.lang.StringUtils;
+import org.apache.hadoop.hbase.client.HTableInterface;
+import org.apache.hadoop.hbase.client.Put;
+import org.apache.hadoop.hbase.client.Result;
+import org.apache.vysper.xmpp.addressing.Entity;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.io.IOException;
+
+import static org.apache.vysper.storage.hbase.HBaseStorage.COLUMN_FAMILY_NAME_XEP;
+import static org.apache.vysper.storage.hbase.HBaseStorage.COLUMN_FAMILY_NAME_XEP_BYTES;
+import static org.apache.vysper.storage.hbase.HBaseStorage.TABLE_NAME_USER;
+import static org.apache.vysper.storage.hbase.HBaseUtils.asBytes;
+import static org.apache.vysper.storage.hbase.HBaseUtils.entityAsBytes;
+import static org.apache.vysper.storage.hbase.HBaseUtils.toStr;
+
+/**
+ */
+public abstract class HBaseGenericXEPDataManager {
+    final Logger logger = LoggerFactory.getLogger(HBaseGenericXEPDataManager.class);
+    
+    protected HBaseStorage hbaseStorage;
+
+    public HBaseGenericXEPDataManager(HBaseStorage hbaseStorage) {
+        this.hbaseStorage = hbaseStorage;
+    }
+
+    protected abstract String getNamespace();
+
+    protected String getColumnForKey(String key) {
+        return getNamespace() + "#"+ key;
+    }
+
+    public boolean isAvailable() {
+        HTableInterface table = null;
+        try {
+            table = hbaseStorage.getTable(TABLE_NAME_USER);
+            return table != null;
+        } finally {
+            hbaseStorage.putTable(table);
+        }
+    }
+
+    protected boolean setValue(Entity entity, String key, String xml) {
+        if (key == null || StringUtils.isBlank(key)) {
+            throw new IllegalArgumentException("key must not be blank, empty or null");
+        }
+        String column = getColumnForKey(key);
+
+        final Put put = new Put(entityAsBytes(entity.getBareJID()));
+        put.add(COLUMN_FAMILY_NAME_XEP_BYTES, asBytes(column), asBytes(xml));
+
+        HTableInterface table = null;
+        try {
+            table = hbaseStorage.getTable(TABLE_NAME_USER);
+            table.put(put);
+            logger.debug("stored private data for {} with key {}", entity, key);
+            return true;
+        } catch (IOException e) {
+            logger.warn("failed to save private data for {} with key {}", entity, key);
+            return false;
+        } finally {
+            hbaseStorage.putTable(table);
+        }
+    }
+
+    protected String getValue(Entity entity, String key) {
+        final Result entityRow = hbaseStorage.getEntityRow(entity, COLUMN_FAMILY_NAME_XEP);
+
+        String column = getColumnForKey(key);
+        return toStr(entityRow.getValue(COLUMN_FAMILY_NAME_XEP_BYTES, asBytes(column)));
+    }
+}

http://git-wip-us.apache.org/repos/asf/mina-vysper/blob/9ffe7f30/server/storage/hbase/src/main/java/org/apache/vysper/storage/hbase/HBaseStorageProviderRegistry.java
----------------------------------------------------------------------
diff --git a/server/storage/hbase/src/main/java/org/apache/vysper/storage/hbase/HBaseStorageProviderRegistry.java b/server/storage/hbase/src/main/java/org/apache/vysper/storage/hbase/HBaseStorageProviderRegistry.java
index 5b86ad4..509dc7a 100644
--- a/server/storage/hbase/src/main/java/org/apache/vysper/storage/hbase/HBaseStorageProviderRegistry.java
+++ b/server/storage/hbase/src/main/java/org/apache/vysper/storage/hbase/HBaseStorageProviderRegistry.java
@@ -23,6 +23,7 @@ import org.apache.vysper.storage.OpenStorageProviderRegistry;
 import org.apache.vysper.storage.hbase.privatedata.HBasePrivateDataPersistenceManager;
 import org.apache.vysper.storage.hbase.roster.HBaseRosterManager;
 import org.apache.vysper.storage.hbase.user.HBaseUserManagement;
+import org.apache.vysper.storage.hbase.vcard.HBaseVcardTempPersistenceManager;
 
 /**
  *
@@ -34,6 +35,7 @@ public class HBaseStorageProviderRegistry extends OpenStorageProviderRegistry {
         add(new HBaseUserManagement(HBaseStorage.getInstance()));
         add(new HBaseRosterManager(HBaseStorage.getInstance()));
         add(new HBasePrivateDataPersistenceManager(HBaseStorage.getInstance()));
+        add(new HBaseVcardTempPersistenceManager(HBaseStorage.getInstance()));
     }
 
 }

http://git-wip-us.apache.org/repos/asf/mina-vysper/blob/9ffe7f30/server/storage/hbase/src/main/java/org/apache/vysper/storage/hbase/privatedata/HBasePrivateDataPersistenceManager.java
----------------------------------------------------------------------
diff --git a/server/storage/hbase/src/main/java/org/apache/vysper/storage/hbase/privatedata/HBasePrivateDataPersistenceManager.java b/server/storage/hbase/src/main/java/org/apache/vysper/storage/hbase/privatedata/HBasePrivateDataPersistenceManager.java
index 4024b59..322bb77 100644
--- a/server/storage/hbase/src/main/java/org/apache/vysper/storage/hbase/privatedata/HBasePrivateDataPersistenceManager.java
+++ b/server/storage/hbase/src/main/java/org/apache/vysper/storage/hbase/privatedata/HBasePrivateDataPersistenceManager.java
@@ -19,10 +19,7 @@
  */
 package org.apache.vysper.storage.hbase.privatedata;
 
-import org.apache.commons.lang.StringUtils;
-import org.apache.hadoop.hbase.client.HTableInterface;
-import org.apache.hadoop.hbase.client.Put;
-import org.apache.hadoop.hbase.client.Result;
+import org.apache.vysper.storage.hbase.HBaseGenericXEPDataManager;
 import org.apache.vysper.storage.hbase.HBaseStorage;
 import org.apache.vysper.xmpp.addressing.Entity;
 import org.apache.vysper.xmpp.modules.extension.xep0049_privatedata.PrivateDataPersistenceManager;
@@ -30,73 +27,29 @@ import org.apache.vysper.xmpp.protocol.NamespaceURIs;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-import java.io.IOException;
-
-import static org.apache.vysper.storage.hbase.HBaseStorage.*;
-import static org.apache.vysper.storage.hbase.HBaseUtils.*;
-
 /**
  * @author The Apache MINA Project (dev@mina.apache.org)
  */
-public class HBasePrivateDataPersistenceManager implements PrivateDataPersistenceManager {
+public class HBasePrivateDataPersistenceManager extends HBaseGenericXEPDataManager implements PrivateDataPersistenceManager {
 
     final Logger logger = LoggerFactory.getLogger(HBasePrivateDataPersistenceManager.class);
 
-    protected HBaseStorage hbaseStorage;
-
     public HBasePrivateDataPersistenceManager(HBaseStorage hbaseStorage) {
-        this.hbaseStorage = hbaseStorage;
+        super(hbaseStorage);
     }
 
+    @Override
     protected String getNamespace() {
         return NamespaceURIs.PRIVATE_DATA;
     }
-    
-    public boolean isAvailable() {
-        HTableInterface table = null;
-        try {
-            table = hbaseStorage.getTable(TABLE_NAME_USER);
-            return table != null;
-        } finally {
-            hbaseStorage.putTable(table);
-        }
-    }
 
     public String getPrivateData(Entity entity, String key) {
-        final Result entityRow = hbaseStorage.getEntityRow(entity, COLUMN_FAMILY_NAME_XEP);
-
-        String column = getColumnForKey(key);
-        String value = toStr(entityRow.getValue(COLUMN_FAMILY_NAME_XEP_BYTES, asBytes(column)));
-        
+        String value = getValue(entity, key);
         return value;
     }
 
-    protected String getColumnForKey(String key) {
-        return getNamespace() + "#"+ key;
-    }
-
     public boolean setPrivateData(Entity entity, String key, String xml) {
-
-        if (key == null || StringUtils.isBlank(key)) {
-            throw new IllegalArgumentException("private data key must not be blank");
-        }
-        String column = getColumnForKey(key);
-        
-        final Put put = new Put(entityAsBytes(entity.getBareJID()));
-        put.add(COLUMN_FAMILY_NAME_XEP_BYTES, asBytes(column), asBytes(xml));
-
-        HTableInterface table = null;
-        try {
-            table = hbaseStorage.getTable(TABLE_NAME_USER);
-            table.put(put);
-            logger.debug("stored private data for {} with key {}", entity, key);
-            return true;
-        } catch (IOException e) {
-            logger.warn("failed to save private data for {} with key {}", entity, key);
-            return false;
-        } finally {
-            hbaseStorage.putTable(table);
-        }
+        return setValue(entity, key, xml);
     }
 
 }

http://git-wip-us.apache.org/repos/asf/mina-vysper/blob/9ffe7f30/server/storage/hbase/src/main/java/org/apache/vysper/storage/hbase/vcard/HBaseVcardTempPersistenceManager.java
----------------------------------------------------------------------
diff --git a/server/storage/hbase/src/main/java/org/apache/vysper/storage/hbase/vcard/HBaseVcardTempPersistenceManager.java b/server/storage/hbase/src/main/java/org/apache/vysper/storage/hbase/vcard/HBaseVcardTempPersistenceManager.java
new file mode 100644
index 0000000..550f8af
--- /dev/null
+++ b/server/storage/hbase/src/main/java/org/apache/vysper/storage/hbase/vcard/HBaseVcardTempPersistenceManager.java
@@ -0,0 +1,56 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ *
+ */
+package org.apache.vysper.storage.hbase.vcard;
+
+import org.apache.vysper.storage.hbase.HBaseGenericXEPDataManager;
+import org.apache.vysper.storage.hbase.HBaseStorage;
+import org.apache.vysper.xmpp.addressing.Entity;
+import org.apache.vysper.xmpp.modules.extension.xep0054_vcardtemp.VcardTempPersistenceManager;
+import org.apache.vysper.xmpp.protocol.NamespaceURIs;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ *
+ * @author The Apache MINA Project (dev@mina.apache.org)
+ */
+public class HBaseVcardTempPersistenceManager extends HBaseGenericXEPDataManager implements VcardTempPersistenceManager {
+
+    final Logger logger = LoggerFactory.getLogger(HBaseVcardTempPersistenceManager.class);
+    
+    private static final String KEY = "vcard";
+
+    public HBaseVcardTempPersistenceManager(HBaseStorage hbaseStorage) {
+        super(hbaseStorage);
+    }
+
+    @Override
+    protected String getNamespace() {
+        return NamespaceURIs.VCARD_TEMP;
+    }
+
+    public String getVcard(Entity entity) {
+        return getValue(entity, KEY);
+    }
+
+    public boolean setVcard(Entity entity, String xml) {
+        return setValue(entity, KEY, xml);
+    }
+}


[3/9] git commit: add HBase storage to distribution

Posted by be...@apache.org.
add HBase storage to distribution


Project: http://git-wip-us.apache.org/repos/asf/mina-vysper/repo
Commit: http://git-wip-us.apache.org/repos/asf/mina-vysper/commit/39f8518d
Tree: http://git-wip-us.apache.org/repos/asf/mina-vysper/tree/39f8518d
Diff: http://git-wip-us.apache.org/repos/asf/mina-vysper/diff/39f8518d

Branch: refs/heads/master
Commit: 39f8518d35db76fd903117d42ba03d995429f2cf
Parents: 843a6d6
Author: Bernd Fondermann <be...@brainlounge.de>
Authored: Fri Jul 5 23:12:14 2013 +0200
Committer: Bernd Fondermann <be...@brainlounge.de>
Committed: Fri Jul 5 23:12:14 2013 +0200

----------------------------------------------------------------------
 dist/pom.xml |  5 +++++
 pom.xml      | 15 +++++++++++++--
 2 files changed, 18 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mina-vysper/blob/39f8518d/dist/pom.xml
----------------------------------------------------------------------
diff --git a/dist/pom.xml b/dist/pom.xml
index 8cf334c..558ee71 100644
--- a/dist/pom.xml
+++ b/dist/pom.xml
@@ -77,6 +77,11 @@
     </dependency>
 
     <dependency>
+      <groupId>org.apache.vysper.storage</groupId>
+      <artifactId>vysper-hbase</artifactId>
+    </dependency>
+        
+    <dependency>
       <groupId>commons-codec</groupId>
       <artifactId>commons-codec</artifactId>
     </dependency>

http://git-wip-us.apache.org/repos/asf/mina-vysper/blob/39f8518d/pom.xml
----------------------------------------------------------------------
diff --git a/pom.xml b/pom.xml
index 0343a6f..1b8745b 100644
--- a/pom.xml
+++ b/pom.xml
@@ -206,11 +206,22 @@
       </dependency>
 
       <dependency>
-        <groupId>org.apache.vysper</groupId>
-        <artifactId>vysper-admin-console</artifactId>
+        <groupId>org.apache.vysper.storage</groupId>
+        <artifactId>vysper-jcr</artifactId>
+        <version>${project.version}</version>
+      </dependency>
+
+      <dependency>
+        <groupId>org.apache.vysper.storage</groupId>
+        <artifactId>vysper-hbase</artifactId>
         <version>${project.version}</version>
       </dependency>
 
+      <dependency>
+        <groupId>org.apache.vysper.extensions</groupId>
+        <artifactId>vysper-websockets</artifactId>
+        <version>${project.version}</version>
+      </dependency>
 
       <dependency>
         <groupId>org.eclipse.jetty</groupId>


[6/9] git commit: fix roster + contact storage in HBase

Posted by be...@apache.org.
fix roster + contact storage in HBase


Project: http://git-wip-us.apache.org/repos/asf/mina-vysper/repo
Commit: http://git-wip-us.apache.org/repos/asf/mina-vysper/commit/472093ca
Tree: http://git-wip-us.apache.org/repos/asf/mina-vysper/tree/472093ca
Diff: http://git-wip-us.apache.org/repos/asf/mina-vysper/diff/472093ca

Branch: refs/heads/master
Commit: 472093ca36fa5df88a64c100e69cc7c44a31e7f1
Parents: 0636dc9
Author: Bernd Fondermann <be...@brainlounge.de>
Authored: Mon Jul 8 10:28:10 2013 +0200
Committer: Bernd Fondermann <be...@brainlounge.de>
Committed: Mon Jul 8 10:28:10 2013 +0200

----------------------------------------------------------------------
 .../storage/hbase/HBaseStorageProviderRegistry.java |  2 ++
 .../storage/hbase/roster/HBaseRosterManager.java    | 16 ++++++++++------
 .../storage/hbase/user/HBaseUserManagement.java     |  9 ++++++++-
 3 files changed, 20 insertions(+), 7 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mina-vysper/blob/472093ca/server/storage/hbase/src/main/java/org/apache/vysper/storage/hbase/HBaseStorageProviderRegistry.java
----------------------------------------------------------------------
diff --git a/server/storage/hbase/src/main/java/org/apache/vysper/storage/hbase/HBaseStorageProviderRegistry.java b/server/storage/hbase/src/main/java/org/apache/vysper/storage/hbase/HBaseStorageProviderRegistry.java
index 32ad50a..5b86ad4 100644
--- a/server/storage/hbase/src/main/java/org/apache/vysper/storage/hbase/HBaseStorageProviderRegistry.java
+++ b/server/storage/hbase/src/main/java/org/apache/vysper/storage/hbase/HBaseStorageProviderRegistry.java
@@ -20,6 +20,7 @@
 package org.apache.vysper.storage.hbase;
 
 import org.apache.vysper.storage.OpenStorageProviderRegistry;
+import org.apache.vysper.storage.hbase.privatedata.HBasePrivateDataPersistenceManager;
 import org.apache.vysper.storage.hbase.roster.HBaseRosterManager;
 import org.apache.vysper.storage.hbase.user.HBaseUserManagement;
 
@@ -32,6 +33,7 @@ public class HBaseStorageProviderRegistry extends OpenStorageProviderRegistry {
     public HBaseStorageProviderRegistry() throws HBaseStorageException {
         add(new HBaseUserManagement(HBaseStorage.getInstance()));
         add(new HBaseRosterManager(HBaseStorage.getInstance()));
+        add(new HBasePrivateDataPersistenceManager(HBaseStorage.getInstance()));
     }
 
 }

http://git-wip-us.apache.org/repos/asf/mina-vysper/blob/472093ca/server/storage/hbase/src/main/java/org/apache/vysper/storage/hbase/roster/HBaseRosterManager.java
----------------------------------------------------------------------
diff --git a/server/storage/hbase/src/main/java/org/apache/vysper/storage/hbase/roster/HBaseRosterManager.java b/server/storage/hbase/src/main/java/org/apache/vysper/storage/hbase/roster/HBaseRosterManager.java
index 0ec3e21..d61ab87 100644
--- a/server/storage/hbase/src/main/java/org/apache/vysper/storage/hbase/roster/HBaseRosterManager.java
+++ b/server/storage/hbase/src/main/java/org/apache/vysper/storage/hbase/roster/HBaseRosterManager.java
@@ -19,6 +19,7 @@
  */
 package org.apache.vysper.storage.hbase.roster;
 
+import org.apache.commons.lang.StringUtils;
 import org.apache.hadoop.hbase.client.Delete;
 import org.apache.hadoop.hbase.client.HTableInterface;
 import org.apache.hadoop.hbase.client.Put;
@@ -99,11 +100,12 @@ public class HBaseRosterManager extends AbstractRosterManager {
 
             AskSubscriptionType askSubscriptionType = AskSubscriptionType.NOT_SET;
             try {
-                if (askTypeString != null)
+                if (StringUtils.isNotBlank(askTypeString)) {
                     askSubscriptionType = AskSubscriptionType.valueOf(askTypeString);
+                }
             } catch (IllegalArgumentException e) {
                 LOG.warn("when loading roster for user " + bareJid.getFullQualifiedName() + ", contact "
-                        + contactJID.getFullQualifiedName() + ", the ask subscription type is unparsable. skipping!");
+                        + contactJID.getFullQualifiedName() + ", the ask subscription type '" + askTypeString + "' is unparsable. skipping!");
                 continue; // don't return it, don't set a default!
             }
 
@@ -144,8 +146,8 @@ public class HBaseRosterManager extends AbstractRosterManager {
         final Put put = new Put(entityAsBytes(jid.getBareJID()));
         put.add(COLUMN_FAMILY_NAME_CONTACT_BYTES, asBytes(contactIdentifier), asBytes(rosterItem.getSubscriptionType().value()));
         put.add(COLUMN_FAMILY_NAME_ROSTER_BYTES, asBytes(COLUMN_PREFIX_NAME + contactIdentifier), asBytes(rosterItem.getName()));
-        put.add(COLUMN_FAMILY_NAME_ROSTER_BYTES, asBytes(COLUMN_PREFIX_TYPE + contactIdentifier), asBytes(rosterItem.getSubscriptionType().value()));
-        put.add(COLUMN_FAMILY_NAME_ROSTER_BYTES, asBytes(COLUMN_PREFIX_ASKTYPE + contactIdentifier), asBytes(rosterItem.getAskSubscriptionType().value()));
+        put.add(COLUMN_FAMILY_NAME_ROSTER_BYTES, asBytes(COLUMN_PREFIX_TYPE + contactIdentifier), asBytes(rosterItem.getSubscriptionType().name()));
+        put.add(COLUMN_FAMILY_NAME_ROSTER_BYTES, asBytes(COLUMN_PREFIX_ASKTYPE + contactIdentifier), asBytes(rosterItem.getAskSubscriptionType().name()));
         int i = 1;
         for (RosterGroup rosterGroup : rosterItem.getGroups()) {
             String columnName = COLUMN_PREFIX_GROUP + i + ":" + contactIdentifier; 
@@ -153,8 +155,9 @@ public class HBaseRosterManager extends AbstractRosterManager {
             i++;
         }
 
-        final HTableInterface userTable = hBaseStorage.getTable(TABLE_NAME_USER);
+        HTableInterface userTable = null;
         try {
+            userTable = hBaseStorage.getTable(TABLE_NAME_USER);
             userTable.put(put);
             LOG.info("contact {} saved to HBase for user {}", rosterItem.getJid(), jid);
         } catch (IOException e) {
@@ -179,8 +182,9 @@ public class HBaseRosterManager extends AbstractRosterManager {
         delete.deleteColumns(COLUMN_FAMILY_NAME_ROSTER_BYTES, asBytes(COLUMN_PREFIX_TYPE + contactIdentifier));
         delete.deleteColumns(COLUMN_FAMILY_NAME_ROSTER_BYTES, asBytes(COLUMN_PREFIX_ASKTYPE + contactIdentifier));
         
-        final HTableInterface userTable = hBaseStorage.getTable(TABLE_NAME_USER);
+        HTableInterface userTable = null;
         try {
+            userTable = hBaseStorage.getTable(TABLE_NAME_USER);
             userTable.delete(delete);
             LOG.info("contact {} removed from HBase for user {}", jidContact, jidUser);
         } catch (IOException e) {

http://git-wip-us.apache.org/repos/asf/mina-vysper/blob/472093ca/server/storage/hbase/src/main/java/org/apache/vysper/storage/hbase/user/HBaseUserManagement.java
----------------------------------------------------------------------
diff --git a/server/storage/hbase/src/main/java/org/apache/vysper/storage/hbase/user/HBaseUserManagement.java b/server/storage/hbase/src/main/java/org/apache/vysper/storage/hbase/user/HBaseUserManagement.java
index 99d6995..e98c019 100644
--- a/server/storage/hbase/src/main/java/org/apache/vysper/storage/hbase/user/HBaseUserManagement.java
+++ b/server/storage/hbase/src/main/java/org/apache/vysper/storage/hbase/user/HBaseUserManagement.java
@@ -19,6 +19,7 @@
  */
 package org.apache.vysper.storage.hbase.user;
 
+import org.apache.hadoop.hbase.client.HTableInterface;
 import org.apache.hadoop.hbase.client.Put;
 import org.apache.hadoop.hbase.client.Result;
 import org.apache.vysper.storage.hbase.HBaseStorage;
@@ -131,7 +132,13 @@ public class HBaseUserManagement implements UserAuthentication, AccountManagemen
     private void setPasswordInHBase(Entity username, String password) throws IOException {
         final Put put = new Put(entityAsBytes(username));
         put.add(COLUMN_FAMILY_NAME_BASIC.getBytes(), PASSWORD_COLUMN, encryptPassword(password));
-        hBaseStorage.getTable(HBaseStorage.TABLE_NAME_USER).put(put);
+        HTableInterface table = null;
+        try {
+            table = hBaseStorage.getTable(HBaseStorage.TABLE_NAME_USER);
+            table.put(put);
+        } finally {
+            hBaseStorage.putTable(table);
+        }
     }
 
     public void changePassword(Entity username, String password) throws AccountCreationException {