📄 abstractresource.java
字号:
/*
* SSL-Explorer
*
* Copyright (C) 2003-2006 3SP LTD. All Rights Reserved
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2 of
* the License, or (at your option) any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public
* License along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
package com.sslexplorer.policyframework;
import java.util.Calendar;
import com.sslexplorer.core.CoreServlet;
import com.sslexplorer.security.AuthenticationScheme;
import com.sslexplorer.security.Constants;
import com.sslexplorer.security.SessionInfo;
/**
* Abstract implementation of a {@link Resource}. Provides setters and getters
* for attributes common to all resource types.
*
* @author Brett Smith <brett@3sp.com>
* @since 0.2.0
*/
public abstract class AbstractResource implements Resource {
// Protected instance variables
protected int resourceId;
protected String resourceName;
protected String resourceDescription;
protected int parentResourcePermission;
protected Calendar dateCreated;
protected Calendar dateAmended;
protected ResourceType resourceType;
/**
* Constructor.
*
* @param resourceType resource type.
* @param resourceId resource Id
* @param resourceName resource name
* @param resourceDescription resource description
* @param parentResourcePermission parent resource permission ID
* @param dateCreated date created
* @param dateAmended date amended
*/
public AbstractResource(ResourceType resourceType, int resourceId, String resourceName, String resourceDescription,
int parentResourcePermission, Calendar dateCreated, Calendar dateAmended) {
this.resourceType = resourceType;
this.resourceId = resourceId;
this.resourceName = resourceName;
this.resourceDescription = resourceDescription;
this.parentResourcePermission = parentResourcePermission;
this.dateCreated = dateCreated;
this.dateAmended = dateAmended;
}
/*
* (non-Javadoc)
*
* @see java.lang.Object#equals(java.lang.Object)
*/
public boolean equals(Object o) {
return o instanceof Resource && ((Resource) o).getResourceType().equals(getResourceType())
&& ((Resource) o).getResourceId() == getResourceId();
}
/*
* (non-Javadoc)
*
* @see com.sslexplorer.boot.policyframework.Resource#getResourceId()
*/
public int getResourceId() {
return resourceId;
}
/*
* (non-Javadoc)
*
* @see com.sslexplorer.boot.policyframework.Resource#getResourceType()
*/
public ResourceType getResourceType() {
return resourceType;
}
/*
* (non-Javadoc)
*
* @see com.sslexplorer.boot.policyframework.Resource#getResourceName()
*/
public String getResourceName() {
return resourceName;
}
/*
* (non-Javadoc)
*
* @see com.sslexplorer.boot.policyframework.Resource#getResourceDescription()
*/
public String getResourceDescription() {
return resourceDescription;
}
/*
* (non-Javadoc)
*
* @see com.sslexplorer.boot.policyframework.Resource#setResourceName(java.lang.String)
*/
public void setResourceName(String resourceName) {
this.resourceName = resourceName;
}
/**
* Set this resources ID
*
* @param resourceId resource Id
*/
public void setResourceId(int resourceId) {
this.resourceId = resourceId;
}
/*
* (non-Javadoc)
*
* @see com.sslexplorer.boot.policyframework.Resource#setResourceDescription(java.lang.String)
*/
public void setResourceDescription(String resourceDescription) {
this.resourceDescription = resourceDescription;
}
/**
* Compare this resource with another using the resource name for
* comparison.
*
* @param o resource to compare with
* @return
*/
public int compareTo(Object o) {
return getResourceName().compareTo(((Resource) o).getResourceName());
}
/*
* (non-Javadoc)
*
* @see com.sslexplorer.boot.policyframework.Resource#getParentResourcePermission()
*/
public int getParentResourcePermission() {
return parentResourcePermission;
}
/*
* (non-Javadoc)
*
* @see com.sslexplorer.boot.policyframework.Resource#getDateCreated()
*/
public Calendar getDateCreated() {
return dateCreated;
}
/**
* Set the date this resource was created
*
* @param dateCreated date created
*/
public void setDateCreated(Calendar dateCreated) {
this.dateCreated = dateCreated;
}
/*
* (non-Javadoc)
*
* @see com.sslexplorer.boot.policyframework.Resource#getDateAmended()
*/
public Calendar getDateAmended() {
return dateAmended;
}
/*
* (non-Javadoc)
*
* @see com.sslexplorer.boot.policyframework.Resource#setDateAmended(java.util.Calendar)
*/
public void setDateAmended(Calendar dateAmended) {
this.dateAmended = dateAmended;
}
/*
* (non-Javadoc)
*
* @see com.sslexplorer.boot.policyframework.Resource#setParentResourcePermission(int)
*/
public void setParentResourcePermission(int parentResourcePermission) {
this.parentResourcePermission = parentResourcePermission;
}
/*
* (non-Javadoc)
*
* @see com.sslexplorer.policyframework.Resource#requiresPassword()
*/
public boolean sessionPasswordRequired(SessionInfo sessionInfo) {
boolean hasSessionPassword = false;
AuthenticationScheme scheme = (AuthenticationScheme) sessionInfo.getHttpSession().getAttribute(Constants.AUTH_SESSION);
if (scheme != null) {
char[] pw = CoreServlet.getServlet().getLogonController().getPasswordFromCredentials(scheme);
if (pw != null) {
hasSessionPassword = true;
}
}
if (!hasSessionPassword & paramsRequirePassword())
return true;
else
return false;
}
/*
* (non-Javadoc)
*
* @see com.sslexplorer.policyframework.Resource#paramsRequirePassword()
*/
public boolean paramsRequirePassword() {
return false;
}
/*
* (non-Javadoc)
*
* @see java.lang.Object#toString()
*/
public String toString() {
StringBuffer buf = new StringBuffer("Resource '");
buf.append(getResourceName());
buf.append("' [id=");
buf.append(getResourceId());
buf.append(",type=");
buf.append(getResourceType().getResourceTypeId());
buf.append(",parentResourcePermission=");
buf.append(getParentResourcePermission());
buf.append("]");
return buf.toString();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -