jackrabbit-oak-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ang...@apache.org
Subject svn commit: r1372944 - in /jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/authentication/token: TokenProvider.java TokenProviderImpl.java
Date Tue, 14 Aug 2012 15:51:00 GMT
Author: angela
Date: Tue Aug 14 15:50:59 2012
New Revision: 1372944

URL: http://svn.apache.org/viewvc?rev=1372944&view=rev
Log:
 OAK-91 - Implement Authentication Support (WIP)

Modified:
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/authentication/token/TokenProvider.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/authentication/token/TokenProviderImpl.java

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/authentication/token/TokenProvider.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/authentication/token/TokenProvider.java?rev=1372944&r1=1372943&r2=1372944&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/authentication/token/TokenProvider.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/authentication/token/TokenProvider.java
Tue Aug 14 15:50:59 2012
@@ -16,6 +16,7 @@
  */
 package org.apache.jackrabbit.oak.security.authentication.token;
 
+import javax.annotation.CheckForNull;
 import javax.jcr.Credentials;
 
 /**
@@ -30,8 +31,10 @@ public interface TokenProvider {
 
     boolean doCreateToken(Credentials credentials);
 
+    @CheckForNull
     TokenInfo createToken(Credentials credentials);
 
+    @CheckForNull
     TokenInfo getTokenInfo(String token);
 
     boolean removeToken(TokenInfo tokenInfo);

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/authentication/token/TokenProviderImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/authentication/token/TokenProviderImpl.java?rev=1372944&r1=1372943&r2=1372944&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/authentication/token/TokenProviderImpl.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/authentication/token/TokenProviderImpl.java
Tue Aug 14 15:50:59 2012
@@ -26,13 +26,11 @@ import java.util.Collections;
 import java.util.Date;
 import java.util.GregorianCalendar;
 import java.util.HashMap;
-import java.util.Iterator;
 import java.util.Map;
-import java.util.UUID;
 import javax.jcr.Credentials;
 import javax.jcr.PropertyType;
+import javax.jcr.RepositoryException;
 import javax.jcr.SimpleCredentials;
-import javax.jcr.query.Query;
 
 import org.apache.jackrabbit.JcrConstants;
 import org.apache.jackrabbit.api.security.authentication.token.TokenCredentials;
@@ -41,13 +39,12 @@ import org.apache.jackrabbit.oak.api.Con
 import org.apache.jackrabbit.oak.api.CoreValue;
 import org.apache.jackrabbit.oak.api.CoreValueFactory;
 import org.apache.jackrabbit.oak.api.PropertyState;
-import org.apache.jackrabbit.oak.api.QueryEngine;
-import org.apache.jackrabbit.oak.api.Result;
-import org.apache.jackrabbit.oak.api.ResultRow;
 import org.apache.jackrabbit.oak.api.Root;
 import org.apache.jackrabbit.oak.api.Tree;
 import org.apache.jackrabbit.oak.core.DefaultConflictHandler;
+import org.apache.jackrabbit.oak.security.user.UserProviderImpl;
 import org.apache.jackrabbit.oak.spi.security.user.PasswordUtility;
+import org.apache.jackrabbit.oak.spi.security.user.UserProvider;
 import org.apache.jackrabbit.util.ISO8601;
 import org.apache.jackrabbit.util.Text;
 import org.slf4j.Logger;
@@ -105,12 +102,11 @@ public class TokenProviderImpl implement
         if (credentials instanceof SimpleCredentials) {
             final SimpleCredentials sc = (SimpleCredentials) credentials;
             String userID = sc.getUserID();
-            String userPath = getUserPath(contentSession, userID);
 
             Root root = contentSession.getCurrentRoot();
-            Tree userTree = (userPath == null) ? null : root.getTree(userPath);
-            if (userTree != null) {
-                try {
+            try {
+                Tree userTree = getUserTree(contentSession, root, userID);
+                if (userTree != null) {
                     Tree tokenParent = userTree.getChild(TOKENS_NODE_NAME);
                     if (tokenParent == null) {
                         tokenParent = userTree.addChild(TOKENS_NODE_NAME);
@@ -144,16 +140,18 @@ public class TokenProviderImpl implement
                     // also set the new token to the simple credentials.
                     sc.setAttribute(TOKEN_ATTRIBUTE, token);
                     return new TokenInfoImpl(tokenTree, token);
-
-                } catch (NoSuchAlgorithmException e) {
-                    log.debug("Failed to create login token ", e.getMessage());
-                } catch (UnsupportedEncodingException e) {
-                    log.debug("Failed to create login token ", e.getMessage());
-                } catch (CommitFailedException e) {
-                    log.debug("Failed to create login token ", e.getMessage());
+                } else {
+                    log.debug("Cannot create login token: No corresponding node for User
" + userID + '.');
                 }
-            } else {
-                log.debug("Cannot create login token: No corresponding node for User " +
userID + '.');
+
+            } catch (NoSuchAlgorithmException e) {
+                log.debug("Failed to create login token ", e.getMessage());
+            } catch (UnsupportedEncodingException e) {
+                log.debug("Failed to create login token ", e.getMessage());
+            } catch (CommitFailedException e) {
+                log.debug("Failed to create login token ", e.getMessage());
+            } catch (RepositoryException e) {
+                log.debug("Failed to create login token ", e.getMessage());
             }
         }
 
@@ -246,23 +244,9 @@ public class TokenProviderImpl implement
         }
     }
 
-    // TODO: move to user related oak-spi that is used both by JCR usermanagement
-    // and oak-level functionality.
-    private static String getUserPath(ContentSession contentSession, String userID) {
-        QueryEngine qe = contentSession.getQueryEngine();
-        try {
-            String uuid = UUID.nameUUIDFromBytes(userID.toLowerCase().getBytes("UTF-8")).toString();
-            Map<String, CoreValue> bindings = Collections.singletonMap("id", contentSession.getCoreValueFactory().createValue(uuid));
-            String statement = "SELECT * FROM [rep:User] WHERE [jcr:uuid] = $id";
-            Result result = contentSession.getQueryEngine().executeQuery(statement, Query.JCR_SQL2,
contentSession, Long.MAX_VALUE, 0, bindings, null);
-            Iterator<? extends ResultRow> it = result.getRows().iterator();
-            if (it.hasNext()) {
-                return it.next().getPath();
-            }
-        } catch (Exception e) {
-            // no such user.
-        }
-        return null;
+    private static Tree getUserTree(ContentSession contentSession, Root root, String userID)
throws RepositoryException {
+        UserProvider userProvider = new UserProviderImpl(contentSession, root, null);
+        return userProvider.getAuthorizable(userID);
     }
 
     //--------------------------------------------------------------------------



Mime
View raw message