You are viewing a plain text version of this content. The canonical link for it is here.
Posted to server-dev@james.apache.org by no...@apache.org on 2010/01/09 11:16:37 UTC

svn commit: r897410 - in /james/server/trunk: ./ imapserver-function/ imapserver-function/src/main/java/org/apache/james/imapserver/ imapserver-function/src/main/java/org/apache/james/mailboxmanager/torque/ spring-deployment/src/main/config/james/ stag...

Author: norman
Date: Sat Jan  9 10:16:36 2010
New Revision: 897410

URL: http://svn.apache.org/viewvc?rev=897410&view=rev
Log:
More refactoring of imapserver stuff to allow easier exchange and reuse of components
upgrade imap snapshots

Added:
    james/server/trunk/imapserver-function/src/main/java/org/apache/james/imapserver/UserMetaDataRepositorySubscripter.java
    james/server/trunk/imapserver-function/src/main/java/org/apache/james/imapserver/UserRepositoryAuthenticator.java
    james/server/trunk/stage/org.apache.james/poms/apache-james-imap-store-0.1-SNAPSHOT.pom
Removed:
    james/server/trunk/imapserver-function/src/main/java/org/apache/james/mailboxmanager/torque/DefaultUserManager.java
Modified:
    james/server/trunk/imapserver-function/pom.xml
    james/server/trunk/imapserver-function/src/main/java/org/apache/james/mailboxmanager/torque/DefaultMailboxManager.java
    james/server/trunk/pom.xml
    james/server/trunk/spring-deployment/src/main/config/james/spring-beans.xml
    james/server/trunk/stage/org.apache.james/jars/apache-james-imap-store-0.1-SNAPSHOT.jar
    james/server/trunk/stage/org.apache.james/jars/apache-james-imap-torque-0.1-SNAPSHOT.jar
    james/server/trunk/stage/org.apache.james/poms/apache-james-imap-torque-0.1-SNAPSHOT.pom
    james/server/trunk/stage/pom.xml

Modified: james/server/trunk/imapserver-function/pom.xml
URL: http://svn.apache.org/viewvc/james/server/trunk/imapserver-function/pom.xml?rev=897410&r1=897409&r2=897410&view=diff
==============================================================================
--- james/server/trunk/imapserver-function/pom.xml (original)
+++ james/server/trunk/imapserver-function/pom.xml Sat Jan  9 10:16:36 2010
@@ -95,6 +95,10 @@
     </dependency>
     <dependency>
       <groupId>org.apache.james</groupId>
+      <artifactId>apache-james-imap-store</artifactId>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.james</groupId>
       <artifactId>apache-james-imap-processor</artifactId>
     </dependency>
     <dependency>

Added: james/server/trunk/imapserver-function/src/main/java/org/apache/james/imapserver/UserMetaDataRepositorySubscripter.java
URL: http://svn.apache.org/viewvc/james/server/trunk/imapserver-function/src/main/java/org/apache/james/imapserver/UserMetaDataRepositorySubscripter.java?rev=897410&view=auto
==============================================================================
--- james/server/trunk/imapserver-function/src/main/java/org/apache/james/imapserver/UserMetaDataRepositorySubscripter.java (added)
+++ james/server/trunk/imapserver-function/src/main/java/org/apache/james/imapserver/UserMetaDataRepositorySubscripter.java Sat Jan  9 10:16:36 2010
@@ -0,0 +1,159 @@
+/****************************************************************
+ * 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.james.imapserver;
+
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Map;
+
+import javax.annotation.Resource;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.james.api.user.UserMetaDataRespository;
+import org.apache.james.api.user.UserRepositoryException;
+import org.apache.james.imap.api.display.HumanReadableText;
+import org.apache.james.imap.mailbox.SubscriptionException;
+import org.apache.james.imap.store.Subscriber;
+
+public class UserMetaDataRepositorySubscripter implements Subscriber {
+
+    public static final String META_DATA_KEY = "org.apache.james.IMAP_SUBSCRIPTIONS";
+
+    private Log log = LogFactory.getLog(UserMetaDataRepositorySubscripter.class);
+
+    private UserMetaDataRespository repository;
+    private final Map userSubscriptionsByUser;
+
+    public UserMetaDataRepositorySubscripter() {
+        userSubscriptionsByUser = new HashMap();
+    }
+
+    @Resource(name = "userMetaDataRepository")
+    public void setUserMetaDataRespository(UserMetaDataRespository repository) {
+        this.repository = repository;
+    }
+    
+    /*
+     * (non-Javadoc)
+     * @see org.apache.james.imap.store.Subscriber#subscribe(java.lang.String, java.lang.String)
+     */
+    public void subscribe(String user, String mailbox) throws SubscriptionException {
+        try {
+            final UserSubscription subscription = getUserSubscription(user);
+            subscription.subscribe(mailbox);
+        } catch (UserRepositoryException e) {
+            throw new SubscriptionException(HumanReadableText.GENERIC_SUBSCRIPTION_FAILURE, e);
+        }
+    }
+
+    /*
+     * (non-Javadoc)
+     * @see org.apache.james.imap.store.Subscriber#subscriptions(java.lang.String)
+     */
+    @SuppressWarnings("unchecked")
+    public Collection<String> subscriptions(String user) throws SubscriptionException {
+        try {
+            final UserSubscription subscription = getUserSubscription(user);
+            final Collection<String> results = (Collection) subscription.subscriptions().clone();
+            return results;
+        } catch (UserRepositoryException e) {
+            throw new SubscriptionException(HumanReadableText.GENERIC_SUBSCRIPTION_FAILURE, e);
+        }
+    }
+
+    /*
+     * (non-Javadoc)
+     * @see org.apache.james.imap.store.Subscriber#unsubscribe(java.lang.String, java.lang.String)
+     */
+    public void unsubscribe(String user, String mailbox) throws SubscriptionException {
+        try {
+            final UserSubscription subscription = getUserSubscription(user);
+            subscription.unsubscribe(mailbox);
+        } catch (UserRepositoryException e) {
+            throw new SubscriptionException(HumanReadableText.GENERIC_UNSUBSCRIPTION_FAILURE, e);
+        }
+    }
+
+    private synchronized UserSubscription getUserSubscription(final String user) {
+        UserSubscription subscription = (UserSubscription) userSubscriptionsByUser.get(user);
+        if (subscription == null) {
+            subscription = new UserSubscription(user, repository, log);
+        }
+        return subscription;
+    }
+
+    /**
+     * Manages subscriptions for a user. Subscriptions are stored in a single
+     * collection. This class synchronizes access for write operations.
+     */
+    private static final class UserSubscription {
+
+        private final String user;
+        private final UserMetaDataRespository repository;
+        private Log log;
+
+        public UserSubscription(final String user, final UserMetaDataRespository repository, Log log) {
+            super();
+            this.user = user;
+            this.repository = repository;
+        }
+
+        public synchronized void subscribe(String mailbox) throws UserRepositoryException {
+            final HashSet<String> existingSubscriptions = subscriptions();
+            if (!existingSubscriptions.contains(mailbox)) {
+                final HashSet newSubscriptions;
+                if (existingSubscriptions == null) {
+                    newSubscriptions = new HashSet();
+                } else {
+                    existingSubscriptions.add(mailbox);
+                    newSubscriptions = existingSubscriptions;
+                }
+                repository.setAttribute(user, newSubscriptions, META_DATA_KEY);
+            }
+        }
+
+        public synchronized void unsubscribe(String mailbox) throws UserRepositoryException {
+            final HashSet subscriptions = subscriptions();
+            if (subscriptions.remove(mailbox)) {
+                repository.setAttribute(user, subscriptions, META_DATA_KEY);
+            }
+        }
+
+        public HashSet<String> subscriptions() throws UserRepositoryException {
+            try {
+                final HashSet<String> storedSubscriptions = (HashSet<String>) repository.getAttribute(user, META_DATA_KEY);
+                final HashSet<String> results;
+                if (storedSubscriptions == null) {
+                    results = new HashSet<String>();
+                } else {
+                    results = storedSubscriptions;
+                }
+                return results;
+            } catch (ClassCastException e) {
+                log.error("ClassCastException during retrieval. Reseting subscriptions for user " + user);
+                log.debug("HashSet expected but not retrieved.", e);
+                return new HashSet<String>();
+            }
+        }
+    }
+
+}

Added: james/server/trunk/imapserver-function/src/main/java/org/apache/james/imapserver/UserRepositoryAuthenticator.java
URL: http://svn.apache.org/viewvc/james/server/trunk/imapserver-function/src/main/java/org/apache/james/imapserver/UserRepositoryAuthenticator.java?rev=897410&view=auto
==============================================================================
--- james/server/trunk/imapserver-function/src/main/java/org/apache/james/imapserver/UserRepositoryAuthenticator.java (added)
+++ james/server/trunk/imapserver-function/src/main/java/org/apache/james/imapserver/UserRepositoryAuthenticator.java Sat Jan  9 10:16:36 2010
@@ -0,0 +1,48 @@
+/****************************************************************
+ * 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.james.imapserver;
+
+import javax.annotation.Resource;
+
+import org.apache.james.api.user.UsersRepository;
+import org.apache.james.imap.store.Authenticator;
+
+/**
+ * Authenticator which use an UsersRepository to check if the user and password match
+ *
+ */
+public class UserRepositoryAuthenticator implements Authenticator{
+
+    private UsersRepository repos;
+
+    @Resource(name="localusersrepository")
+    public void setUsersRepository(UsersRepository repos) {
+        this.repos = repos;
+    }
+
+    /*
+     * (non-Javadoc)
+     * @see org.apache.james.imap.store.Authenticator#isAuthentic(java.lang.String, java.lang.CharSequence)
+     */
+    public boolean isAuthentic(String userid, CharSequence passwd) {
+        return repos.test(userid, passwd.toString());
+    }
+    
+}

Modified: james/server/trunk/imapserver-function/src/main/java/org/apache/james/mailboxmanager/torque/DefaultMailboxManager.java
URL: http://svn.apache.org/viewvc/james/server/trunk/imapserver-function/src/main/java/org/apache/james/mailboxmanager/torque/DefaultMailboxManager.java?rev=897410&r1=897409&r2=897410&view=diff
==============================================================================
--- james/server/trunk/imapserver-function/src/main/java/org/apache/james/mailboxmanager/torque/DefaultMailboxManager.java (original)
+++ james/server/trunk/imapserver-function/src/main/java/org/apache/james/mailboxmanager/torque/DefaultMailboxManager.java Sat Jan  9 10:16:36 2010
@@ -35,6 +35,8 @@
 import org.apache.commons.logging.Log;
 import org.apache.james.imap.api.display.HumanReadableText;
 import org.apache.james.imap.mailbox.MailboxException;
+import org.apache.james.imap.store.Authenticator;
+import org.apache.james.imap.store.Subscriber;
 import org.apache.james.lifecycle.Configurable;
 import org.apache.james.lifecycle.LogEnabled;
 import org.apache.james.mailboxmanager.torque.om.MailboxRowPeer;
@@ -61,8 +63,8 @@
 
     private String torqueFile;
     
-    public DefaultMailboxManager(UserManager userManager) {
-        super(userManager);       
+    public DefaultMailboxManager(Authenticator authenticator, Subscriber subscripters) {
+        super(authenticator, subscripters);       
     }
 
     @Resource(name="filesystem")

Modified: james/server/trunk/pom.xml
URL: http://svn.apache.org/viewvc/james/server/trunk/pom.xml?rev=897410&r1=897409&r2=897410&view=diff
==============================================================================
--- james/server/trunk/pom.xml (original)
+++ james/server/trunk/pom.xml Sat Jan  9 10:16:36 2010
@@ -490,6 +490,11 @@
     </dependency>
     <dependency>
       <groupId>org.apache.james</groupId>
+      <artifactId>apache-james-imap-store</artifactId>
+      <version>0.1-SNAPSHOT</version>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.james</groupId>
       <artifactId>apache-james-imap-processor</artifactId>
       <version>0.1-SNAPSHOT</version>
     </dependency>

Modified: james/server/trunk/spring-deployment/src/main/config/james/spring-beans.xml
URL: http://svn.apache.org/viewvc/james/server/trunk/spring-deployment/src/main/config/james/spring-beans.xml?rev=897410&r1=897409&r2=897410&view=diff
==============================================================================
--- james/server/trunk/spring-deployment/src/main/config/james/spring-beans.xml (original)
+++ james/server/trunk/spring-deployment/src/main/config/james/spring-beans.xml Sat Jan  9 10:16:36 2010
@@ -331,10 +331,13 @@
     <bean id="imapEncoder" factory-bean="imapEncoderFactory"  factory-method="buildImapEncoder"/>
        
 	<bean id="mailboxmanager" class="org.apache.james.mailboxmanager.torque.DefaultMailboxManager">
-		 	<constructor-arg index="0" ref="userManager"/>
+		 	<constructor-arg index="0" ref="authenticator"/>
+		 	<constructor-arg index="1" ref="subscriper"/>
 	</bean>
 	
-    <bean id="userManager" class="org.apache.james.mailboxmanager.torque.DefaultUserManager"/>
+	<bean id="subscriper" class="org.apache.james.imapserver.UserMetaDataRepositorySubscripter"/>
+		
+	<bean id="authenticator" class="org.apache.james.imapserver.UserRepositoryAuthenticator"/>
 	
 	<bean id="userMetaDataRepository" class="org.apache.james.user.impl.file.FileUserMetaDataRepository">
 	 	<constructor-arg index="0" value="var/users"/>

Modified: james/server/trunk/stage/org.apache.james/jars/apache-james-imap-store-0.1-SNAPSHOT.jar
URL: http://svn.apache.org/viewvc/james/server/trunk/stage/org.apache.james/jars/apache-james-imap-store-0.1-SNAPSHOT.jar?rev=897410&r1=897409&r2=897410&view=diff
==============================================================================
Binary files - no diff available.

Modified: james/server/trunk/stage/org.apache.james/jars/apache-james-imap-torque-0.1-SNAPSHOT.jar
URL: http://svn.apache.org/viewvc/james/server/trunk/stage/org.apache.james/jars/apache-james-imap-torque-0.1-SNAPSHOT.jar?rev=897410&r1=897409&r2=897410&view=diff
==============================================================================
Binary files - no diff available.

Added: james/server/trunk/stage/org.apache.james/poms/apache-james-imap-store-0.1-SNAPSHOT.pom
URL: http://svn.apache.org/viewvc/james/server/trunk/stage/org.apache.james/poms/apache-james-imap-store-0.1-SNAPSHOT.pom?rev=897410&view=auto
==============================================================================
--- james/server/trunk/stage/org.apache.james/poms/apache-james-imap-store-0.1-SNAPSHOT.pom (added)
+++ james/server/trunk/stage/org.apache.james/poms/apache-james-imap-store-0.1-SNAPSHOT.pom Sat Jan  9 10:16:36 2010
@@ -0,0 +1,69 @@
+<?xml version="1.0" encoding="ISO-8859-15"?>
+<!--
+  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>
+  <parent>
+    <artifactId>apache-james-imap-parent</artifactId>
+    <groupId>org.apache.james</groupId>
+    <version>0.1-SNAPSHOT</version>
+    <relativePath>../parent/pom.xml</relativePath>
+  </parent>
+  <modelVersion>4.0.0</modelVersion>
+  <groupId>org.apache.james</groupId>
+  <artifactId>apache-james-imap-store</artifactId>
+  <name>Apache James IMAP Mailbox Store Framework</name>
+  <dependencies>
+    <dependency>
+      <groupId>${javax.mail.groupId}</groupId>
+      <artifactId>${javax.mail.artifactId}</artifactId>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.james</groupId>
+      <artifactId>apache-james-imap-api</artifactId>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.james</groupId>
+      <artifactId>apache-james-imap-mailbox</artifactId>
+    </dependency>
+
+    <dependency>
+      <groupId>org.apache.james</groupId>
+      <artifactId>apache-mime4j</artifactId>
+    </dependency>
+
+    <dependency>
+      <groupId>commons-logging</groupId>
+      <artifactId>commons-logging</artifactId>
+    </dependency>
+    <dependency>
+      <groupId>commons-lang</groupId>
+      <artifactId>commons-lang</artifactId>
+    </dependency>
+    <dependency>
+      <groupId>commons-collections</groupId>
+      <artifactId>commons-collections</artifactId>
+    </dependency>
+    
+    <dependency>
+      <groupId>junit</groupId>
+      <artifactId>junit</artifactId>
+      <scope>test</scope>
+    </dependency>
+  </dependencies>
+</project>

Modified: james/server/trunk/stage/org.apache.james/poms/apache-james-imap-torque-0.1-SNAPSHOT.pom
URL: http://svn.apache.org/viewvc/james/server/trunk/stage/org.apache.james/poms/apache-james-imap-torque-0.1-SNAPSHOT.pom?rev=897410&r1=897409&r2=897410&view=diff
==============================================================================
--- james/server/trunk/stage/org.apache.james/poms/apache-james-imap-torque-0.1-SNAPSHOT.pom (original)
+++ james/server/trunk/stage/org.apache.james/poms/apache-james-imap-torque-0.1-SNAPSHOT.pom Sat Jan  9 10:16:36 2010
@@ -19,9 +19,10 @@
 -->
 <project>
   <parent>
-    <artifactId>apache-james-imap</artifactId>
+    <artifactId>apache-james-imap-parent</artifactId>
     <groupId>org.apache.james</groupId>
     <version>0.1-SNAPSHOT</version>
+    <relativePath>../parent/pom.xml</relativePath>
   </parent>
   <modelVersion>4.0.0</modelVersion>
   <groupId>org.apache.james</groupId>
@@ -40,15 +41,19 @@
       <groupId>org.apache.james</groupId>
       <artifactId>apache-james-imap-mailbox</artifactId>
     </dependency>
-
+    <dependency>
+      <groupId>org.apache.james</groupId>
+      <artifactId>apache-james-imap-store</artifactId>
+    </dependency>
+    
     <dependency>
       <groupId>org.apache.james</groupId>
       <artifactId>apache-mime4j</artifactId>
     </dependency>
     
     <dependency>
-      <groupId>org.apache.db.torque</groupId>
-      <artifactId>runtime</artifactId>
+      <groupId>org.apache.torque</groupId>
+      <artifactId>torque-runtime</artifactId>
     </dependency>
 
     <dependency>
@@ -60,13 +65,10 @@
       <artifactId>commons-lang</artifactId>
     </dependency>
     <dependency>
-      <groupId>village</groupId>
+      <groupId>org.apache.torque</groupId>
       <artifactId>village</artifactId>
     </dependency>
-    <dependency>
-      <groupId>concurrent</groupId>
-      <artifactId>concurrent</artifactId>
-    </dependency>
+
     <dependency>
       <groupId>commons-collections</groupId>
       <artifactId>commons-collections</artifactId>
@@ -77,5 +79,12 @@
       <artifactId>junit</artifactId>
       <scope>test</scope>
     </dependency>
+    
+    <dependency>
+      <groupId>org.apache.james</groupId>
+      <artifactId>apache-james-imap-store</artifactId>
+      <type>test-jar</type>
+      <scope>test</scope>
+    </dependency>
   </dependencies>
 </project>

Modified: james/server/trunk/stage/pom.xml
URL: http://svn.apache.org/viewvc/james/server/trunk/stage/pom.xml?rev=897410&r1=897409&r2=897410&view=diff
==============================================================================
--- james/server/trunk/stage/pom.xml (original)
+++ james/server/trunk/stage/pom.xml Sat Jan  9 10:16:36 2010
@@ -93,6 +93,10 @@
       <groupId>org.apache.james</groupId>
       <artifactId>apache-james-imap-torque</artifactId>
     </dependency>
+    <dependency>
+      <groupId>org.apache.james</groupId>
+      <artifactId>apache-james-imap-store</artifactId>
+    </dependency>
     <!-- TODO test the updated version
     <dependency>
       <groupId>bouncycastle</groupId>



---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org