You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@labs.apache.org by be...@apache.org on 2009/03/21 08:26:27 UTC
svn commit: r756884 - in /labs/vysper: lib/ src/main/config/
src/main/java/org/apache/vysper/storage/
src/main/java/org/apache/vysper/storage/jcr/
src/main/java/org/apache/vysper/storage/jcr/roster/
src/main/java/org/apache/vysper/storage/jcr/user/ src...
Author: berndf
Date: Sat Mar 21 07:26:27 2009
New Revision: 756884
URL: http://svn.apache.org/viewvc?rev=756884&view=rev
Log:
[vysper] LABS-125 JCR persistence: general JCR infrastructure, store credentials in JCR, first steps towards having roster in JCR
Added:
labs/vysper/src/main/java/org/apache/vysper/storage/
labs/vysper/src/main/java/org/apache/vysper/storage/jcr/
labs/vysper/src/main/java/org/apache/vysper/storage/jcr/JcrStorage.java
labs/vysper/src/main/java/org/apache/vysper/storage/jcr/JcrStorageException.java
labs/vysper/src/main/java/org/apache/vysper/storage/jcr/roster/
labs/vysper/src/main/java/org/apache/vysper/storage/jcr/roster/JcrRoster.java
labs/vysper/src/main/java/org/apache/vysper/storage/jcr/roster/JcrRosterManager.java
labs/vysper/src/main/java/org/apache/vysper/storage/jcr/user/
labs/vysper/src/main/java/org/apache/vysper/storage/jcr/user/JcrUserManagement.java
labs/vysper/src/main/java/org/apache/vysper/xmpp/authorization/AccountCreation.java
labs/vysper/src/main/java/org/apache/vysper/xmpp/authorization/AccountCreationException.java
labs/vysper/src/main/java/org/apache/vysper/xmpp/modules/roster/persistence/AbstractRosterManager.java
Modified:
labs/vysper/lib/LIBRARY_OVERVIEW.txt
labs/vysper/src/main/config/log4j.xml
labs/vysper/src/main/java/org/apache/vysper/xmpp/authorization/SimpleUserAuthorization.java
labs/vysper/src/main/java/org/apache/vysper/xmpp/modules/roster/RosterModule.java
labs/vysper/src/main/java/org/apache/vysper/xmpp/modules/roster/persistence/MemoryRosterManager.java
labs/vysper/src/main/java/org/apache/vysper/xmpp/server/ServerMain.java
Modified: labs/vysper/lib/LIBRARY_OVERVIEW.txt
URL: http://svn.apache.org/viewvc/labs/vysper/lib/LIBRARY_OVERVIEW.txt?rev=756884&r1=756883&r2=756884&view=diff
==============================================================================
--- labs/vysper/lib/LIBRARY_OVERVIEW.txt (original)
+++ labs/vysper/lib/LIBRARY_OVERVIEW.txt Sat Mar 21 07:26:27 2009
@@ -4,6 +4,7 @@
bcprov-jdk15-135.jar - bouncycastle.org - Apache-like
commons-logging.jar - Apache Commons
+jackrabbit-standalone-1.5.3.jar - ASL - only needed for JCR persistence
junit.jar - junit.sourceforge.net - Commons Public 1.0
log4j-1.2.14.jar - Apache MINA
mina-core-1.1.0.jar - Apache MINA
Modified: labs/vysper/src/main/config/log4j.xml
URL: http://svn.apache.org/viewvc/labs/vysper/src/main/config/log4j.xml?rev=756884&r1=756883&r2=756884&view=diff
==============================================================================
--- labs/vysper/src/main/config/log4j.xml (original)
+++ labs/vysper/src/main/config/log4j.xml Sat Mar 21 07:26:27 2009
@@ -66,6 +66,11 @@
<priority value="WARN"/>
</category>
+ <!-- limit logging for jackrabbit -->
+ <category name="org.apache.jackrabbit">
+ <priority value="INFO"/>
+ </category>
+
<category name="stanza">
<priority value="INFO"/>
<appender-ref ref="STANZA" />
Added: labs/vysper/src/main/java/org/apache/vysper/storage/jcr/JcrStorage.java
URL: http://svn.apache.org/viewvc/labs/vysper/src/main/java/org/apache/vysper/storage/jcr/JcrStorage.java?rev=756884&view=auto
==============================================================================
--- labs/vysper/src/main/java/org/apache/vysper/storage/jcr/JcrStorage.java (added)
+++ labs/vysper/src/main/java/org/apache/vysper/storage/jcr/JcrStorage.java Sat Mar 21 07:26:27 2009
@@ -0,0 +1,110 @@
+/***********************************************************************
+ * Copyright (c) 2006-2008 The Apache Software Foundation. *
+ * All rights reserved. *
+ * ------------------------------------------------------------------- *
+ * Licensed 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.jcr;
+
+import org.apache.jackrabbit.core.TransientRepository;
+import org.apache.vysper.xmpp.addressing.Entity;
+
+import javax.jcr.*;
+
+/**
+ * back-end stuff for JCR, used by the semantic specific adapters
+ */
+public class JcrStorage {
+
+ protected static JcrStorage jcrStorageSingleton;
+
+ protected JcrStorage() {
+ super();
+ // protected
+ }
+
+ public static JcrStorage getInstance() {
+ synchronized (JcrStorage.class) {
+ if (jcrStorageSingleton == null) jcrStorageSingleton = new JcrStorage();
+ return jcrStorageSingleton;
+ }
+ }
+
+ protected Session session = null;
+
+ public Session getRepositorySession() throws JcrStorageException {
+ if (session != null) return session;
+ try {
+ Repository repository = new TransientRepository();
+ session = repository.login(new SimpleCredentials("xmpp-admin", "adminpassword".toCharArray()));
+ return session;
+ } catch (Exception e) {
+ throw new JcrStorageException(e);
+ }
+ }
+
+ public Node getRootNode() throws JcrStorageException {
+ try {
+ return getRepositorySession().getRootNode();
+ } catch (RepositoryException e) {
+ throw new JcrStorageException(e);
+ }
+ }
+
+ public Node getEntityNode(Entity bareEntity, String namespace, boolean createIfMissing) throws JcrStorageException {
+ bareEntity = bareEntity.getBareJID(); // make it really sure
+ if (namespace != null) namespace = namespace.replace(':', '_');
+ final String path = "/accountentity/" + bareEntity.getFullQualifiedName() + (namespace != null ? "/" + namespace : "");
+ if (!itemExists(path)) {
+ if (!createIfMissing) return null;
+ Node accountEntityNode = getOrCreate(getRootNode(), "accountentity");
+ Node entityNode = getOrCreate(accountEntityNode, bareEntity.getFullQualifiedName());
+ if (namespace != null) entityNode = getOrCreate(entityNode, namespace);
+ return entityNode;
+ } else {
+ try {
+ return (Node)getRepositorySession().getItem(path);
+ } catch (RepositoryException e) {
+ throw new JcrStorageException(e);
+ }
+ }
+ }
+
+ private boolean itemExists(String absolutePath) throws JcrStorageException {
+ try {
+ return getRepositorySession().itemExists(absolutePath);
+ } catch (RepositoryException e) {
+ throw new JcrStorageException(e);
+ } catch (JcrStorageException e) {
+ throw e;
+ }
+ }
+
+ protected Node getOrCreate(Node parent, String nodeName) throws JcrStorageException {
+ Node childNode;
+ try {
+ childNode = parent.getNode(nodeName);
+ } catch (RepositoryException e) {
+ childNode = null;
+ }
+ if (childNode == null) {
+ try {
+ childNode = parent.addNode(nodeName);
+ parent.save();
+ } catch (RepositoryException e) {
+ throw new JcrStorageException(e);
+ }
+ }
+ return childNode;
+ }
+}
Added: labs/vysper/src/main/java/org/apache/vysper/storage/jcr/JcrStorageException.java
URL: http://svn.apache.org/viewvc/labs/vysper/src/main/java/org/apache/vysper/storage/jcr/JcrStorageException.java?rev=756884&view=auto
==============================================================================
--- labs/vysper/src/main/java/org/apache/vysper/storage/jcr/JcrStorageException.java (added)
+++ labs/vysper/src/main/java/org/apache/vysper/storage/jcr/JcrStorageException.java Sat Mar 21 07:26:27 2009
@@ -0,0 +1,37 @@
+/***********************************************************************
+ * Copyright (c) 2006-2008 The Apache Software Foundation. *
+ * All rights reserved. *
+ * ------------------------------------------------------------------- *
+ * Licensed 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.jcr;
+
+/**
+ */
+public class JcrStorageException extends Exception {
+ public JcrStorageException() {
+ super();
+ }
+
+ public JcrStorageException(String message) {
+ super(message);
+ }
+
+ public JcrStorageException(String message, Throwable cause) {
+ super(message, cause);
+ }
+
+ public JcrStorageException(Throwable cause) {
+ super(cause);
+ }
+}
Added: labs/vysper/src/main/java/org/apache/vysper/storage/jcr/roster/JcrRoster.java
URL: http://svn.apache.org/viewvc/labs/vysper/src/main/java/org/apache/vysper/storage/jcr/roster/JcrRoster.java?rev=756884&view=auto
==============================================================================
--- labs/vysper/src/main/java/org/apache/vysper/storage/jcr/roster/JcrRoster.java (added)
+++ labs/vysper/src/main/java/org/apache/vysper/storage/jcr/roster/JcrRoster.java Sat Mar 21 07:26:27 2009
@@ -0,0 +1,62 @@
+/***********************************************************************
+ * Copyright (c) 2006-2007 The Apache Software Foundation. *
+ * All rights reserved. *
+ * ------------------------------------------------------------------- *
+ * Licensed 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.jcr.roster;
+
+import org.apache.vysper.storage.jcr.JcrStorage;
+import org.apache.vysper.xmpp.modules.roster.MutableRoster;
+import org.apache.vysper.xmpp.modules.roster.RosterItem;
+import org.apache.vysper.xmpp.addressing.Entity;
+
+import javax.jcr.Node;
+import javax.jcr.RepositoryException;
+
+/**
+ */
+public class JcrRoster extends MutableRoster {
+
+ protected JcrStorage jcrStorage;
+ protected Entity jid;
+
+ public JcrRoster(JcrStorage jcrStorage, Entity jid) {
+ this.jcrStorage = jcrStorage;
+ this.jid = jid;
+ }
+
+ @Override
+ public void addItem(RosterItem rosterItem) {
+ final Node node = JcrRosterManager.retrieveRosterNode(jcrStorage, jid);
+ Node contactNode = null;
+ try {
+ contactNode = node.addNode(rosterItem.getJid().getBareJID().getFullQualifiedName());
+ contactNode.save();
+ } catch (RepositoryException e) {
+ throw new RuntimeException("failed to create roster item for owner = " + jid.getFullQualifiedName() +
+ " and contact " + rosterItem.getJid().getFullQualifiedName());
+ }
+
+ try {
+ contactNode.setProperty("name", rosterItem.getName());
+ contactNode.setProperty("type", rosterItem.getSubscriptionType().value());
+ contactNode.setProperty("askType", rosterItem.getAskSubscriptionType().value());
+ //TODO save groups contactNode.setProperty(, rosterItem.getGroups())
+ contactNode.save();
+ } catch (RepositoryException e) {
+ throw new RuntimeException("failed to set roster properties for owner = " + jid.getFullQualifiedName() +
+ " and contact " + rosterItem.getJid().getFullQualifiedName());
+ }
+ }
+}
Added: labs/vysper/src/main/java/org/apache/vysper/storage/jcr/roster/JcrRosterManager.java
URL: http://svn.apache.org/viewvc/labs/vysper/src/main/java/org/apache/vysper/storage/jcr/roster/JcrRosterManager.java?rev=756884&view=auto
==============================================================================
--- labs/vysper/src/main/java/org/apache/vysper/storage/jcr/roster/JcrRosterManager.java (added)
+++ labs/vysper/src/main/java/org/apache/vysper/storage/jcr/roster/JcrRosterManager.java Sat Mar 21 07:26:27 2009
@@ -0,0 +1,65 @@
+/***********************************************************************
+ * Copyright (c) 2006-2007 The Apache Software Foundation. *
+ * All rights reserved. *
+ * ------------------------------------------------------------------- *
+ * Licensed 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.jcr.roster;
+
+import org.apache.vysper.xmpp.modules.roster.persistence.AbstractRosterManager;
+import org.apache.vysper.xmpp.modules.roster.Roster;
+import org.apache.vysper.xmpp.modules.roster.MutableRoster;
+import org.apache.vysper.xmpp.addressing.Entity;
+import org.apache.vysper.xmpp.protocol.NamespaceURIs;
+import org.apache.vysper.storage.jcr.JcrStorage;
+import org.apache.vysper.storage.jcr.JcrStorageException;
+
+import javax.jcr.Node;
+
+/**
+ */
+public class JcrRosterManager extends AbstractRosterManager {
+
+ protected JcrStorage jcrStorage;
+
+ public JcrRosterManager(JcrStorage jcrStorage) {
+ this.jcrStorage = jcrStorage;
+ }
+
+ /*package*/ static Node retrieveRosterNode(JcrStorage jcrStorage, Entity bareJid) {
+ try {
+ if (jcrStorage.getEntityNode(bareJid, null, false) == null) return null;
+ return jcrStorage.getEntityNode(bareJid, NamespaceURIs.JABBER_IQ_ROSTER, true);
+ } catch (JcrStorageException e) {
+ return null;
+ }
+ }
+
+ protected Roster retrieveRosterInternal(Entity bareJid) {
+ final Node node = retrieveRosterNode(jcrStorage, bareJid);
+ if (node == null) return null;
+ return null;
+ }
+
+ protected Roster addNewRosterInternal(Entity jid) {
+ JcrRoster mutableRoster = new JcrRoster(jcrStorage, jid);
+
+ try {
+ jcrStorage.getEntityNode(jid, NamespaceURIs.JABBER_IQ_ROSTER, false);
+ } catch (JcrStorageException e) {
+ // did not create roster. maybe already exists
+ }
+
+ return mutableRoster;
+ }
+}
Added: labs/vysper/src/main/java/org/apache/vysper/storage/jcr/user/JcrUserManagement.java
URL: http://svn.apache.org/viewvc/labs/vysper/src/main/java/org/apache/vysper/storage/jcr/user/JcrUserManagement.java?rev=756884&view=auto
==============================================================================
--- labs/vysper/src/main/java/org/apache/vysper/storage/jcr/user/JcrUserManagement.java (added)
+++ labs/vysper/src/main/java/org/apache/vysper/storage/jcr/user/JcrUserManagement.java Sat Mar 21 07:26:27 2009
@@ -0,0 +1,99 @@
+/***********************************************************************
+ * Copyright (c) 2006-2008 The Apache Software Foundation. *
+ * All rights reserved. *
+ * ------------------------------------------------------------------- *
+ * Licensed 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.jcr.user;
+
+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.authorization.AccountCreation;
+import org.apache.vysper.xmpp.authorization.AccountCreationException;
+import org.apache.vysper.xmpp.authorization.AccountVerification;
+import org.apache.vysper.xmpp.authorization.UserAuthorization;
+import org.apache.vysper.storage.jcr.JcrStorage;
+import org.apache.vysper.storage.jcr.JcrStorageException;
+
+import javax.jcr.Node;
+import javax.jcr.Property;
+
+/**
+ */
+public class JcrUserManagement implements UserAuthorization, AccountVerification, AccountCreation {
+
+ protected JcrStorage jcrStorage;
+ private static final String CREDENTIALS_NAMESPACE = "vysper_internal_credentials";
+
+ public JcrUserManagement(JcrStorage jcrStorage) {
+ this.jcrStorage = jcrStorage;
+ }
+
+ public boolean verifyCredentials(Entity jid, String passwordCleartext, Object credentials) {
+ if (passwordCleartext == null) return false;
+ try {
+ final Node credentialsNode = jcrStorage.getEntityNode(jid, CREDENTIALS_NAMESPACE, false);
+ if (credentialsNode == null) return false;
+ final Property property = credentialsNode.getProperty("password");
+ if (property == null) return false;
+ final String password = property.getValue().getString();
+ return passwordCleartext.equals(password);
+ } catch (Exception e) {
+ return false;
+ }
+ }
+
+ 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) {
+ try {
+ return jcrStorage.getEntityNode(jid, CREDENTIALS_NAMESPACE, false) != null;
+ } catch (JcrStorageException e) {
+ return false;
+ }
+ }
+
+ public void addUser(String username, String password) throws AccountCreationException {
+ final EntityImpl entity;
+ try {
+ entity = EntityImpl.parse(username);
+ } catch (EntityFormatException e) {
+ throw new AccountCreationException("username is expected to be in proper entity format, not " + username, e); // wrap as unchecked
+ }
+ // if already existent, don't create, throw error
+ try {
+ if (jcrStorage.getEntityNode(entity, CREDENTIALS_NAMESPACE, false) != null) {
+ throw new AccountCreationException("account already exists: " + entity.getFullQualifiedName());
+ }
+ } catch (JcrStorageException e) {
+ throw new AccountCreationException("account exists check failed for " + entity.getFullQualifiedName(), e);
+ }
+ // now, finally, create
+ try {
+ final Node credentialsNode = jcrStorage.getEntityNode(entity, CREDENTIALS_NAMESPACE, true);
+ credentialsNode.setProperty("password", password);
+ credentialsNode.save();
+ } catch (Exception e) {
+ // TODO remove account?
+ throw new AccountCreationException("failed to create the account set credentials", e);
+ }
+
+ }
+}
Added: labs/vysper/src/main/java/org/apache/vysper/xmpp/authorization/AccountCreation.java
URL: http://svn.apache.org/viewvc/labs/vysper/src/main/java/org/apache/vysper/xmpp/authorization/AccountCreation.java?rev=756884&view=auto
==============================================================================
--- labs/vysper/src/main/java/org/apache/vysper/xmpp/authorization/AccountCreation.java (added)
+++ labs/vysper/src/main/java/org/apache/vysper/xmpp/authorization/AccountCreation.java Sat Mar 21 07:26:27 2009
@@ -0,0 +1,23 @@
+/***********************************************************************
+ * Copyright (c) 2006-2008 The Apache Software Foundation. *
+ * All rights reserved. *
+ * ------------------------------------------------------------------- *
+ * Licensed 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.xmpp.authorization;
+
+/**
+ */
+public interface AccountCreation {
+ void addUser(String username, String password) throws AccountCreationException;
+}
Added: labs/vysper/src/main/java/org/apache/vysper/xmpp/authorization/AccountCreationException.java
URL: http://svn.apache.org/viewvc/labs/vysper/src/main/java/org/apache/vysper/xmpp/authorization/AccountCreationException.java?rev=756884&view=auto
==============================================================================
--- labs/vysper/src/main/java/org/apache/vysper/xmpp/authorization/AccountCreationException.java (added)
+++ labs/vysper/src/main/java/org/apache/vysper/xmpp/authorization/AccountCreationException.java Sat Mar 21 07:26:27 2009
@@ -0,0 +1,36 @@
+/***********************************************************************
+ * Copyright (c) 2006-2008 The Apache Software Foundation. *
+ * All rights reserved. *
+ * ------------------------------------------------------------------- *
+ * Licensed 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.xmpp.authorization;
+
+/**
+ */
+public class AccountCreationException extends Exception {
+ public AccountCreationException() {
+ }
+
+ public AccountCreationException(String message) {
+ super(message);
+ }
+
+ public AccountCreationException(String message, Throwable cause) {
+ super(message, cause);
+ }
+
+ public AccountCreationException(Throwable cause) {
+ super(cause);
+ }
+}
Modified: labs/vysper/src/main/java/org/apache/vysper/xmpp/authorization/SimpleUserAuthorization.java
URL: http://svn.apache.org/viewvc/labs/vysper/src/main/java/org/apache/vysper/xmpp/authorization/SimpleUserAuthorization.java?rev=756884&r1=756883&r2=756884&view=diff
==============================================================================
--- labs/vysper/src/main/java/org/apache/vysper/xmpp/authorization/SimpleUserAuthorization.java (original)
+++ labs/vysper/src/main/java/org/apache/vysper/xmpp/authorization/SimpleUserAuthorization.java Sat Mar 21 07:26:27 2009
@@ -24,7 +24,7 @@
/**
* very simple in-memory {@link org.apache.vysper.xmpp.authorization.UserAuthorization} service
*/
-public class SimpleUserAuthorization implements UserAuthorization, AccountVerification {
+public class SimpleUserAuthorization implements UserAuthorization, AccountVerification, AccountCreation {
private final Map<String, String> userPasswordMap = new HashMap<String, String>();
Modified: labs/vysper/src/main/java/org/apache/vysper/xmpp/modules/roster/RosterModule.java
URL: http://svn.apache.org/viewvc/labs/vysper/src/main/java/org/apache/vysper/xmpp/modules/roster/RosterModule.java?rev=756884&r1=756883&r2=756884&view=diff
==============================================================================
--- labs/vysper/src/main/java/org/apache/vysper/xmpp/modules/roster/RosterModule.java (original)
+++ labs/vysper/src/main/java/org/apache/vysper/xmpp/modules/roster/RosterModule.java Sat Mar 21 07:26:27 2009
@@ -20,6 +20,8 @@
import org.apache.vysper.xmpp.modules.ServerRuntimeContextService;
import org.apache.vysper.xmpp.modules.roster.persistence.MemoryRosterManager;
import org.apache.vysper.xmpp.protocol.HandlerDictionary;
+import org.apache.vysper.storage.jcr.JcrStorage;
+import org.apache.vysper.storage.jcr.roster.JcrRosterManager;
import java.util.List;
@@ -43,6 +45,6 @@
@Override
protected void addServerServices(List<ServerRuntimeContextService> serviceList) {
- serviceList.add(new MemoryRosterManager());
+ serviceList.add(new JcrRosterManager(JcrStorage.getInstance()));
}
}
\ No newline at end of file
Added: labs/vysper/src/main/java/org/apache/vysper/xmpp/modules/roster/persistence/AbstractRosterManager.java
URL: http://svn.apache.org/viewvc/labs/vysper/src/main/java/org/apache/vysper/xmpp/modules/roster/persistence/AbstractRosterManager.java?rev=756884&view=auto
==============================================================================
--- labs/vysper/src/main/java/org/apache/vysper/xmpp/modules/roster/persistence/AbstractRosterManager.java (added)
+++ labs/vysper/src/main/java/org/apache/vysper/xmpp/modules/roster/persistence/AbstractRosterManager.java Sat Mar 21 07:26:27 2009
@@ -0,0 +1,64 @@
+/***********************************************************************
+ * Copyright (c) 2006-2007 The Apache Software Foundation. *
+ * All rights reserved. *
+ * ------------------------------------------------------------------- *
+ * Licensed 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.xmpp.modules.roster.persistence;
+
+import org.apache.vysper.xmpp.modules.ServerRuntimeContextService;
+import org.apache.vysper.xmpp.modules.roster.Roster;
+import org.apache.vysper.xmpp.modules.roster.RosterItem;
+import org.apache.vysper.xmpp.modules.roster.RosterException;
+import org.apache.vysper.xmpp.modules.roster.MutableRoster;
+import org.apache.vysper.xmpp.addressing.Entity;
+
+/**
+ */
+public abstract class AbstractRosterManager implements RosterManager, ServerRuntimeContextService {
+
+ abstract protected Roster retrieveRosterInternal(Entity bareJid);
+
+ abstract protected Roster addNewRosterInternal(Entity jid);
+
+ public Roster retrieve(Entity jid) {
+ jid = jid.getBareJID();
+ return retrieveRosterInternal(jid);
+ }
+
+ public void addContact(Entity jid, RosterItem rosterItem) throws RosterException {
+ if (jid == null) throw new RosterException("jid not provided");
+ MutableRoster mutableRoster = (MutableRoster) retrieve(jid);
+ if (mutableRoster == null) {
+ mutableRoster = (MutableRoster) addNewRosterInternal(jid);
+ }
+ mutableRoster.addItem(rosterItem);
+ }
+
+ public RosterItem getContact(Entity jidUser, Entity jidContact) throws RosterException {
+ if (jidUser == null) throw new RosterException("jid not provided");
+ Roster roster = retrieve(jidUser);
+ if (roster == null) throw new RosterException("roster not available for jid = " + jidUser.getFullQualifiedName());
+ return roster.getEntry(jidContact);
+ }
+
+ public void removeContact(Entity jidUser, Entity jidContact) throws RosterException {
+ if (jidUser == null) throw new RosterException("jid not provided");
+ Roster roster = retrieve(jidUser);
+ if (roster == null) throw new RosterException("roster not available for jid = " + jidUser.getFullQualifiedName());
+ }
+
+ public String getServiceName() {
+ return RosterManager.SERVER_SERVICE_ROSTERMANAGER;
+ }
+}
Modified: labs/vysper/src/main/java/org/apache/vysper/xmpp/modules/roster/persistence/MemoryRosterManager.java
URL: http://svn.apache.org/viewvc/labs/vysper/src/main/java/org/apache/vysper/xmpp/modules/roster/persistence/MemoryRosterManager.java?rev=756884&r1=756883&r2=756884&view=diff
==============================================================================
--- labs/vysper/src/main/java/org/apache/vysper/xmpp/modules/roster/persistence/MemoryRosterManager.java (original)
+++ labs/vysper/src/main/java/org/apache/vysper/xmpp/modules/roster/persistence/MemoryRosterManager.java Sat Mar 21 07:26:27 2009
@@ -17,53 +17,28 @@
package org.apache.vysper.xmpp.modules.roster.persistence;
import org.apache.vysper.xmpp.addressing.Entity;
-import org.apache.vysper.xmpp.modules.roster.Roster;
-import org.apache.vysper.xmpp.modules.roster.RosterItem;
-import org.apache.vysper.xmpp.modules.roster.RosterException;
import org.apache.vysper.xmpp.modules.roster.MutableRoster;
-import org.apache.vysper.xmpp.modules.ServerRuntimeContextService;
+import org.apache.vysper.xmpp.modules.roster.Roster;
-import java.util.Map;
import java.util.HashMap;
+import java.util.Map;
/**
* manages rosters in memory (and if the application ends, they are lost)
*/
-public class MemoryRosterManager implements RosterManager, ServerRuntimeContextService {
+public class MemoryRosterManager extends AbstractRosterManager {
private Map<Entity, MutableRoster> rosterMap = new HashMap<Entity, MutableRoster>();
-
- public Roster retrieve(Entity jid) {
- jid = jid.getBareJID();
- if (!rosterMap.containsKey(jid)) rosterMap.put(jid, new MutableRoster());
- return rosterMap.get(jid);
+ protected Roster addNewRosterInternal(Entity jid) {
+ MutableRoster mutableRoster = new MutableRoster();
+ rosterMap.put(jid.getBareJID(), (MutableRoster) mutableRoster);
+ return mutableRoster;
}
- public void addContact(Entity jid, RosterItem rosterItem) throws RosterException {
- if (jid == null) throw new RosterException("jid not provided");
- MutableRoster mutableRoster = (MutableRoster) retrieve(jid);
- if (mutableRoster == null) {
- mutableRoster = new MutableRoster();
- rosterMap.put(jid.getBareJID(), mutableRoster);
- }
- mutableRoster.addItem(rosterItem);
+ protected Roster retrieveRosterInternal(Entity bareJid) {
+ if (!rosterMap.containsKey(bareJid)) rosterMap.put(bareJid, new MutableRoster());
+ return rosterMap.get(bareJid);
}
- public RosterItem getContact(Entity jidUser, Entity jidContact) throws RosterException {
- if (jidUser == null) throw new RosterException("jid not provided");
- Roster roster = retrieve(jidUser);
- if (roster == null) throw new RosterException("roster not available for jid = " + jidUser.getFullQualifiedName());
- return roster.getEntry(jidContact);
- }
-
- public void removeContact(Entity jidUser, Entity jidContact) throws RosterException {
- if (jidUser == null) throw new RosterException("jid not provided");
- Roster roster = retrieve(jidUser);
- if (roster == null) throw new RosterException("roster not available for jid = " + jidUser.getFullQualifiedName());
- }
-
- public String getServiceName() {
- return RosterManager.SERVER_SERVICE_ROSTERMANAGER;
- }
}
Modified: labs/vysper/src/main/java/org/apache/vysper/xmpp/server/ServerMain.java
URL: http://svn.apache.org/viewvc/labs/vysper/src/main/java/org/apache/vysper/xmpp/server/ServerMain.java?rev=756884&r1=756883&r2=756884&view=diff
==============================================================================
--- labs/vysper/src/main/java/org/apache/vysper/xmpp/server/ServerMain.java (original)
+++ labs/vysper/src/main/java/org/apache/vysper/xmpp/server/ServerMain.java Sat Mar 21 07:26:27 2009
@@ -18,9 +18,11 @@
import org.apache.vysper.mina.TCPEndpoint;
import org.apache.vysper.stanzasession.StanzaSessionFactory;
-import org.apache.vysper.xmpp.authorization.SimpleUserAuthorization;
+import org.apache.vysper.xmpp.authorization.AccountCreationException;
import org.apache.vysper.xmpp.modules.extension.xep0092_software_version.SoftwareVersionModule;
import org.apache.vysper.xmpp.modules.extension.xep0202_entity_time.EntityTimeModule;
+import org.apache.vysper.storage.jcr.JcrStorage;
+import org.apache.vysper.storage.jcr.user.JcrUserManagement;
import java.io.File;
@@ -34,19 +36,23 @@
* found on the classpath
* @param args
*/
- public static void main(String[] args) {
+ public static void main(String[] args) throws AccountCreationException {
//new ClassPathXmlApplicationContext("spring-config.xml");
- SimpleUserAuthorization userAuthorization = new SimpleUserAuthorization();
- userAuthorization.addUser("user1@vysper.org", "password1");
- userAuthorization.addUser("user2@vysper.org", "password1");
- userAuthorization.addUser("user3@vysper.org", "password1");
+ final JcrStorage jcrStorage = JcrStorage.getInstance();
+ final JcrUserManagement userManagement = new JcrUserManagement(jcrStorage);
+
+ //SimpleUserAuthorization userManagement = new SimpleUserAuthorization();
+
+ //userManagement.addUser("user1@vysper.org", "password1");
+ //userManagement.addUser("user2@vysper.org", "password1");
+ //userManagement.addUser("user3@vysper.org", "password1");
XMPPServer server = new XMPPServer("vysper.org");
server.addEndpoint(new TCPEndpoint());
server.addEndpoint(new StanzaSessionFactory());
- server.setUserAuthorization(userAuthorization);
- server.setAccountVerification(userAuthorization);
+ server.setUserAuthorization(userManagement);
+ server.setAccountVerification(userManagement);
server.setTLSCertificateInfo(new File("src/main/config/bogus_mina_tls.cert"), "boguspw");
@@ -60,4 +66,4 @@
server.addModule(new SoftwareVersionModule());
server.addModule(new EntityTimeModule());
}
-}
\ No newline at end of file
+}
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@labs.apache.org
For additional commands, e-mail: commits-help@labs.apache.org