You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cxf.apache.org by se...@apache.org on 2016/04/21 14:12:02 UTC

cxf git commit: Minor update to JPACodeDataProvider

Repository: cxf
Updated Branches:
  refs/heads/3.1.x-fixes 2d84f4043 -> d1687e70d


Minor update to JPACodeDataProvider


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

Branch: refs/heads/3.1.x-fixes
Commit: d1687e70dc8b0e8571cc7dfebbd173ec1ccb1c32
Parents: 2d84f40
Author: Sergey Beryozkin <sb...@gmail.com>
Authored: Thu Apr 21 13:09:42 2016 +0100
Committer: Sergey Beryozkin <sb...@gmail.com>
Committed: Thu Apr 21 13:11:39 2016 +0100

----------------------------------------------------------------------
 .../oauth2/grants/code/JPACodeDataProvider.java         | 12 +++++++++++-
 1 file changed, 11 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cxf/blob/d1687e70/rt/rs/security/oauth-parent/oauth2/src/main/java/org/apache/cxf/rs/security/oauth2/grants/code/JPACodeDataProvider.java
----------------------------------------------------------------------
diff --git a/rt/rs/security/oauth-parent/oauth2/src/main/java/org/apache/cxf/rs/security/oauth2/grants/code/JPACodeDataProvider.java b/rt/rs/security/oauth-parent/oauth2/src/main/java/org/apache/cxf/rs/security/oauth2/grants/code/JPACodeDataProvider.java
index c122f34..d6d759c 100644
--- a/rt/rs/security/oauth-parent/oauth2/src/main/java/org/apache/cxf/rs/security/oauth2/grants/code/JPACodeDataProvider.java
+++ b/rt/rs/security/oauth-parent/oauth2/src/main/java/org/apache/cxf/rs/security/oauth2/grants/code/JPACodeDataProvider.java
@@ -44,7 +44,17 @@ public class JPACodeDataProvider extends JPAOAuthDataProvider implements Authori
     }
 
     protected void saveCodeGrant(ServerAuthorizationCodeGrant grant) { 
-        persistEntity(grant);
+        getEntityManager().getTransaction().begin();
+        if (grant.getSubject() != null) {
+            UserSubject sub = getEntityManager().find(UserSubject.class, grant.getSubject().getLogin());
+            if (sub == null) {
+                getEntityManager().persist(grant.getSubject());
+            } else {
+                grant.setSubject(sub);
+            }
+        }
+        getEntityManager().persist(grant);
+        getEntityManager().getTransaction().commit();
     }
     
     @Override