KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > hibernate > secure > HibernatePermission


1 //$Id: HibernatePermission.java,v 1.3 2005/02/12 07:19:45 steveebersole Exp $
2
package org.hibernate.secure;
3
4 import java.security.Permission JavaDoc;
5
6 /**
7  * @author Gavin King
8  */

9 public class HibernatePermission extends Permission JavaDoc {
10     
11     public static final String JavaDoc INSERT = "insert";
12     public static final String JavaDoc UPDATE = "update";
13     public static final String JavaDoc DELETE = "delete";
14     public static final String JavaDoc READ = "read";
15     public static final String JavaDoc ANY = "*";
16     
17     private final String JavaDoc actions;
18
19     public HibernatePermission(String JavaDoc entityName, String JavaDoc actions) {
20         super(entityName);
21         this.actions = actions;
22     }
23
24     public boolean implies(Permission JavaDoc permission) {
25         //TODO!
26
return ( "*".equals( getName() ) || getName().equals( permission.getName() ) ) &&
27             ( "*".equals(actions) || actions.indexOf( permission.getActions() ) >= 0 );
28     }
29
30     public boolean equals(Object JavaDoc 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 JavaDoc getActions() {
42         return actions;
43     }
44     
45     public String JavaDoc toString() {
46         return "HibernatePermission(" + getName() + ':' + actions + ')';
47     }
48
49 }
50
Popular Tags