1 28 package net.sf.jguard.core.authorization.permissions; 29 30 import java.security.Permission ; 31 import java.util.Date ; 32 33 38 public class DurationDecorator extends Permission { 39 40 private static final long serialVersionUID = 3085444057980849140L; 41 private Permission permission; 42 private Date begin; 43 private Date end; 44 45 51 public DurationDecorator(Permission p,Date start,Date end){ 52 super(p.getName()); 53 this.permission = p; 54 this.begin = start; 55 this.end = end; 56 } 57 58 public boolean equals(Object obj) { 59 if (obj instanceof DurationDecorator) { 60 DurationDecorator duration = (DurationDecorator) obj; 61 if(this.permission.getName().equals(duration.getName()) 62 && this.permission.getActions().equals(duration.getActions())){ 63 return true; 64 } 65 } 66 return false; 67 } 68 69 public String getActions() { 70 return permission.getActions(); 71 } 72 73 public int hashCode() { 74 int hashCode = permission.hashCode(); 75 if(begin!= null){ 76 hashCode += begin.hashCode(); 77 } 78 if(end!= null){ 79 hashCode += end.hashCode(); 80 } 81 return hashCode; 82 83 } 84 85 public boolean implies(Permission permission) { 86 Date now = new Date (); 87 if(begin != null && now.before(begin)){ 88 return false; 89 } 90 if(end != null && now.after(end)){ 91 return false; 92 } 93 return this.permission.implies(permission); 96 } 97 98 } 99 | Popular Tags |