Quantcast

cxf git commit: [CXF-7374] Re-enabling the test, This closes #273

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

cxf git commit: [CXF-7374] Re-enabling the test, This closes #273

sergeyb
Repository: cxf
Updated Branches:
  refs/heads/3.1.x-fixes 8d5d7e76e -> f747d09e9


[CXF-7374] Re-enabling the test, This closes #273


Project: http://git-wip-us.apache.org/repos/asf/cxf/repo
Commit: http://git-wip-us.apache.org/repos/asf/cxf/commit/f747d09e
Tree: http://git-wip-us.apache.org/repos/asf/cxf/tree/f747d09e
Diff: http://git-wip-us.apache.org/repos/asf/cxf/diff/f747d09e

Branch: refs/heads/3.1.x-fixes
Commit: f747d09e9e0cd107d205eb9fda4379320a40ed6f
Parents: 8d5d7e7
Author: Sergey Beryozkin <[hidden email]>
Authored: Fri May 19 21:39:02 2017 +0100
Committer: Sergey Beryozkin <[hidden email]>
Committed: Fri May 19 21:41:40 2017 +0100

----------------------------------------------------------------------
 .../provider/AbstractOAuthDataProvider.java      |  4 +++-
 .../oauth2/provider/JPAOAuthDataProvider.java    | 19 ++++++++++++++-----
 .../grants/code/JPACMTOAuthDataProviderTest.java |  5 +----
 3 files changed, 18 insertions(+), 10 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cxf/blob/f747d09e/rt/rs/security/oauth-parent/oauth2/src/main/java/org/apache/cxf/rs/security/oauth2/provider/AbstractOAuthDataProvider.java
----------------------------------------------------------------------
diff --git a/rt/rs/security/oauth-parent/oauth2/src/main/java/org/apache/cxf/rs/security/oauth2/provider/AbstractOAuthDataProvider.java b/rt/rs/security/oauth-parent/oauth2/src/main/java/org/apache/cxf/rs/security/oauth2/provider/AbstractOAuthDataProvider.java
index 4f407b0..78fc2b6 100644
--- a/rt/rs/security/oauth-parent/oauth2/src/main/java/org/apache/cxf/rs/security/oauth2/provider/AbstractOAuthDataProvider.java
+++ b/rt/rs/security/oauth-parent/oauth2/src/main/java/org/apache/cxf/rs/security/oauth2/provider/AbstractOAuthDataProvider.java
@@ -385,7 +385,9 @@ public abstract class AbstractOAuthDataProvider implements OAuthDataProvider, Cl
     }
     
     protected void linkAccessTokenToRefreshToken(RefreshToken rt, ServerAccessToken at) {
-        rt.getAccessTokens().add(at.getTokenKey());
+        if (!rt.getAccessTokens().contains(at.getTokenKey())) {
+            rt.getAccessTokens().add(at.getTokenKey());
+        }
     }
     protected void linkRefreshTokenToAccessToken(RefreshToken rt, ServerAccessToken at) {
         at.setRefreshToken(rt.getTokenKey());

http://git-wip-us.apache.org/repos/asf/cxf/blob/f747d09e/rt/rs/security/oauth-parent/oauth2/src/main/java/org/apache/cxf/rs/security/oauth2/provider/JPAOAuthDataProvider.java
----------------------------------------------------------------------
diff --git a/rt/rs/security/oauth-parent/oauth2/src/main/java/org/apache/cxf/rs/security/oauth2/provider/JPAOAuthDataProvider.java b/rt/rs/security/oauth-parent/oauth2/src/main/java/org/apache/cxf/rs/security/oauth2/provider/JPAOAuthDataProvider.java
index b93205b..75c8864 100644
--- a/rt/rs/security/oauth-parent/oauth2/src/main/java/org/apache/cxf/rs/security/oauth2/provider/JPAOAuthDataProvider.java
+++ b/rt/rs/security/oauth-parent/oauth2/src/main/java/org/apache/cxf/rs/security/oauth2/provider/JPAOAuthDataProvider.java
@@ -59,6 +59,7 @@ public class JPAOAuthDataProvider extends AbstractOAuthDataProvider {
     private static final int DEFAULT_PESSIMISTIC_LOCK_TIMEOUT = 10000;
     
     private int pessimisticLockTimeout = DEFAULT_PESSIMISTIC_LOCK_TIMEOUT;
+    private boolean useJpaLockForExistingRefreshToken = true;
     
     private EntityManagerFactory entityManagerFactory;
 
@@ -100,9 +101,13 @@ public class JPAOAuthDataProvider extends AbstractOAuthDataProvider {
         
     @Override
     protected RefreshToken updateExistingRefreshToken(RefreshToken rt, ServerAccessToken at) {
-        // lock RT for update
-        lockRefreshTokenForUpdate(rt);
-        return super.updateRefreshToken(rt, at);
+        if (useJpaLockForExistingRefreshToken) {
+            // lock RT for update
+            lockRefreshTokenForUpdate(rt);
+            return super.updateRefreshToken(rt, at);
+        } else {
+            return super.updateExistingRefreshToken(rt, at);
+        }
     }
     
     
@@ -454,8 +459,12 @@ public class JPAOAuthDataProvider extends AbstractOAuthDataProvider {
         em.close();
     }
 
-    public int getPessimisticLockTimeout() {
-        return pessimisticLockTimeout;
+    public void setPessimisticLockTimeout(int pessimisticLockTimeout) {
+        this.pessimisticLockTimeout = pessimisticLockTimeout;
+    }
+
+    public void setUseJpaLockForExistingRefreshToken(boolean useJpaLockForExistingRefreshToken) {
+        this.useJpaLockForExistingRefreshToken = useJpaLockForExistingRefreshToken;
     }
 
     public interface EntityManagerOperation<T> {

http://git-wip-us.apache.org/repos/asf/cxf/blob/f747d09e/rt/rs/security/oauth-parent/oauth2/src/test/java/org/apache/cxf/rs/security/oauth2/grants/code/JPACMTOAuthDataProviderTest.java
----------------------------------------------------------------------
diff --git a/rt/rs/security/oauth-parent/oauth2/src/test/java/org/apache/cxf/rs/security/oauth2/grants/code/JPACMTOAuthDataProviderTest.java b/rt/rs/security/oauth-parent/oauth2/src/test/java/org/apache/cxf/rs/security/oauth2/grants/code/JPACMTOAuthDataProviderTest.java
index d0f5b56..142b2f6 100644
--- a/rt/rs/security/oauth-parent/oauth2/src/test/java/org/apache/cxf/rs/security/oauth2/grants/code/JPACMTOAuthDataProviderTest.java
+++ b/rt/rs/security/oauth-parent/oauth2/src/test/java/org/apache/cxf/rs/security/oauth2/grants/code/JPACMTOAuthDataProviderTest.java
@@ -30,7 +30,6 @@ import org.apache.cxf.rs.security.oauth2.provider.JPAOAuthDataProviderTest;
 import org.apache.cxf.rs.security.oauth2.tokens.refresh.RefreshToken;
 import org.junit.After;
 import org.junit.Before;
-import org.junit.Ignore;
 import org.junit.Test;
 import org.junit.runner.RunWith;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -78,7 +77,6 @@ public class JPACMTOAuthDataProviderTest extends JPAOAuthDataProviderTest {
     }
     
     @Test
-    @Ignore
     public void testRefreshAccessTokenConcurrently() throws Exception {
         getProvider().setRecycleRefreshTokens(false);
 
@@ -117,8 +115,7 @@ public class JPACMTOAuthDataProviderTest extends JPAOAuthDataProviderTest {
         List<String> atl = rtl.get(0).getAccessTokens();
         assertNotNull(atl);
 
-        // after 3 parallel refreshes we should have 4 AccessTokens
-        assertEquals(4, atl.size());
+        assertEquals(2, atl.size());
     }
 }
 

Loading...