All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.infinispan.security.CachePermissionCollection Maven / Gradle / Ivy

There is a newer version: 15.1.0.Dev04
Show newest version
package org.infinispan.security;

import static org.infinispan.util.logging.Log.SECURITY;

import java.security.Permission;
import java.security.PermissionCollection;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Enumeration;
import java.util.List;

/**
 * CachePermissionCollection.
 *
 * @author Tristan Tarrant
 * @since 7.0
 */
public class CachePermissionCollection extends PermissionCollection {
   private static final long serialVersionUID = -3709477547317792941L;
   private final List perms;
   private int mask = 0;

   public CachePermissionCollection() {
      perms = new ArrayList<>();
   }

   @Override
   public void add(Permission permission) {
      if (permission.getClass() != CachePermission.class)
         throw SECURITY.invalidPermission(permission);

     if (isReadOnly())
         throw SECURITY.readOnlyPermissionCollection();

     CachePermission p = (CachePermission)permission;

     synchronized (this) {
         perms.add(p);
         mask |= p.getAuthorizationPermission().getMask();
     }
   }

   @Override
   public boolean implies(Permission permission) {
      if (permission == null || permission.getClass() != CachePermission.class)
         return false;
      CachePermission p = (CachePermission)permission;
      return p.getAuthorizationPermission().matches(mask);
   }

   @Override
   public Enumeration elements() {
      synchronized (this) {
         return Collections.enumeration(perms);
     }
   }

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy