[kune-commits] r1823 - in openfireauth: . src/main/java/cc/kune/core/server/auth/openfire src/test/java/cc/kune/core/server/auth/openfire

Vicente J. Ruiz Jurado vjrj_ at ourproject.org
Tue Apr 3 02:35:12 CEST 2012


Author: vjrj_
Date: 2012-04-03 02:35:11 +0200 (Tue, 03 Apr 2012)
New Revision: 1823

Modified:
   openfireauth/.classpath
   openfireauth/pom.xml
   openfireauth/src/main/java/cc/kune/core/server/auth/openfire/KuneAuthProvider.java
   openfireauth/src/test/java/cc/kune/core/server/auth/openfire/KuneAuthProviderTest.java
Log:
Openfire AuthProvider now use RPC

Modified: openfireauth/.classpath
===================================================================
--- openfireauth/.classpath	2012-04-03 00:06:45 UTC (rev 1822)
+++ openfireauth/.classpath	2012-04-03 00:35:11 UTC (rev 1823)
@@ -5,17 +5,14 @@
   <classpathentry kind="src" path="src/test/resources" output="target/test-classes" excluding="**/*.java"/>
   <classpathentry kind="output" path="target/classes"/>
   <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
-  <classpathentry kind="var" path="M2_REPO/com/google/guava/guava/r09/guava-r09.jar" sourcepath="M2_REPO/com/google/guava/guava/r09/guava-r09-sources.jar"/>
-  <classpathentry kind="var" path="M2_REPO/com/google/protobuf/protobuf-java/2.3.0/protobuf-java-2.3.0.jar"/>
+  <classpathentry kind="var" path="M2_REPO/cc/kune/kune/0.1.0-SNAPSHOT/kune-0.1.0-SNAPSHOT.jar"/>
+  <classpathentry kind="var" path="M2_REPO/com/google/gwt/gwt-user/2.1.1/gwt-user-2.1.1.jar" sourcepath="M2_REPO/com/google/gwt/gwt-user/2.1.1/gwt-user-2.1.1-sources.jar"/>
+  <classpathentry kind="var" path="M2_REPO/com/googlecode/gwtrpccommlayer/0.0.1-SNAPSHOT/gwtrpccommlayer-0.0.1-SNAPSHOT.jar"/>
   <classpathentry kind="var" path="M2_REPO/junit/junit/4.9/junit-4.9.jar" sourcepath="M2_REPO/junit/junit/4.9/junit-4.9-sources.jar"/>
   <classpathentry kind="var" path="M2_REPO/org/hamcrest/hamcrest-core/1.1/hamcrest-core-1.1.jar" sourcepath="M2_REPO/org/hamcrest/hamcrest-core/1.1/hamcrest-core-1.1-sources.jar"/>
+  <classpathentry kind="var" path="M2_REPO/org/apache/httpcomponents/httpclient/4.0.1/httpclient-4.0.1.jar"/>
+  <classpathentry kind="var" path="M2_REPO/org/apache/httpcomponents/httpcore/4.0.1/httpcore-4.0.1.jar"/>
+  <classpathentry kind="var" path="M2_REPO/commons-logging/commons-logging/1.1.1/commons-logging-1.1.1.jar"/>
+  <classpathentry kind="var" path="M2_REPO/commons-codec/commons-codec/1.3/commons-codec-1.3.jar" sourcepath="M2_REPO/commons-codec/commons-codec/1.3/commons-codec-1.3-sources.jar"/>
   <classpathentry kind="var" path="M2_REPO/org/igniterealtime/openfire/3.7.0/openfire-3.7.0.jar"/>
-  <classpathentry kind="var" path="M2_REPO/org/waveprotocol/box/0.3.13/box-0.3.13.jar"/>
-  <classpathentry kind="var" path="M2_REPO/org/waveprotocol/box-src/0.3.13/box-src-0.3.13.jar" sourcepath="M2_REPO/org/waveprotocol/box-src/0.3.13/box-src-0.3.13-sources.jar"/>
-  <classpathentry kind="var" path="M2_REPO/org/waveprotocol/model/0.3.13/model-0.3.13.jar"/>
-  <classpathentry kind="var" path="M2_REPO/org/waveprotocol/model-src/0.3.13/model-src-0.3.13.jar" sourcepath="M2_REPO/org/waveprotocol/model-src/0.3.13/model-src-0.3.13-sources.jar"/>
-  <classpathentry kind="var" path="M2_REPO/org/waveprotocol/proto/0.3.13/proto-0.3.13.jar"/>
-  <classpathentry kind="var" path="M2_REPO/org/waveprotocol/proto-src/0.3.13/proto-src-0.3.13.jar"/>
-  <classpathentry kind="var" path="M2_REPO/org/waveprotocol/util/0.3.13/util-0.3.13.jar"/>
-  <classpathentry kind="var" path="M2_REPO/org/waveprotocol/util-src/0.3.13/util-src-0.3.13.jar" sourcepath="M2_REPO/org/waveprotocol/util-src/0.3.13/util-src-0.3.13-sources.jar"/>
 </classpath>
\ No newline at end of file

Modified: openfireauth/pom.xml
===================================================================
--- openfireauth/pom.xml	2012-04-03 00:06:45 UTC (rev 1822)
+++ openfireauth/pom.xml	2012-04-03 00:35:11 UTC (rev 1823)
@@ -3,7 +3,7 @@
   <modelVersion>4.0.0</modelVersion>
   <groupId>cc.kune</groupId>
   <artifactId>kune-openfireauth</artifactId>
-  <version>0.0.1-SNAPSHOT</version>
+  <version>0.0.2-SNAPSHOT</version>
   <name>Kune Openfire Auth Lib</name>
   <description>The jar generated, can be installed in /lib/ directory and allow to auth openfire users throw kune session tokens (see HybridAuthProvider)</description>
   <properties>
@@ -11,6 +11,7 @@
     <maven.compiler.target>1.6</maven.compiler.target>
     <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
     <wiab.version>0.3.13</wiab.version>
+    <gwt.version>2.1.1</gwt.version>
   </properties>
   <repositories>
     <repository>
@@ -20,66 +21,42 @@
   </repositories>
   <dependencies>
     <dependency>
-      <groupId>com.google.guava</groupId>
-      <artifactId>guava</artifactId>
-      <version>r09</version>
-    </dependency>
-    <dependency>
-      <groupId>com.google.protobuf</groupId>
-      <artifactId>protobuf-java</artifactId>
-      <version>2.3.0</version>
-    </dependency>
-    <dependency>
-      <groupId>org.waveprotocol</groupId>
-      <artifactId>model</artifactId>
-      <version>${wiab.version}</version>
-    </dependency>
-    <dependency>
-      <groupId>org.waveprotocol</groupId>
-      <artifactId>model-src</artifactId>
-      <version>${wiab.version}</version>
-    </dependency>
-    <dependency>
-      <groupId>org.waveprotocol</groupId>
-      <artifactId>box</artifactId>
-      <version>${wiab.version}</version>
-    </dependency>
-    <dependency>
-      <groupId>org.waveprotocol</groupId>
-      <artifactId>box-src</artifactId>
-      <version>${wiab.version}</version>
-    </dependency>
-    <dependency>
       <groupId>org.igniterealtime</groupId>
       <artifactId>openfire</artifactId>
       <version>3.7.0</version>
     </dependency>
     <dependency>
-      <groupId>org.waveprotocol</groupId>
-      <artifactId>proto</artifactId>
-      <version>${wiab.version}</version>
-    </dependency>
-    <dependency>
-      <groupId>org.waveprotocol</groupId>
-      <artifactId>proto-src</artifactId>
-      <version>${wiab.version}</version>
-    </dependency>
-    <dependency>
       <groupId>junit</groupId>
       <artifactId>junit</artifactId>
       <version>4.9</version>
       <scope>test</scope>
     </dependency>
     <dependency>
-      <groupId>org.waveprotocol</groupId>
-      <artifactId>util</artifactId>
-      <version>${wiab.version}</version>
+      <groupId>com.googlecode</groupId>
+      <artifactId>gwtrpccommlayer</artifactId>
+      <version>0.0.1-SNAPSHOT</version>
     </dependency>
     <dependency>
-      <groupId>org.waveprotocol</groupId>
-      <artifactId>util-src</artifactId>
-      <version>${wiab.version}</version>
+      <groupId>cc.kune</groupId>
+      <artifactId>kune</artifactId>
+      <version>0.1.0-SNAPSHOT</version>
     </dependency>
+    <dependency>
+      <groupId>com.google.gwt</groupId>
+      <artifactId>gwt-user</artifactId>
+      <version>${gwt.version}</version>
+      <scope>provided</scope>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.httpcomponents</groupId>
+      <artifactId>httpclient</artifactId>
+      <version>4.0.1</version>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.httpcomponents</groupId>
+      <artifactId>httpcore</artifactId>
+      <version>4.0.1</version>
+    </dependency>
   </dependencies>
   <build>
     <plugins>
@@ -105,4 +82,4 @@
       </plugin>
     </plugins>
   </build>
-</project>
\ No newline at end of file
+</project>

Modified: openfireauth/src/main/java/cc/kune/core/server/auth/openfire/KuneAuthProvider.java
===================================================================
--- openfireauth/src/main/java/cc/kune/core/server/auth/openfire/KuneAuthProvider.java	2012-04-03 00:06:45 UTC (rev 1822)
+++ openfireauth/src/main/java/cc/kune/core/server/auth/openfire/KuneAuthProvider.java	2012-04-03 00:35:11 UTC (rev 1823)
@@ -1,12 +1,7 @@
 package cc.kune.core.server.auth.openfire;
 
-import java.io.DataInputStream;
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.ObjectInputStream;
-import java.util.Properties;
+import java.net.MalformedURLException;
+import java.net.URL;
 
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
@@ -15,137 +10,34 @@
 import org.jivesoftware.openfire.auth.InternalUnauthenticatedException;
 import org.jivesoftware.openfire.auth.UnauthorizedException;
 import org.jivesoftware.openfire.user.UserNotFoundException;
-import org.waveprotocol.box.server.CoreSettings;
-import org.waveprotocol.box.server.account.AccountData;
-import org.waveprotocol.box.server.persistence.PersistenceException;
-import org.waveprotocol.box.server.persistence.file.FileAccountStore;
-import org.waveprotocol.wave.model.wave.ParticipantId;
 
-public class KuneAuthProvider implements AuthProvider {
+import cc.kune.core.client.rpcservices.UserService;
 
-  protected class ClassLoadingObjectInputStream extends ObjectInputStream {
+import com.googlecode.gwtrpccommlayer.client.impl.GwtRpcCommLayerClient;
 
-    /**
-     * Code copied from HashSessionManager
-     * 
-     * @throws IOException
-     */
-    public ClassLoadingObjectInputStream() throws IOException {
-      super();
-    }
+public class KuneAuthProvider implements AuthProvider {
 
-    public ClassLoadingObjectInputStream(final java.io.InputStream in) throws IOException {
-      super(in);
-    }
-
-    @Override
-    public Class<?> resolveClass(final java.io.ObjectStreamClass cl) throws IOException,
-        ClassNotFoundException {
-      try {
-        return Class.forName(cl.getName(), false, Thread.currentThread().getContextClassLoader());
-      } catch (final ClassNotFoundException e) {
-        return super.resolveClass(cl);
-      }
-    }
-  }
-
-  private static final String INCORRECT_USERNAME = "Incorrect username";
   public static final Log LOG = LogFactory.getLog(KuneAuthProvider.class);
   private static final String USER_NOT_LOGGED = "User not logged";
-  private final FileAccountStore accountStore;
-  private final Properties prop;
+  private final UserService userService;
 
-  public KuneAuthProvider() {
-    prop = new Properties();
-    try {
-      final InputStream is = this.getClass().getClassLoader().getResourceAsStream(
-          "wave-server.properties");
+  public KuneAuthProvider() throws MalformedURLException, ClassNotFoundException,
+      IllegalAccessException, InstantiationException {
 
-      // final String location =
-      // getClass().getProtectionDomain().getCodeSource().getLocation().toString();
-      // LOG.info("Location: " + location);
-      // final String path = location.substring(5);
-      // final FileInputStream fis = new FileInputStream(new File(path +
-      // "wave-server.properties"));
-      prop.load(is);
-    } catch (final IOException e) {
-      LOG.error("Error openning property files", e);
-    }
-    final String acStoreLocation = getProp(CoreSettings.ACCOUNT_STORE_DIRECTORY);
-    LOG.warn("Account store location: " + acStoreLocation);
-    accountStore = new FileAccountStore(acStoreLocation);
+    // http://googlewebtoolkit.blogspot.com.es/2010/07/gwtrpccommlayer-extending-gwt-rpc-to-do.html
+
+    final URL url = new URL("http://127.0.0.1:8888/ws/UserService");
+    final GwtRpcCommLayerClient client = new GwtRpcCommLayerClient(url);
+    userService = client.createRemoteServicePojoProxy(UserService.class);
   }
 
   @Override
-  @SuppressWarnings("unused")
   public void authenticate(final String username, final String passwdOrToken)
-      throws UnauthorizedException, ConnectionException, InternalUnauthenticatedException {
+      throws UnauthorizedException {
     try {
-      final String accountName = username + ParticipantId.DOMAIN_PREFIX
-          + getProp(CoreSettings.WAVE_SERVER_DOMAIN);
-      // LOG.warn("Trying to check account " + accountName);
-      final AccountData account = accountStore.getAccount(ParticipantId.ofUnsafe(accountName));
-      if (account.asHuman().getPasswordDigest().verify(passwdOrToken.toCharArray())) {
-        // Great ... authenticated
-      } else {
-        boolean logged = false;
-        final String sessionName = getProp(CoreSettings.SESSIONS_STORE_DIRECTORY) + File.separator
-            + passwdOrToken;
-        // LOG.warn("Session name: " + sessionName);
-        try {
-          final File session = new File(sessionName);
-          if (session.exists()) {
-            final FileInputStream is = new FileInputStream(session);
-            final DataInputStream in = new DataInputStream(is);
-
-            final String clusterId = in.readUTF();
-            in.readUTF(); // nodeId
-            final long created = in.readLong();
-            final long accessed = in.readLong();
-            final int requests = in.readInt();
-
-            final int size = in.readInt();
-            if (size > 0) {
-              final ClassLoadingObjectInputStream ois = new ClassLoadingObjectInputStream(in);
-              for (int i = 0; i < size; i++) {
-                try {
-                  final String key = ois.readUTF();
-                  final Object value = ois.readObject();
-                  if (value instanceof ParticipantId) {
-                    if (((ParticipantId) value).getAddress().startsWith(username + "@")) {
-                      // LOG.warn("Participation id found in session");
-                      logged = true;
-                      break;
-                    }
-                  }
-                } catch (final ClassNotFoundException e) {
-                } catch (final IOException e) {
-                  LOG.warn("Persisted in kune session unexpected object: " + e.getMessage());
-                }
-              }
-              ois.close();
-            }
-            in.close();
-            is.close();
-            if (!logged) {
-              // LOG.warn("Participation id not found in session");
-              throw new UnauthorizedException(INCORRECT_USERNAME);
-            } else {
-              // LOG.warn("Participation id found in session");
-              // Great ... authenticated
-            }
-          } else {
-            // LOG.warn("Session file doesn't exists");
-            throw new UnauthorizedException(USER_NOT_LOGGED);
-          }
-        } catch (final IOException e) {
-          LOG.warn("File session io error", e);
-          throw new UnauthorizedException(USER_NOT_LOGGED, e);
-        }
-      }
-    } catch (final PersistenceException e) {
-      LOG.warn("File session persistence error");
-      throw new UnauthorizedException(INCORRECT_USERNAME, e);
+      userService.checkUserAndHash(username, passwdOrToken);
+    } catch (final Exception e) {
+      throw new UnauthorizedException(USER_NOT_LOGGED, e);
     }
   }
 
@@ -161,10 +53,6 @@
     throw new UnsupportedOperationException();
   }
 
-  private String getProp(final String key) {
-    return (String) prop.get(key);
-  }
-
   @Override
   public boolean isDigestSupported() {
     return false;

Modified: openfireauth/src/test/java/cc/kune/core/server/auth/openfire/KuneAuthProviderTest.java
===================================================================
--- openfireauth/src/test/java/cc/kune/core/server/auth/openfire/KuneAuthProviderTest.java	2012-04-03 00:06:45 UTC (rev 1822)
+++ openfireauth/src/test/java/cc/kune/core/server/auth/openfire/KuneAuthProviderTest.java	2012-04-03 00:35:11 UTC (rev 1823)
@@ -1,5 +1,7 @@
 package cc.kune.core.server.auth.openfire;
 
+import java.net.MalformedURLException;
+
 import org.jivesoftware.openfire.auth.ConnectionException;
 import org.jivesoftware.openfire.auth.InternalUnauthenticatedException;
 import org.jivesoftware.openfire.auth.UnauthorizedException;
@@ -9,32 +11,38 @@
 
   @Test
   public void maintest() throws UnauthorizedException, ConnectionException,
-      InternalUnauthenticatedException {
+      InternalUnauthenticatedException, MalformedURLException, ClassNotFoundException,
+      IllegalAccessException, InstantiationException {
     final KuneAuthProvider auth = new KuneAuthProvider();
     auth.authenticate("admin", "easyeasy");
-    auth.authenticate("vjrj", "6rzonw7n39p01td1p0rfujvu3");
-    auth.authenticate("admin", "x04c5575ycquu96k4kajldaq");
+    // Test with a valid session hash also
+    auth.authenticate("admin", "1lvy0m668xv9w1csre15n874hx");
+    // auth.authenticate("vjrj", "6rzonw7n39p01td1p0rfujvu3");
+    // auth.authenticate("admin", "x04c5575ycquu96k4kajldaq");
     // Only usersession!!!
     // auth.authenticate("vjrj", "1006oh5apswj81tl4vcsk1gqpj");
   }
 
   @Test(expected = UnauthorizedException.class)
   public void wrongFileSession() throws UnauthorizedException, ConnectionException,
-      InternalUnauthenticatedException {
+      InternalUnauthenticatedException, MalformedURLException, ClassNotFoundException,
+      IllegalAccessException, InstantiationException {
     final KuneAuthProvider auth = new KuneAuthProvider();
     auth.authenticate("admin", "6rzonw7n39p01td1p0rfujvu3a");
   }
 
   @Test(expected = UnauthorizedException.class)
   public void wrongPass() throws UnauthorizedException, ConnectionException,
-      InternalUnauthenticatedException {
+      InternalUnauthenticatedException, MalformedURLException, ClassNotFoundException,
+      IllegalAccessException, InstantiationException {
     final KuneAuthProvider auth = new KuneAuthProvider();
     auth.authenticate("admin", "easyeasy2");
   }
 
   @Test(expected = UnauthorizedException.class)
   public void wrongSession() throws UnauthorizedException, ConnectionException,
-      InternalUnauthenticatedException {
+      InternalUnauthenticatedException, MalformedURLException, ClassNotFoundException,
+      IllegalAccessException, InstantiationException {
     final KuneAuthProvider auth = new KuneAuthProvider();
     auth.authenticate("admin", "6rzonw7n39p01td1p0rfujvu3");
   }




More information about the kune-commits mailing list