1 package org.hibernate.secure; 3 4 import java.security.Permission ; 5 6 9 public class HibernatePermission extends Permission { 10 11 public static final String INSERT = "insert"; 12 public static final String UPDATE = "update"; 13 public static final String DELETE = "delete"; 14 public static final String READ = "read"; 15 public static final String ANY = "*"; 16 17 private final String actions; 18 19 public HibernatePermission(String entityName, String actions) { 20 super(entityName); 21 this.actions = actions; 22 } 23 24 public boolean implies(Permission permission) { 25 return ( "*".equals( getName() ) || getName().equals( permission.getName() ) ) && 27 ( "*".equals(actions) || actions.indexOf( permission.getActions() ) >= 0 ); 28 } 29 30 public boolean equals(Object obj) { 31 if ( !(obj instanceof HibernatePermission) ) return false; 32 HibernatePermission permission = (HibernatePermission) obj; 33 return permission.getName().equals( getName() ) && 34 permission.getActions().equals(actions); 35 } 36 37 public int hashCode() { 38 return getName().hashCode() * 37 + actions.hashCode(); 39 } 40 41 public String getActions() { 42 return actions; 43 } 44 45 public String toString() { 46 return "HibernatePermission(" + getName() + ':' + actions + ')'; 47 } 48 49 } 50 | Popular Tags |