align package names.
[utils] / security / impl / src / main / java / org / wamblee / security / authorization / jpa / JpaAuthorizationService.java
index e1b71d7dd177c8a940f8c9119630294871dcfb50..9683888f93df6420f8daabd2189a0a331b79e4f4 100644 (file)
@@ -20,13 +20,13 @@ import javax.persistence.NoResultException;
 import javax.persistence.NonUniqueResultException;
 
 import org.wamblee.persistence.JpaMergeSupport;
+import org.wamblee.security.authentication.UserAccessor;
 import org.wamblee.security.authorization.AbstractAuthorizationService;
 import org.wamblee.security.authorization.AbstractAuthorizationRule;
 import org.wamblee.security.authorization.AuthorizationRule;
 import org.wamblee.security.authorization.AuthorizationService;
 import org.wamblee.security.authorization.DefaultAuthorizationService;
 import org.wamblee.security.authorization.Operation;
-import org.wamblee.usermgt.UserAccessor;
 
 /**
  * Authorization service with persistent storage. This is a wrapper for
@@ -100,16 +100,17 @@ public class JpaAuthorizationService implements AuthorizationService {
      */
     private void initialize() {
         if (service == null) {
-            refreshByReload();
+            service = refreshByReload();
         }
     }
 
-    private void refreshByReload() {
+    private AuthorizationService refreshByReload() {
+        AuthorizationService service; 
         try {
             service = entityManager.createNamedQuery(
                 AbstractAuthorizationService.QUERY_FIND_BY_NAME,
                 AbstractAuthorizationService.class).setParameter(
-                    AbstractAuthorizationService.NAME_PARAM, name).getSingleResult();
+                    DefaultAuthorizationService.NAME_PARAM, name).getSingleResult();
             service.setUserAccessor(userAccessor);
         } catch (NonUniqueResultException e) {
             throw new IllegalArgumentException(
@@ -118,6 +119,7 @@ public class JpaAuthorizationService implements AuthorizationService {
             service = new DefaultAuthorizationService(userAccessor, name);
             entityManager.persist(service);
         }
+        return service;
     }
 
     /*
@@ -170,7 +172,7 @@ public class JpaAuthorizationService implements AuthorizationService {
         initialize();
         refresh();
         service.appendRule(aRule);
-        save();
+        save(); // service might still be detached as service is cached. 
     }
 
     /*
@@ -183,7 +185,7 @@ public class JpaAuthorizationService implements AuthorizationService {
         initialize();
         refresh();
         service.removeRule(aIndex);
-        save();
+        save(); // service might still be detached as service is cached. 
     }
 
     /*
@@ -197,7 +199,7 @@ public class JpaAuthorizationService implements AuthorizationService {
         initialize();
         refresh();
         service.insertRuleAfter(aIndex, aRule);
-        save();
+        save(); // service might still be detached as service is cached.
     }
 
     /**
@@ -207,7 +209,7 @@ public class JpaAuthorizationService implements AuthorizationService {
         long time = System.currentTimeMillis();
 
         if ((time - lastRefreshTime) > refreshInterval) {
-            refreshByReload();
+            service = refreshByReload();
             lastRefreshTime = time;
         }
     }