cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From serg...@apache.org
Subject [1/2] cxf git commit: [CXF-7374] Moving the jpaLock related code to CMT provider, using the code from Adrian's patch
Date Mon, 29 May 2017 12:40:06 GMT
Repository: cxf
Updated Branches:
  refs/heads/master da59b2511 -> daf48cacd


[CXF-7374] Moving the jpaLock related code to CMT provider, using the code from Adrian's patch


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

Branch: refs/heads/master
Commit: 26feb75455abbf3ef999804395d4c5d5348042a2
Parents: e17a9fc
Author: Sergey Beryozkin <sberyozkin@gmail.com>
Authored: Mon May 29 13:39:26 2017 +0100
Committer: Sergey Beryozkin <sberyozkin@gmail.com>
Committed: Mon May 29 13:39:26 2017 +0100

----------------------------------------------------------------------
 .../grants/code/JPACMTCodeDataProvider.java     | 52 ++++++++++++++++++++
 .../oauth2/provider/JPAOAuthDataProvider.java   | 49 ------------------
 2 files changed, 52 insertions(+), 49 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cxf/blob/26feb754/rt/rs/security/oauth-parent/oauth2/src/main/java/org/apache/cxf/rs/security/oauth2/grants/code/JPACMTCodeDataProvider.java
----------------------------------------------------------------------
diff --git a/rt/rs/security/oauth-parent/oauth2/src/main/java/org/apache/cxf/rs/security/oauth2/grants/code/JPACMTCodeDataProvider.java
b/rt/rs/security/oauth-parent/oauth2/src/main/java/org/apache/cxf/rs/security/oauth2/grants/code/JPACMTCodeDataProvider.java
index 5eaa39a..bcc2ee7 100644
--- a/rt/rs/security/oauth-parent/oauth2/src/main/java/org/apache/cxf/rs/security/oauth2/grants/code/JPACMTCodeDataProvider.java
+++ b/rt/rs/security/oauth-parent/oauth2/src/main/java/org/apache/cxf/rs/security/oauth2/grants/code/JPACMTCodeDataProvider.java
@@ -18,12 +18,24 @@
  */
 package org.apache.cxf.rs.security.oauth2.grants.code;
 
+import java.util.Collections;
+import java.util.Map;
+
 import javax.persistence.EntityManager;
 import javax.persistence.EntityTransaction;
+import javax.persistence.LockModeType;
 import javax.persistence.PersistenceContext;
 
+import org.apache.cxf.rs.security.oauth2.common.ServerAccessToken;
+import org.apache.cxf.rs.security.oauth2.tokens.refresh.RefreshToken;
+
 public class JPACMTCodeDataProvider extends JPACodeDataProvider {
 
+    private static final int DEFAULT_PESSIMISTIC_LOCK_TIMEOUT = 10000;
+    
+    private int pessimisticLockTimeout = DEFAULT_PESSIMISTIC_LOCK_TIMEOUT;
+    private boolean useJpaLockForExistingRefreshToken = true;
+    
     @PersistenceContext
     private EntityManager entityManager;
 
@@ -60,4 +72,44 @@ public class JPACMTCodeDataProvider extends JPACodeDataProvider {
     @Override
     protected void closeIfNeeded(EntityManager em) {
     }
+    
+    @Override
+    protected RefreshToken updateExistingRefreshToken(RefreshToken rt, ServerAccessToken
at) {
+        if (useJpaLockForExistingRefreshToken) {
+            // lock RT for update
+            lockRefreshTokenForUpdate(rt);
+            return super.updateRefreshToken(rt, at);
+        } else {
+            return super.updateExistingRefreshToken(rt, at);
+        }
+    }
+    
+    protected void lockRefreshTokenForUpdate(final RefreshToken refreshToken) {
+        try {
+            execute(new EntityManagerOperation<Void>() {
+
+                @Override
+                public Void execute(EntityManager em) {
+                    Map<String, Object> options = null;
+                    if (pessimisticLockTimeout > 0) {
+                        options = Collections.singletonMap("javax.persistence.lock.timeout",
pessimisticLockTimeout);
+                    } else {
+                        options = Collections.emptyMap();
+                    }
+                    em.refresh(refreshToken, LockModeType.PESSIMISTIC_WRITE, options);
+                    return null;
+                }
+            });
+        } catch (IllegalArgumentException e) {
+            // entity is not managed yet. ignore
+        }
+    }
+    
+    public void setPessimisticLockTimeout(int pessimisticLockTimeout) {
+        this.pessimisticLockTimeout = pessimisticLockTimeout;
+    }
+
+    public void setUseJpaLockForExistingRefreshToken(boolean useJpaLockForExistingRefreshToken)
{
+        this.useJpaLockForExistingRefreshToken = useJpaLockForExistingRefreshToken;
+    }
 }

http://git-wip-us.apache.org/repos/asf/cxf/blob/26feb754/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 fc59431..850b76d 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
@@ -19,16 +19,13 @@
 package org.apache.cxf.rs.security.oauth2.provider;
 
 import java.util.ArrayList;
-import java.util.Collections;
 import java.util.HashMap;
 import java.util.LinkedList;
 import java.util.List;
-import java.util.Map;
 
 import javax.persistence.EntityManager;
 import javax.persistence.EntityManagerFactory;
 import javax.persistence.EntityTransaction;
-import javax.persistence.LockModeType;
 import javax.persistence.TypedQuery;
 
 import org.apache.cxf.helpers.CastUtils;
@@ -56,11 +53,6 @@ public class JPAOAuthDataProvider extends AbstractOAuthDataProvider {
     private static final String CLIENT_QUERY = "SELECT client FROM Client client"
             + " INNER JOIN client.resourceOwnerSubject ros";
 
-    private static final int DEFAULT_PESSIMISTIC_LOCK_TIMEOUT = 10000;
-    
-    private int pessimisticLockTimeout = DEFAULT_PESSIMISTIC_LOCK_TIMEOUT;
-    private boolean useJpaLockForExistingRefreshToken = true;
-    
     private EntityManagerFactory entityManagerFactory;
 
     public void setEntityManagerFactory(EntityManagerFactory emf) {
@@ -77,39 +69,6 @@ public class JPAOAuthDataProvider extends AbstractOAuthDataProvider {
         });
     }
 
-    protected void lockRefreshTokenForUpdate(final RefreshToken refreshToken) {
-        try {
-            execute(new EntityManagerOperation<Void>() {
-
-                @Override
-                public Void execute(EntityManager em) {
-                    Map<String, Object> options = null;
-                    if (pessimisticLockTimeout > 0) {
-                        options = Collections.singletonMap("javax.persistence.lock.timeout",
pessimisticLockTimeout);
-                    } else {
-                        options = Collections.emptyMap();
-                    }
-                    em.refresh(refreshToken, LockModeType.PESSIMISTIC_WRITE, options);
-                    return null;
-                }
-            });
-        } catch (IllegalArgumentException e) {
-            // entity is not managed yet. ignore
-        }
-    }
-        
-    @Override
-    protected RefreshToken updateExistingRefreshToken(RefreshToken rt, ServerAccessToken
at) {
-        if (useJpaLockForExistingRefreshToken) {
-            // lock RT for update
-            lockRefreshTokenForUpdate(rt);
-            return super.updateRefreshToken(rt, at);
-        } else {
-            return super.updateExistingRefreshToken(rt, at);
-        }
-    }
-    
-    
     protected <T> T execute(EntityManagerOperation<T> operation) {
         EntityManager em = getEntityManager();
         T value;
@@ -458,14 +417,6 @@ public class JPAOAuthDataProvider extends AbstractOAuthDataProvider {
         em.close();
     }
 
-    public void setPessimisticLockTimeout(int pessimisticLockTimeout) {
-        this.pessimisticLockTimeout = pessimisticLockTimeout;
-    }
-
-    public void setUseJpaLockForExistingRefreshToken(boolean useJpaLockForExistingRefreshToken)
{
-        this.useJpaLockForExistingRefreshToken = useJpaLockForExistingRefreshToken;
-    }
-
     public interface EntityManagerOperation<T> {
         T execute(EntityManager em);
     }


Mime
View raw message