1 19 20 package com.sslexplorer.policyframework; 21 22 import java.io.Serializable ; 23 import java.util.Calendar ; 24 25 import com.sslexplorer.security.AuthenticationScheme; 26 import com.sslexplorer.security.Constants; 27 import com.sslexplorer.security.LogonControllerFactory; 28 import com.sslexplorer.security.SessionInfo; 29 30 37 38 public abstract class AbstractResource implements Resource, Serializable { 39 40 protected int resourceId; 42 protected String resourceName; 43 protected String resourceDescription; 44 protected Calendar dateCreated; 45 protected Calendar dateAmended; 46 protected ResourceType resourceType; 47 protected int realmID; 48 49 52 protected AbstractResource() { 53 } 54 55 65 public AbstractResource(int realmID, ResourceType resourceType, int resourceId, String resourceName, String resourceDescription, 66 Calendar dateCreated, Calendar dateAmended) { 67 this.resourceType = resourceType; 68 this.resourceId = resourceId; 69 this.resourceName = resourceName; 70 this.resourceDescription = resourceDescription; 71 this.dateCreated = dateCreated; 72 this.dateAmended = dateAmended; 73 this.realmID = realmID; 74 } 75 76 81 public boolean equals(Object o) { 82 return o instanceof Resource && ((Resource) o).getResourceType().equals(getResourceType()) 83 && ((Resource) o).getResourceId() == getResourceId() && ((Resource) o).getRealmID() == getRealmID(); 84 } 85 86 91 public int getResourceId() { 92 return resourceId; 93 } 94 95 100 public ResourceType getResourceType() { 101 return resourceType; 102 } 103 104 109 public String getResourceName() { 110 return resourceName; 111 } 112 113 118 public String getResourceDisplayName() { 119 return getResourceName(); 120 } 121 122 127 public String getResourceDescription() { 128 return resourceDescription; 129 } 130 131 136 public void setResourceName(String resourceName) { 137 this.resourceName = resourceName; 138 } 139 140 145 public void setResourceId(int resourceId) { 146 this.resourceId = resourceId; 147 } 148 149 154 public void setResourceDescription(String resourceDescription) { 155 this.resourceDescription = resourceDescription; 156 } 157 158 165 public int compareTo(Object o) { 166 return getResourceName().compareTo(((Resource) o).getResourceName()); 167 } 168 169 174 public Calendar getDateCreated() { 175 return dateCreated; 176 } 177 178 183 public void setDateCreated(Calendar dateCreated) { 184 this.dateCreated = dateCreated; 185 } 186 187 192 public Calendar getDateAmended() { 193 return dateAmended; 194 } 195 196 201 public void setDateAmended(Calendar dateAmended) { 202 this.dateAmended = dateAmended; 203 } 204 205 210 public boolean sessionPasswordRequired(SessionInfo sessionInfo) { 211 boolean hasSessionPassword = false; 212 AuthenticationScheme scheme = sessionInfo.getHttpSession() == null ? null : (AuthenticationScheme) sessionInfo.getHttpSession().getAttribute(Constants.AUTH_SESSION); 213 if (scheme != null) { 214 char[] pw = LogonControllerFactory.getInstance().getPasswordFromCredentials(scheme); 215 if (pw != null) { 216 hasSessionPassword = true; 217 } 218 } 219 220 if (!hasSessionPassword & paramsRequirePassword()) 221 return true; 222 else 223 return false; 224 } 225 226 231 public boolean paramsRequirePassword() { 232 return false; 233 } 234 235 240 public String toString() { 241 StringBuffer buf = new StringBuffer ("Resource '"); 242 buf.append(getResourceName()); 243 buf.append("' [id="); 244 buf.append(getResourceId()); 245 buf.append("]"); 246 return buf.toString(); 247 } 248 249 250 253 public int getRealmID() { 254 return realmID; 255 } 256 257 258 } 259 | Popular Tags |