X-Git-Url: http://wamblee.org/gitweb/?a=blobdiff_plain;f=security%2Fsrc%2Fmain%2Fjava%2Forg%2Fwamblee%2Fsecurity%2Fauthorization%2Fhibernate%2FPersistentAuthorizationService.java;h=895e77e642d9129bcb24478ddebd6695179c15ca;hb=0d8d8f24656e585ee75558cfd6a4c661f8f14985;hp=dfe2439caa1a930a491e8178525c9db658268c4e;hpb=da48a523c81e59fe0eac34e43d12937396161f25;p=utils diff --git a/security/src/main/java/org/wamblee/security/authorization/hibernate/PersistentAuthorizationService.java b/security/src/main/java/org/wamblee/security/authorization/hibernate/PersistentAuthorizationService.java index dfe2439c..895e77e6 100644 --- a/security/src/main/java/org/wamblee/security/authorization/hibernate/PersistentAuthorizationService.java +++ b/security/src/main/java/org/wamblee/security/authorization/hibernate/PersistentAuthorizationService.java @@ -50,32 +50,32 @@ public class PersistentAuthorizationService extends AbstractPersistent /** * Authorization service to use. */ - private DefaultAuthorizationService _service; + private DefaultAuthorizationService service; /** * Hibernate template to use. */ - private HibernateTemplate _template; + private HibernateTemplate template; /** * User accessor. */ - private UserAccessor _userAccessor; + private UserAccessor userAccessor; /** * Name of the service. */ - private String _name; + private String name; /** * Refresh interval in milliseconds. */ - private final long _refreshInterval; + private final long refreshInterval; /** * Last refresh time. */ - private long _lastRefreshTime; + private long lastRefreshTime; /** * Constructs the persistent service. @@ -93,34 +93,34 @@ public class PersistentAuthorizationService extends AbstractPersistent public PersistentAuthorizationService(String aName, HibernateTemplate aTemplate, UserAccessor aAccessor, long aRefreshInterval) { - _template = aTemplate; - _refreshInterval = aRefreshInterval; - _lastRefreshTime = System.currentTimeMillis(); - _userAccessor = aAccessor; - _name = aName; + template = aTemplate; + refreshInterval = aRefreshInterval; + lastRefreshTime = System.currentTimeMillis(); + userAccessor = aAccessor; + name = aName; } /** * Initialize service if needed. */ private void initialize() { - if (_service == null) { - List result = _template + if (service == null) { + List result = template .findByNamedQueryAndNamedParam(FIND_QUERY, NAME_PARAM, - _name); + name); if (result.size() > 1) { throw new IllegalArgumentException( - "Returned more than one service for name '" + _name + "Returned more than one service for name '" + name + "' (" + result.size() + ")"); } if (result.size() == 0) { - _service = new DefaultAuthorizationService(_userAccessor, _name); - _template.persist(_service); + service = new DefaultAuthorizationService(userAccessor, name); + template.persist(service); } else { - _service = result.get(0); - _service.setUserAccessor(_userAccessor); + service = result.get(0); + service.setUserAccessor(userAccessor); } } } @@ -134,7 +134,7 @@ public class PersistentAuthorizationService extends AbstractPersistent public boolean isAllowed(Object aResource, Operation aOperation) { initialize(); refresh(); - return _service.isAllowed(aResource, aOperation); + return service.isAllowed(aResource, aOperation); } /* (non-Javadoc) @@ -143,7 +143,7 @@ public class PersistentAuthorizationService extends AbstractPersistent public T check(T aResource, Operation aOperation) { initialize(); refresh(); - return _service.check(aResource, aOperation); + return service.check(aResource, aOperation); } /* @@ -154,7 +154,7 @@ public class PersistentAuthorizationService extends AbstractPersistent public AuthorizationRule[] getRules() { initialize(); refresh(); - return _service.getRules(); + return service.getRules(); } /* @@ -165,7 +165,7 @@ public class PersistentAuthorizationService extends AbstractPersistent public void appendRule(AuthorizationRule aRule) { initialize(); refresh(); - _service.appendRule(aRule); + service.appendRule(aRule); save(); } @@ -177,7 +177,7 @@ public class PersistentAuthorizationService extends AbstractPersistent public void removeRule(int aIndex) { initialize(); refresh(); - _service.removeRule(aIndex); + service.removeRule(aIndex); save(); } @@ -190,7 +190,7 @@ public class PersistentAuthorizationService extends AbstractPersistent public void insertRuleAfter(int aIndex, AuthorizationRule aRule) { initialize(); refresh(); - _service.insertRuleAfter(aIndex, aRule); + service.insertRuleAfter(aIndex, aRule); save(); } @@ -200,9 +200,9 @@ public class PersistentAuthorizationService extends AbstractPersistent */ private synchronized void refresh() { long time = System.currentTimeMillis(); - if ( time - _lastRefreshTime > _refreshInterval ) { - _template.refresh(_service); - _lastRefreshTime = time; + if ( time - lastRefreshTime > refreshInterval ) { + template.refresh(service); + lastRefreshTime = time; } } @@ -210,6 +210,6 @@ public class PersistentAuthorizationService extends AbstractPersistent * Saves any changes to the service state if necessary. */ private void save() { - HibernateSupport.merge(_template, _service); + HibernateSupport.merge(template, service); } }