jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bae...@apache.org
Subject svn commit: r1605781 - in /jackrabbit/branches/2.6: ./ jackrabbit-core/src/main/java/org/apache/jackrabbit/core/security/authentication/token/ jackrabbit-core/src/test/java/org/apache/jackrabbit/core/security/authentication/token/
Date Thu, 26 Jun 2014 13:30:09 GMT
Author: baedke
Date: Thu Jun 26 13:30:08 2014
New Revision: 1605781

URL: http://svn.apache.org/r1605781
Log:
JCR-3761 : TokenInfo#resetExpiration always fails with ConstraintViolationException

Added:
    jackrabbit/branches/2.6/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/security/authentication/token/TokenProviderTest.java
      - copied, changed from r1582373, jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/security/authentication/token/TokenProviderTest.java
Modified:
    jackrabbit/branches/2.6/   (props changed)
    jackrabbit/branches/2.6/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/security/authentication/token/TokenProvider.java
    jackrabbit/branches/2.6/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/security/authentication/token/TestAll.java

Propchange: jackrabbit/branches/2.6/
------------------------------------------------------------------------------
  Merged /jackrabbit/trunk:r1582373,1603934

Modified: jackrabbit/branches/2.6/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/security/authentication/token/TokenProvider.java
URL: http://svn.apache.org/viewvc/jackrabbit/branches/2.6/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/security/authentication/token/TokenProvider.java?rev=1605781&r1=1605780&r2=1605781&view=diff
==============================================================================
--- jackrabbit/branches/2.6/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/security/authentication/token/TokenProvider.java
(original)
+++ jackrabbit/branches/2.6/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/security/authentication/token/TokenProvider.java
Thu Jun 26 13:30:08 2014
@@ -38,6 +38,7 @@ import javax.jcr.PropertyIterator;
 import javax.jcr.RepositoryException;
 import javax.jcr.Session;
 import javax.jcr.SimpleCredentials;
+import javax.jcr.Value;
 import javax.jcr.ValueFactory;
 
 import org.apache.jackrabbit.api.security.authentication.token.TokenCredentials;
@@ -161,7 +162,7 @@ public class TokenProvider extends Prote
 
                 String keyHash = PasswordUtility.buildPasswordHash(getKeyValue(key, user.getID()));
                 setProperty(tokenNode, session.getQName(TOKEN_ATTRIBUTE_KEY), vf.createValue(keyHash));
-                setProperty(tokenNode, session.getQName(TOKEN_ATTRIBUTE_EXPIRY), vf.createValue(createExpirationValue(creationTime)));
+                setProperty(tokenNode, session.getQName(TOKEN_ATTRIBUTE_EXPIRY), createExpirationValue(creationTime,
session));
 
                 for (String name : attributes.keySet()) {
                     if (!RESERVED_ATTRIBUTES.contains(name)) {
@@ -186,10 +187,10 @@ public class TokenProvider extends Prote
         return null;
     }
 
-    private Calendar createExpirationValue(long creationTime) {
+    private Value createExpirationValue(long creationTime, Session session) throws RepositoryException
{
         Calendar cal = Calendar.getInstance();
         cal.setTimeInMillis(createExpirationTime(creationTime, tokenExpiration));
-        return cal;
+        return session.getValueFactory().createValue(cal);
     }
 
     /**
@@ -400,7 +401,7 @@ public class TokenProvider extends Prote
             try {
                 if (expirationTime - loginTime <= tokenExpiration / 2) {
                     s = session.createSession(session.getWorkspace().getName());
-                    s.getNode(tokenPath).setProperty(TOKEN_ATTRIBUTE_EXPIRY, createExpirationValue(loginTime));
+                    setProperty((NodeImpl) s.getNode(tokenPath), session.getQName(TOKEN_ATTRIBUTE_EXPIRY),
createExpirationValue(loginTime, session));
                     s.save();
                     log.debug("Successfully reset token expiration time.");
                     return true;

Modified: jackrabbit/branches/2.6/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/security/authentication/token/TestAll.java
URL: http://svn.apache.org/viewvc/jackrabbit/branches/2.6/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/security/authentication/token/TestAll.java?rev=1605781&r1=1605780&r2=1605781&view=diff
==============================================================================
--- jackrabbit/branches/2.6/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/security/authentication/token/TestAll.java
(original)
+++ jackrabbit/branches/2.6/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/security/authentication/token/TestAll.java
Thu Jun 26 13:30:08 2014
@@ -35,6 +35,7 @@ public class TestAll extends TestCase {
         suite.addTestSuite(TokenBasedAuthenticationCompatTest.class);
         suite.addTestSuite(TokenBasedAuthenticationTest.class);
         suite.addTestSuite(TokenBasedLoginTest.class);
+        suite.addTestSuite(TokenProviderTest.class);
 
         return suite;
     }

Copied: jackrabbit/branches/2.6/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/security/authentication/token/TokenProviderTest.java
(from r1582373, jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/security/authentication/token/TokenProviderTest.java)
URL: http://svn.apache.org/viewvc/jackrabbit/branches/2.6/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/security/authentication/token/TokenProviderTest.java?p2=jackrabbit/branches/2.6/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/security/authentication/token/TokenProviderTest.java&p1=jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/security/authentication/token/TokenProviderTest.java&r1=1582373&r2=1605781&rev=1605781&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/security/authentication/token/TokenProviderTest.java
(original)
+++ jackrabbit/branches/2.6/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/security/authentication/token/TokenProviderTest.java
Thu Jun 26 13:30:08 2014
@@ -154,7 +154,7 @@ public class TokenProviderTest extends A
     public void testIsExpired() throws Exception {
         TokenInfo info = tokenProvider.createToken(testuser, new SimpleCredentials(userId,
userId.toCharArray()));
 
-        long loginTime = System.currentTimeMillis();
+        long loginTime = waitForSystemTimeIncrement(System.currentTimeMillis());
         assertFalse(info.isExpired(loginTime));
         assertTrue(info.isExpired(loginTime + TokenBasedAuthentication.TOKEN_EXPIRATION));
     }
@@ -163,7 +163,7 @@ public class TokenProviderTest extends A
         TokenInfo info = tokenProvider.createToken(testuser, new SimpleCredentials(userId,
userId.toCharArray()));
         long expTime = getTokenNode(info).getProperty("rep:token.exp").getLong();
 
-        long loginTime = System.currentTimeMillis();
+        long loginTime = waitForSystemTimeIncrement(System.currentTimeMillis());
         assertFalse(info.resetExpiration(loginTime));
         assertFalse(info.resetExpiration(loginTime + TokenBasedAuthentication.TOKEN_EXPIRATION));
 
@@ -182,4 +182,11 @@ public class TokenProviderTest extends A
     private Node getTokenNode(TokenInfo info) throws RepositoryException {
         return TokenProvider.getTokenNode(info.getToken(), session);
     }
+
+    private static long waitForSystemTimeIncrement(long old){
+        while (old == System.currentTimeMillis()) {
+            // wait for system timer to move
+        }
+        return System.currentTimeMillis();
+    }
 }
\ No newline at end of file



Mime
View raw message