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
*/
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(
service = new DefaultAuthorizationService(userAccessor, name);
entityManager.persist(service);
}
+ return service;
}
/*
initialize();
refresh();
service.appendRule(aRule);
- save();
+ save(); // service might still be detached as service is cached.
}
/*
initialize();
refresh();
service.removeRule(aIndex);
- save();
+ save(); // service might still be detached as service is cached.
}
/*
initialize();
refresh();
service.insertRuleAfter(aIndex, aRule);
- save();
+ save(); // service might still be detached as service is cached.
}
/**
long time = System.currentTimeMillis();
if ((time - lastRefreshTime) > refreshInterval) {
- refreshByReload();
+ service = refreshByReload();
lastRefreshTime = time;
}
}