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.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;
* @param aRefresh
* Whether or not to refresh the state of the service at the
* start of every operation.
*/
public JpaAuthorizationService(String aName, EntityManager aEntityManager,
* @param aRefresh
* Whether or not to refresh the state of the service at the
* start of every operation.
*/
public JpaAuthorizationService(String aName, EntityManager aEntityManager,
entityManager = aEntityManager;
refreshInterval = aRefreshInterval;
lastRefreshTime = System.currentTimeMillis();
userAccessor = aAccessor;
entityManager = aEntityManager;
refreshInterval = aRefreshInterval;
lastRefreshTime = System.currentTimeMillis();
userAccessor = aAccessor;
-
- /**
- * Initialize service if needed.
- *
- */
- private void initialize() {
- if (service == null) {
- service = refreshByReload();
- }
+
+ @Override
+ public void setUserAdministration(UserAdministration aUserAdmin) {
+ userAdmin = aUserAdmin;
AbstractAuthorizationService.QUERY_FIND_BY_NAME,
AbstractAuthorizationService.class).setParameter(
DefaultAuthorizationService.NAME_PARAM, name).getSingleResult();
AbstractAuthorizationService.QUERY_FIND_BY_NAME,
AbstractAuthorizationService.class).setParameter(
DefaultAuthorizationService.NAME_PARAM, name).getSingleResult();
} catch (NonUniqueResultException e) {
throw new IllegalArgumentException(
"Returned more than one service for name '" + name + "'");
} catch (NoResultException e) {
} catch (NonUniqueResultException e) {
throw new IllegalArgumentException(
"Returned more than one service for name '" + name + "'");
} catch (NoResultException e) {
- service = new DefaultAuthorizationService(userAccessor, name);
- entityManager.persist(service);
+ svc = new DefaultAuthorizationService(userAccessor, userAdmin, name);
+ entityManager.persist(svc);
* .lang.Object, org.wamblee.security.authorization.Operation)
*/
public boolean isAllowed(Object aResource, Operation aOperation) {
* .lang.Object, org.wamblee.security.authorization.Operation)
*/
public boolean isAllowed(Object aResource, Operation aOperation) {
* org.wamblee.security.authorization.Operation)
*/
public <T> T check(T aResource, Operation aOperation) {
* org.wamblee.security.authorization.Operation)
*/
public <T> T check(T aResource, Operation aOperation) {
* @see org.wamblee.security.authorization.AuthorizationService#getRules()
*/
public AuthorizationRule[] getRules() {
* @see org.wamblee.security.authorization.AuthorizationService#getRules()
*/
public AuthorizationRule[] getRules() {
* .wamblee.security.authorization.AuthorizationRule)
*/
public void appendRule(AuthorizationRule aRule) {
* .wamblee.security.authorization.AuthorizationRule)
*/
public void appendRule(AuthorizationRule aRule) {
- initialize();
- refresh();
- service.appendRule(aRule);
- save(); // service might still be detached as service is cached.
+ AuthorizationService svc = refreshByReload();
+ svc.appendRule(aRule);
+ // Setting service to null will force reload the next time the
+ // service is used. This deals effectively with the case where the
+ // current transaction would roll back and the change would not have been made.
+ setService(null);
* org.wamblee.security.authorization.AuthorizationService#removeRule(int)
*/
public void removeRule(int aIndex) {
* org.wamblee.security.authorization.AuthorizationService#removeRule(int)
*/
public void removeRule(int aIndex) {
* (int, org.wamblee.security.authorization.AuthorizationRule)
*/
public void insertRuleAfter(int aIndex, AuthorizationRule aRule) {
* (int, org.wamblee.security.authorization.AuthorizationRule)
*/
public void insertRuleAfter(int aIndex, AuthorizationRule aRule) {
- initialize();
- refresh();
- service.insertRuleAfter(aIndex, aRule);
- save(); // service might still be detached as service is cached.
+ AuthorizationService svc = refreshByReload();
+ svc.insertRuleAfter(aIndex, aRule);
+ setService(null);