X-Git-Url: http://wamblee.org/gitweb/?a=blobdiff_plain;f=security%2Fimpl%2Fsrc%2Fmain%2Fjava%2Forg%2Fwamblee%2Fsecurity%2Fauthorization%2Fjpa%2FJpaAuthorizationService.java;h=9683888f93df6420f8daabd2189a0a331b79e4f4;hb=ca06b860025bad8d605ea2260164e8a2bb242d2b;hp=e1b71d7dd177c8a940f8c9119630294871dcfb50;hpb=a484e5ed22abd827236f61aed3ecf25853fcfc18;p=utils diff --git a/security/impl/src/main/java/org/wamblee/security/authorization/jpa/JpaAuthorizationService.java b/security/impl/src/main/java/org/wamblee/security/authorization/jpa/JpaAuthorizationService.java index e1b71d7d..9683888f 100644 --- a/security/impl/src/main/java/org/wamblee/security/authorization/jpa/JpaAuthorizationService.java +++ b/security/impl/src/main/java/org/wamblee/security/authorization/jpa/JpaAuthorizationService.java @@ -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; } }