james-server-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From nor...@apache.org
Subject svn commit: r952180 - in /james/imap/trunk/jcr/src/main/java/org/apache/james/imap/jcr: JCRRepositoryAuthenticator.java MailboxSessionJCRRepository.java
Date Mon, 07 Jun 2010 10:27:58 GMT
Author: norman
Date: Mon Jun  7 10:27:57 2010
New Revision: 952180

URL: http://svn.apache.org/viewvc?rev=952180&view=rev
Log:
Add Authenticator implementation which use the JCR Repository for check if a user exists

Added:
    james/imap/trunk/jcr/src/main/java/org/apache/james/imap/jcr/JCRRepositoryAuthenticator.java
Modified:
    james/imap/trunk/jcr/src/main/java/org/apache/james/imap/jcr/MailboxSessionJCRRepository.java

Added: james/imap/trunk/jcr/src/main/java/org/apache/james/imap/jcr/JCRRepositoryAuthenticator.java
URL: http://svn.apache.org/viewvc/james/imap/trunk/jcr/src/main/java/org/apache/james/imap/jcr/JCRRepositoryAuthenticator.java?rev=952180&view=auto
==============================================================================
--- james/imap/trunk/jcr/src/main/java/org/apache/james/imap/jcr/JCRRepositoryAuthenticator.java
(added)
+++ james/imap/trunk/jcr/src/main/java/org/apache/james/imap/jcr/JCRRepositoryAuthenticator.java
Mon Jun  7 10:27:57 2010
@@ -0,0 +1,61 @@
+/****************************************************************
+ * 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.imap.jcr;
+
+import javax.jcr.Repository;
+import javax.jcr.RepositoryException;
+import javax.jcr.Session;
+import javax.jcr.SimpleCredentials;
+
+import org.apache.james.imap.store.Authenticator;
+
+/**
+ * {@link Authenticator} implementation which will try to log in the {@link Repository} and
obtain a Session. If this fails it will handle the 
+ * user/pass as invalid. If it success it will logout from the session again and handle the
user/pass as valid.
+ * 
+ * This implementation should be used if you want to handle the IMAP Users transparent to
the JCR Users. The use of the implementation only makes
+ * real sense in conjunction with the direct {@link MailboxSessionJCRRepository} implementation
(not a subclass).
+ *
+ */
+public class JCRRepositoryAuthenticator implements Authenticator{
+
+    private MailboxSessionJCRRepository repository;
+    
+    public JCRRepositoryAuthenticator(MailboxSessionJCRRepository repository) {
+        this.repository = repository;
+    }
+    
+    /*
+     * (non-Javadoc)
+     * @see org.apache.james.imap.store.Authenticator#isAuthentic(java.lang.String, java.lang.CharSequence)
+     */
+    public boolean isAuthentic(String userid, CharSequence passwd) {
+        Repository repos = repository.getRepository();
+        try {
+            // Try to log in the Repository with the user and password. If this success we
can asume that the user/pass is valid. In 
+            // all cases we need to logout again to not bind two JCR Session per thread later
+            Session session = repos.login(new SimpleCredentials(userid,passwd.toString().toCharArray()),
repository.getWorkspace());
+            session.logout();
+            return true;
+        } catch (RepositoryException e) {
+            return false;
+        }
+    }
+
+}

Modified: james/imap/trunk/jcr/src/main/java/org/apache/james/imap/jcr/MailboxSessionJCRRepository.java
URL: http://svn.apache.org/viewvc/james/imap/trunk/jcr/src/main/java/org/apache/james/imap/jcr/MailboxSessionJCRRepository.java?rev=952180&r1=952179&r2=952180&view=diff
==============================================================================
--- james/imap/trunk/jcr/src/main/java/org/apache/james/imap/jcr/MailboxSessionJCRRepository.java
(original)
+++ james/imap/trunk/jcr/src/main/java/org/apache/james/imap/jcr/MailboxSessionJCRRepository.java
Mon Jun  7 10:27:57 2010
@@ -28,7 +28,7 @@ import org.apache.james.imap.mailbox.Mai
 
 /**
  * Manage JCR {@link Session}. It use the username and the password of 
- * the logged in IMAP user to access the {@link Repository}
+ * the logged in IMAP user to obtain a JCR {@link Session} from the {@link Repository}
  *
  */
 public class MailboxSessionJCRRepository {
@@ -66,7 +66,7 @@ public class MailboxSessionJCRRepository
      * 
      * @return repository
      */
-    protected Repository getRepository() {
+    public Repository getRepository() {
         return repository;
     }
     
@@ -75,7 +75,7 @@ public class MailboxSessionJCRRepository
      * 
      * @return workspace
      */
-    protected String getWorkspace() {
+    public String getWorkspace() {
         return workspace;
     }
 }



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


Mime
View raw message