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
|

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

sergeyb
Repository: cxf
Updated Branches:
  refs/heads/master 5724e6154 -> 047f9f291


[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/047f9f29
Tree: http://git-wip-us.apache.org/repos/asf/cxf/tree/047f9f29
Diff: http://git-wip-us.apache.org/repos/asf/cxf/diff/047f9f29

Branch: refs/heads/master
Commit: 047f9f2918be0c53d3451e90b347ac26639dc33c
Parents: 5724e61
Author: Sergey Beryozkin <[hidden email]>
Authored: Fri May 19 21:39:02 2017 +0100
Committer: Sergey Beryozkin <[hidden email]>
Committed: Fri May 19 21:39:02 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/047f9f29/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 9df94db..ac5ce0f 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
@@ -380,7 +380,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/047f9f29/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 28c5d2a..fc59431 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;
 
@@ -99,9 +100,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);
+        }
     }
     
     
@@ -453,8 +458,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/047f9f29/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 cd93378..c390b6a 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());
     }
 }