jackrabbit-oak-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ang...@apache.org
Subject svn commit: r1404546 - in /jackrabbit/oak/trunk/oak-core/src: main/java/org/apache/jackrabbit/oak/security/authentication/token/ main/resources/org/apache/jackrabbit/oak/plugins/nodetype/ test/java/org/apache/jackrabbit/oak/security/authentication/token/
Date Thu, 01 Nov 2012 11:25:28 GMT
Author: angela
Date: Thu Nov  1 11:25:27 2012
New Revision: 1404546

URL: http://svn.apache.org/viewvc?rev=1404546&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/TokenProviderImpl.java
    jackrabbit/oak/trunk/oak-core/src/main/resources/org/apache/jackrabbit/oak/plugins/nodetype/builtin_nodetypes.cnd
    jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/security/authentication/token/TokenInfoTest.java
    jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/security/authentication/token/TokenProviderImplTest.java

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=1404546&r1=1404545&r2=1404546&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
Thu Nov  1 11:25:27 2012
@@ -46,6 +46,7 @@ import org.apache.jackrabbit.oak.api.Roo
 import org.apache.jackrabbit.oak.api.Tree;
 import org.apache.jackrabbit.oak.namepath.NamePathMapper;
 import org.apache.jackrabbit.oak.plugins.identifier.IdentifierManager;
+import org.apache.jackrabbit.oak.plugins.name.NamespaceConstants;
 import org.apache.jackrabbit.oak.spi.security.ConfigurationParameters;
 import org.apache.jackrabbit.oak.spi.security.authentication.ImpersonationCredentials;
 import org.apache.jackrabbit.oak.spi.security.authentication.token.TokenInfo;
@@ -88,10 +89,11 @@ public class TokenProviderImpl implement
      * trigger the generation of a new token.
      */
     private static final String TOKEN_ATTRIBUTE = ".token";
-    private static final String TOKEN_ATTRIBUTE_EXPIRY = TOKEN_ATTRIBUTE + ".exp";
-    private static final String TOKEN_ATTRIBUTE_KEY = TOKEN_ATTRIBUTE + ".key";
+    private static final String TOKEN_ATTRIBUTE_EXPIRY = "rep:token.exp";
+    private static final String TOKEN_ATTRIBUTE_KEY = "rep:token.key";
     private static final String TOKENS_NODE_NAME = ".tokens";
     private static final String TOKENS_NT_NAME = JcrConstants.NT_UNSTRUCTURED;
+    private static final String TOKEN_NT_NAME = "rep:Token";
 
     /**
      * Default expiration time in ms for login tokens is 2 hours.
@@ -171,8 +173,8 @@ public class TokenProviderImpl implement
                 creation.setTimeInMillis(creationTime);
                 String tokenName = Text.replace(ISO8601.format(creation), ":", ".");
 
-                NodeUtil tokenNode = tokenParent.addChild(tokenName, TOKENS_NT_NAME);
-                // TODO: review if token node should be made referenceable
+                NodeUtil tokenNode = tokenParent.addChild(tokenName, TOKEN_NT_NAME);
+                tokenNode.setString(JcrConstants.JCR_UUID, IdentifierManager.generateUUID());
 
                 String key = generateKey(options.getConfigValue(PARAM_TOKEN_LENGTH, DEFAULT_KEY_SIZE));
                 String nodeId = identifierManager.getIdentifier(tokenNode.getTree());
@@ -450,7 +452,7 @@ public class TokenProviderImpl implement
          */
         private static boolean isInfoAttribute(String propertyName) {
             String prefix = Text.getNamespacePrefix(propertyName);
-            return !"jcr".equals(prefix) && !"rep".equals(prefix);
+            return !NamespaceConstants.RESERVED_PREFIXES.contains(prefix);
         }
     }
 }

Modified: jackrabbit/oak/trunk/oak-core/src/main/resources/org/apache/jackrabbit/oak/plugins/nodetype/builtin_nodetypes.cnd
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/resources/org/apache/jackrabbit/oak/plugins/nodetype/builtin_nodetypes.cnd?rev=1404546&r1=1404545&r2=1404546&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/resources/org/apache/jackrabbit/oak/plugins/nodetype/builtin_nodetypes.cnd
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/resources/org/apache/jackrabbit/oak/plugins/nodetype/builtin_nodetypes.cnd
Thu Nov  1 11:25:27 2012
@@ -649,6 +649,15 @@
   - rep:isAbstract (BOOLEAN) protected
   - rep:aggregates (NAME) protected multiple
 
+// -----------------------------------------------------------------------------
+// Token Management
+// -----------------------------------------------------------------------------
+/**
+ * @since oak 1.0
+ */
+[rep:Token] > nt:unstructured, mix:referenceable
+  - rep:token.key (STRING) protected mandatory
+  - rep:token.exp (STRING) protected mandatory
 
 // -----------------------------------------------------------------------------
 // J A C K R A B B I T  R E T E N T I O N  M A N A G E M E N T

Modified: jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/security/authentication/token/TokenInfoTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/security/authentication/token/TokenInfoTest.java?rev=1404546&r1=1404545&r2=1404546&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/security/authentication/token/TokenInfoTest.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/security/authentication/token/TokenInfoTest.java
Thu Nov  1 11:25:27 2012
@@ -93,8 +93,8 @@ public class TokenInfoTest extends Abstr
     public void testGetAttributes() {
         Map<String, String> reserved = new HashMap<String, String>();
         reserved.put(".token", "value");
-        reserved.put(".token.key", "value");
-        reserved.put(".token.exp", "value");
+        reserved.put("rep:token.key", "value");
+        reserved.put("rep:token.exp", "value");
 
         Map<String, String> privateAttributes = new HashMap<String, String>();
         privateAttributes.put(".token_exp", "value");
@@ -113,22 +113,22 @@ public class TokenInfoTest extends Abstr
         TokenInfo info = tokenProvider.createToken(userId, attributes);
 
         Map<String,String> pubAttr = info.getPublicAttributes();
-        assertEquals(publicAttributes.size(), pubAttr.size());
+        assertEquals("public attributes",publicAttributes.size(), pubAttr.size());
         for (String key : publicAttributes.keySet()) {
-            assertTrue(pubAttr.containsKey(key));
-            assertEquals(publicAttributes.get(key), pubAttr.get(key));
+            assertTrue("public attribute "+key+" not contained",pubAttr.containsKey(key));
+            assertEquals("public attribute " + key,publicAttributes.get(key), pubAttr.get(key));
         }
 
         Map<String,String> privAttr = info.getPrivateAttributes();
-        assertEquals(privateAttributes.size(), privAttr.size());
+        assertEquals("private attributes",privateAttributes.size(), privAttr.size());
         for (String key : privateAttributes.keySet()) {
-            assertTrue(privAttr.containsKey(key));
-            assertEquals(privateAttributes.get(key), privAttr.get(key));
+            assertTrue("private attribute "+key+" not contained",privAttr.containsKey(key));
+            assertEquals("private attribute" + key,privateAttributes.get(key), privAttr.get(key));
         }
 
         for (String key : reserved.keySet()) {
-            assertFalse(privAttr.containsKey(key));
-            assertFalse(pubAttr.containsKey(key));
+            assertFalse("reserved attribute "+key,privAttr.containsKey(key));
+            assertFalse("reserved attribute "+key,pubAttr.containsKey(key));
         }
     }
 }
\ No newline at end of file

Modified: jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/security/authentication/token/TokenProviderImplTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/security/authentication/token/TokenProviderImplTest.java?rev=1404546&r1=1404545&r2=1404546&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/security/authentication/token/TokenProviderImplTest.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/security/authentication/token/TokenProviderImplTest.java
Thu Nov  1 11:25:27 2012
@@ -59,7 +59,7 @@ public class TokenProviderImplTest exten
         sc.setAttribute("any_attribute", "value");
         assertFalse(tokenProvider.doCreateToken(sc));
 
-        sc.setAttribute(".token_key", "value");
+        sc.setAttribute("rep:token_key", "value");
         assertFalse(tokenProvider.doCreateToken(sc));
 
         sc.setAttribute(".token", "existing");
@@ -111,8 +111,8 @@ public class TokenProviderImplTest exten
     public void testTokenNode() throws Exception {
         Map<String, String> reserved = new HashMap<String, String>();
         reserved.put(".token", "value");
-        reserved.put(".token.key", "value");
-        reserved.put(".token.exp", "value");
+        reserved.put("rep:token.key", "value");
+        reserved.put("rep:token.exp", "value");
 
         Map<String, String> privateAttributes = new HashMap<String, String>();
         privateAttributes.put(".token_exp", "value");
@@ -136,8 +136,8 @@ public class TokenProviderImplTest exten
         assertEquals(1, tokens.getChildrenCount());
 
         Tree tokenNode = tokens.getChildren().iterator().next();
-        assertNotNull(tokenNode.getProperty(".token.key"));
-        assertNotNull(tokenNode.getProperty(".token.exp"));
+        assertNotNull(tokenNode.getProperty("rep:token.key"));
+        assertNotNull(tokenNode.getProperty("rep:token.exp"));
 
         for (String key : reserved.keySet()) {
             PropertyState p = tokenNode.getProperty(key);



Mime
View raw message