[kune-commits] r1751 - / openfireauth openfireauth/src openfireauth/src/main openfireauth/src/main/java openfireauth/src/main/java/cc openfireauth/src/main/java/cc/kune openfireauth/src/main/java/cc/kune/core openfireauth/src/main/java/cc/kune/core/server openfireauth/src/main/java/cc/kune/core/server/auth openfireauth/src/main/java/cc/kune/core/server/auth/openfire openfireauth/src/main/resources openfireauth/src/test openfireauth/src/test/java openfireauth/src/test/java/cc openfireauth/src/test/java/cc/kune openfireauth/src/test/java/cc/kune/core openfireauth/src/test/java/cc/kune/core/server openfireauth/src/test/java/cc/kune/core/server/auth openfireauth/src/test/java/cc/kune/core/server/auth/openfire openfireauth/target
Vicente J. Ruiz Jurado
vjrj_ at ourproject.org
Sat Mar 10 06:28:49 CET 2012
Author: vjrj_
Date: 2012-03-10 06:28:48 +0100 (Sat, 10 Mar 2012)
New Revision: 1751
Added:
openfireauth/
openfireauth/pom.xml
openfireauth/src/
openfireauth/src/main/
openfireauth/src/main/java/
openfireauth/src/main/java/cc/
openfireauth/src/main/java/cc/kune/
openfireauth/src/main/java/cc/kune/core/
openfireauth/src/main/java/cc/kune/core/server/
openfireauth/src/main/java/cc/kune/core/server/auth/
openfireauth/src/main/java/cc/kune/core/server/auth/openfire/
openfireauth/src/main/java/cc/kune/core/server/auth/openfire/KuneAuthProvider.java
openfireauth/src/main/resources/
openfireauth/src/main/resources/log4j.properties
openfireauth/src/test/
openfireauth/src/test/java/
openfireauth/src/test/java/cc/
openfireauth/src/test/java/cc/kune/
openfireauth/src/test/java/cc/kune/core/
openfireauth/src/test/java/cc/kune/core/server/
openfireauth/src/test/java/cc/kune/core/server/auth/
openfireauth/src/test/java/cc/kune/core/server/auth/openfire/
openfireauth/src/test/java/cc/kune/core/server/auth/openfire/KuneAuthProviderTest.java
openfireauth/src/test/resources/
openfireauth/target/
Log:
openfire alternative auth module for kune
Added: openfireauth/pom.xml
===================================================================
--- openfireauth/pom.xml (rev 0)
+++ openfireauth/pom.xml 2012-03-10 05:28:48 UTC (rev 1751)
@@ -0,0 +1,44 @@
+<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/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+ <groupId>cc.kune</groupId>
+ <artifactId>kune-openfireauth</artifactId>
+ <version>0.0.1-SNAPSHOT</version>
+ <name>Kuen 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>
+ <maven.compiler.source>1.6</maven.compiler.source>
+ <maven.compiler.target>1.6</maven.compiler.target>
+ <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+ <wiab.version>0.3.12</wiab.version>
+ </properties>
+ <repositories>
+ <repository>
+ <id>kune-maven</id>
+ <url>http://kune.ourproject.org/mavenrepo/</url>
+ </repository>
+ </repositories>
+ <dependencies>
+ <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.igniterealtime</groupId>
+ <artifactId>openfire</artifactId>
+ <version>3.7.0</version>
+ </dependency>
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <version>4.9</version>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+</project>
\ No newline at end of file
Added: openfireauth/src/main/java/cc/kune/core/server/auth/openfire/KuneAuthProvider.java
===================================================================
--- openfireauth/src/main/java/cc/kune/core/server/auth/openfire/KuneAuthProvider.java (rev 0)
+++ openfireauth/src/main/java/cc/kune/core/server/auth/openfire/KuneAuthProvider.java 2012-03-10 05:28:48 UTC (rev 1751)
@@ -0,0 +1,135 @@
+package cc.kune.core.server.auth.openfire;
+
+import java.io.DataInputStream;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.io.ObjectInputStream;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.jivesoftware.openfire.auth.AuthProvider;
+import org.jivesoftware.openfire.auth.ConnectionException;
+import org.jivesoftware.openfire.auth.InternalUnauthenticatedException;
+import org.jivesoftware.openfire.auth.UnauthorizedException;
+import org.jivesoftware.openfire.user.UserNotFoundException;
+import org.waveprotocol.wave.model.wave.ParticipantId;
+
+public class KuneAuthProvider implements AuthProvider {
+
+ protected class ClassLoadingObjectInputStream extends ObjectInputStream {
+
+ /**
+ * Code copied from HashSessionManager
+ *
+ * @throws IOException
+ */
+ public ClassLoadingObjectInputStream() throws IOException {
+ super();
+ }
+
+ 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);
+ }
+ }
+ }
+
+ public static final Log LOG = LogFactory.getLog(KuneAuthProvider.class);
+
+ private static final String USER_NOT_LOGGED = "User not logged";
+
+ @Override
+ @SuppressWarnings("unused")
+ public void authenticate(final String username, final String token) throws UnauthorizedException,
+ ConnectionException, InternalUnauthenticatedException {
+ try {
+ final File session = new File("/var/lib/kune/_sessions/" + token);
+ boolean logged = false;
+ 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++) {
+ final String key = ois.readUTF();
+ try {
+ final Object value = ois.readObject();
+ if (value instanceof ParticipantId) {
+ if (((ParticipantId) value).getAddress().startsWith(username + "@")) {
+ logged = true;
+ break;
+ }
+ }
+ } catch (final ClassNotFoundException e) {
+ LOG.warn("Persisted in kune session unexpected object: " + e.getMessage());
+ }
+ }
+ ois.close();
+ }
+ in.close();
+ is.close();
+ if (!logged) {
+ throw new UnauthorizedException("Incorrect username");
+ }
+ } else {
+ throw new UnauthorizedException(USER_NOT_LOGGED);
+ }
+ } catch (final FileNotFoundException e) {
+ throw new UnauthorizedException(USER_NOT_LOGGED, e);
+ } catch (final IOException e) {
+ throw new UnauthorizedException(USER_NOT_LOGGED, e);
+ }
+ }
+
+ @Override
+ public void authenticate(final String username, final String token, final String digest)
+ throws UnauthorizedException, ConnectionException, InternalUnauthenticatedException {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public String getPassword(final String arg0) throws UserNotFoundException,
+ UnsupportedOperationException {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public boolean isDigestSupported() {
+ return false;
+ }
+
+ @Override
+ public boolean isPlainSupported() {
+ return true;
+ }
+
+ @Override
+ public void setPassword(final String arg0, final String arg1) throws UserNotFoundException,
+ UnsupportedOperationException {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public boolean supportsPasswordRetrieval() {
+ return false;
+ }
+
+}
Added: openfireauth/src/main/resources/log4j.properties
===================================================================
--- openfireauth/src/main/resources/log4j.properties (rev 0)
+++ openfireauth/src/main/resources/log4j.properties 2012-03-10 05:28:48 UTC (rev 1751)
@@ -0,0 +1,8 @@
+# Root logger option
+log4j.rootLogger=INFO, stdout
+
+# Direct log messages to stdout
+log4j.appender.stdout=org.apache.log4j.ConsoleAppender
+log4j.appender.stdout.Target=System.out
+log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
+log4j.appender.stdout.layout.ConversionPattern=%d{ABSOLUTE} %5p %c{1}:%L - %m%n
\ No newline at end of file
Added: openfireauth/src/test/java/cc/kune/core/server/auth/openfire/KuneAuthProviderTest.java
===================================================================
--- openfireauth/src/test/java/cc/kune/core/server/auth/openfire/KuneAuthProviderTest.java (rev 0)
+++ openfireauth/src/test/java/cc/kune/core/server/auth/openfire/KuneAuthProviderTest.java 2012-03-10 05:28:48 UTC (rev 1751)
@@ -0,0 +1,17 @@
+package cc.kune.core.server.auth.openfire;
+
+import org.jivesoftware.openfire.auth.ConnectionException;
+import org.jivesoftware.openfire.auth.InternalUnauthenticatedException;
+import org.jivesoftware.openfire.auth.UnauthorizedException;
+import org.junit.Test;
+
+public class KuneAuthProviderTest {
+
+ @Test
+ public void maintest() throws UnauthorizedException, ConnectionException,
+ InternalUnauthenticatedException {
+ final KuneAuthProvider auth = new KuneAuthProvider();
+ auth.authenticate("vjrj", "6rzonw7n39p01td1p0rfujvu3");
+ auth.authenticate("admin", "x04c5575ycquu96k4kajldaq");
+ }
+}
Property changes on: openfireauth/target
___________________________________________________________________
Name: svn:ignore
+ classes
kune-openfireauth-0.0.1-SNAPSHOT.jar
maven-archiver
mvn-eclipse-cache.properties
surefire-reports
test-classes
More information about the kune-commits
mailing list