Add toString() methods to help in debugging; remove commented code and unused imports.
This commit is contained in:
parent
44c1de7b4e
commit
6b9f448dc2
9 changed files with 50 additions and 113 deletions
|
@ -40,6 +40,6 @@ public class CuratorEditingIdentifierFactory implements IdentifierBundleFactory{
|
|||
|
||||
public String getUri(){ return uri; }
|
||||
|
||||
public String toString(){ return uri; }
|
||||
public String toString(){ return "CuratorEditingId: " + uri; }
|
||||
}
|
||||
}
|
||||
|
|
|
@ -43,7 +43,7 @@ public class DbAdminEditingIdentifierFactory implements IdentifierBundleFactory{
|
|||
public String getUri(){ return uri; }
|
||||
|
||||
public String toString(){
|
||||
return "DbAdmin role of " + getRole();
|
||||
return "DbAdminEditingId: role of " + getRole();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,8 +2,6 @@
|
|||
|
||||
package edu.cornell.mannlib.vitro.webapp.auth.identifier;
|
||||
|
||||
import edu.cornell.mannlib.vitro.webapp.auth.identifier.SelfEditingIdentifierFactory.SelfEditing;
|
||||
|
||||
public abstract class RoleIdentifier implements Identifier {
|
||||
public abstract String getRole();
|
||||
public abstract String getUri();
|
||||
|
|
|
@ -33,22 +33,19 @@ import edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactory;
|
|||
/**
|
||||
* Pulls a netId out of the CUWebAuth REMOTE_USER header.
|
||||
*
|
||||
*
|
||||
* @author bdc34
|
||||
*
|
||||
*/
|
||||
public class SelfEditingIdentifierFactory implements IdentifierBundleFactory {
|
||||
public final static String httpHeaderForNetId = "REMOTE_USER";
|
||||
|
||||
private static final Log log = LogFactory.getLog(SelfEditingIdentifierFactory.class.getName());
|
||||
|
||||
|
||||
public IdentifierBundle getIdentifierBundle(ServletRequest request, HttpSession session, ServletContext context) {
|
||||
IdentifierBundle idb = getFromCUWebAuthHeader(request,session,context);
|
||||
if( idb != null )
|
||||
return idb;
|
||||
else
|
||||
return getFromSession(request,session);
|
||||
return getFromSession(session);
|
||||
}
|
||||
|
||||
private IdentifierBundle getFromCUWebAuthHeader(ServletRequest request, HttpSession session,ServletContext context){
|
||||
|
@ -100,7 +97,6 @@ public class SelfEditingIdentifierFactory implements IdentifierBundleFactory {
|
|||
}
|
||||
putNetIdInSession(session, selfE, netid);
|
||||
return idb;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -139,7 +135,7 @@ public class SelfEditingIdentifierFactory implements IdentifierBundleFactory {
|
|||
break;
|
||||
}catch(RuntimeException ex){
|
||||
log.error("Could not run blacklist check query for file " +
|
||||
file.getAbsolutePath() + file.separatorChar + file.getName(),
|
||||
file.getAbsolutePath() + File.separatorChar + file.getName(),
|
||||
ex);
|
||||
}
|
||||
}
|
||||
|
@ -214,7 +210,7 @@ public class SelfEditingIdentifierFactory implements IdentifierBundleFactory {
|
|||
return null;
|
||||
}
|
||||
|
||||
private IdentifierBundle getFromSession(ServletRequest req, HttpSession session ){
|
||||
private IdentifierBundle getFromSession( HttpSession session ){
|
||||
if (session == null) {
|
||||
return null;
|
||||
}
|
||||
|
@ -258,7 +254,7 @@ public class SelfEditingIdentifierFactory implements IdentifierBundleFactory {
|
|||
this.value = value;
|
||||
}
|
||||
public String getValue(){return value;}
|
||||
public String toString(){ return value;}
|
||||
public String toString(){ return "NetID: " + value;}
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -86,6 +86,11 @@ public class UserToIndIdentifierFactory implements IdentifierBundleFactory {
|
|||
}
|
||||
public List<String> getMayEditAsURIs() {
|
||||
return mayEditAsURIs;
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public String toString() {
|
||||
return "UserIdentifier: " + userURI;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -57,7 +57,7 @@ public class RoleBasedPolicy extends DefaultInconclusivePolicy implements Polic
|
|||
/**
|
||||
* What is the minimum AuthRole needed to perform a given action?
|
||||
*/
|
||||
private static Map<Class,AuthRole> actionToMinRole = new HashMap<Class,AuthRole>();
|
||||
private static Map<Class<?>,AuthRole> actionToMinRole = new HashMap<Class<?>,AuthRole>();
|
||||
static{
|
||||
//anybody actions
|
||||
//view resources?
|
||||
|
@ -103,7 +103,7 @@ public class RoleBasedPolicy extends DefaultInconclusivePolicy implements Polic
|
|||
|
||||
//We need to find the class of the RequestedAction since that
|
||||
//encodes what type of action is being requested.
|
||||
Class requesetClass = whatToAuth.getClass();
|
||||
Class<?> requesetClass = whatToAuth.getClass();
|
||||
AuthRole minmumRoleForAction = actionToMinRole.get(requesetClass);
|
||||
|
||||
if( minmumRoleForAction == null ){
|
||||
|
@ -118,33 +118,14 @@ public class RoleBasedPolicy extends DefaultInconclusivePolicy implements Polic
|
|||
return new BasicPolicyDecision(Authorization.UNAUTHORIZED,"not authorized for role");
|
||||
}
|
||||
|
||||
/**
|
||||
* Because it extends AbstractPolicySetup and implements this method, RoleBasedPolicy
|
||||
* can be used as a ServletContextListener that puts its self on the ServletPolicyList
|
||||
* at servlet context initialization.
|
||||
*
|
||||
* Notice that this method also setups the IdentifierBundleFactory that it needs.
|
||||
*/
|
||||
// @Override
|
||||
// public List<PolicyIface> createPolicies(ServletContextEvent sce) {
|
||||
// List<PolicyIface> list = new ArrayList<PolicyIface>(1);
|
||||
// list.add(new RoleBasedPolicy());
|
||||
//
|
||||
// //notice that the idBundleFactory gets created here,
|
||||
// JenaRoleIdentifierBundleFactory jibf = new JenaRoleIdentifierBundleFactory(userModelUri);
|
||||
// ServletIdentifierBundleFactory.addIdentifierBundleFactory(sce.getServletContext(),jibf);
|
||||
//
|
||||
// return list;
|
||||
// }
|
||||
@Override
|
||||
public String toString() {
|
||||
return "RoleBasedPolicy";
|
||||
}
|
||||
|
||||
/********************** Roles *****************************************/
|
||||
|
||||
/********************** Roles *****************************************/
|
||||
public static enum AuthRole implements Identifier {
|
||||
// ANYBODY("http://vitro.mannlib.cornell.edu/authRole#anybody",0),
|
||||
// USER("http://vitro.mannlib.cornell.edu/authRole#user",1),
|
||||
// EDITOR("http://vitro.mannlib.cornell.edu/authRole#editor",2),
|
||||
// CURATOR("http://vitro.mannlib.cornell.edu/authRole#curator",3),
|
||||
// DBA("http://vitro.mannlib.cornell.edu/authRole#dba",50);
|
||||
|
||||
ANYBODY( "role:/0" ,LoginStatusBean.ANYBODY),
|
||||
USER( "role:/1" ,LoginStatusBean.NON_EDITOR),
|
||||
EDITOR( "role:/4" ,LoginStatusBean.EDITOR),
|
||||
|
@ -181,5 +162,10 @@ public class RoleBasedPolicy extends DefaultInconclusivePolicy implements Polic
|
|||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "AuthRole: " + name();
|
||||
}
|
||||
}/* end of enum AuthRole */
|
||||
}/* end of class RoleBasedPolicy */
|
||||
|
|
|
@ -4,35 +4,18 @@ package edu.cornell.mannlib.vitro.webapp.auth.policy.ifaces;
|
|||
|
||||
import edu.cornell.mannlib.vitro.webapp.auth.identifier.IdentifierBundle;
|
||||
import edu.cornell.mannlib.vitro.webapp.auth.policy.BasicPolicyDecision;
|
||||
import edu.cornell.mannlib.vitro.webapp.auth.requestedAction.AddDataPropStmt;
|
||||
import edu.cornell.mannlib.vitro.webapp.auth.requestedAction.AddObjectPropStmt;
|
||||
import edu.cornell.mannlib.vitro.webapp.auth.requestedAction.AddResource;
|
||||
import edu.cornell.mannlib.vitro.webapp.auth.requestedAction.DropDataPropStmt;
|
||||
import edu.cornell.mannlib.vitro.webapp.auth.requestedAction.DropObjectPropStmt;
|
||||
import edu.cornell.mannlib.vitro.webapp.auth.requestedAction.DropResource;
|
||||
import edu.cornell.mannlib.vitro.webapp.auth.requestedAction.EditDataPropStmt;
|
||||
import edu.cornell.mannlib.vitro.webapp.auth.requestedAction.EditObjPropStmt;
|
||||
import edu.cornell.mannlib.vitro.webapp.auth.requestedAction.admin.AddNewUser;
|
||||
import edu.cornell.mannlib.vitro.webapp.auth.requestedAction.admin.LoadOntology;
|
||||
import edu.cornell.mannlib.vitro.webapp.auth.requestedAction.admin.RebuildTextIndex;
|
||||
import edu.cornell.mannlib.vitro.webapp.auth.requestedAction.admin.RemoveUser;
|
||||
import edu.cornell.mannlib.vitro.webapp.auth.requestedAction.admin.ServerStatus;
|
||||
import edu.cornell.mannlib.vitro.webapp.auth.requestedAction.admin.UpdateTextIndex;
|
||||
import edu.cornell.mannlib.vitro.webapp.auth.requestedAction.admin.UploadFile;
|
||||
import edu.cornell.mannlib.vitro.webapp.auth.requestedAction.ifaces.RequestedAction;
|
||||
import edu.cornell.mannlib.vitro.webapp.auth.requestedAction.ontology.CreateOwlClass;
|
||||
import edu.cornell.mannlib.vitro.webapp.auth.requestedAction.ontology.DefineDataProperty;
|
||||
import edu.cornell.mannlib.vitro.webapp.auth.requestedAction.ontology.DefineObjectProperty;
|
||||
import edu.cornell.mannlib.vitro.webapp.auth.requestedAction.ontology.RemoveOwlClass;
|
||||
|
||||
/**
|
||||
* a policy where every type of action is authorized as INCONCLUSIVE
|
||||
* by default.
|
||||
*
|
||||
* @author bdc34
|
||||
*
|
||||
*/
|
||||
public class DefaultAuthorizedPolicy implements PolicyIface{
|
||||
protected static PolicyDecision AUTHORIZED_DECISION = new BasicPolicyDecision(
|
||||
Authorization.AUTHORIZED,
|
||||
"This is the default decision defined in DefaultAuthorizedPolicy");
|
||||
|
||||
public PolicyDecision isAuthorized(IdentifierBundle whoToAuth,
|
||||
RequestedAction whatToAuth) {
|
||||
|
@ -45,7 +28,8 @@ public class DefaultAuthorizedPolicy implements PolicyIface{
|
|||
return AUTHORIZED_DECISION;
|
||||
}
|
||||
|
||||
protected static PolicyDecision AUTHORIZED_DECISION = new BasicPolicyDecision(
|
||||
Authorization.AUTHORIZED,
|
||||
"This is the default decision defined in DefaultAuthorizedPolicy");
|
||||
@Override
|
||||
public String toString() {
|
||||
return "DefaultAuthorizedPolicy";
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,35 +4,17 @@ package edu.cornell.mannlib.vitro.webapp.auth.policy.ifaces;
|
|||
|
||||
import edu.cornell.mannlib.vitro.webapp.auth.identifier.IdentifierBundle;
|
||||
import edu.cornell.mannlib.vitro.webapp.auth.policy.BasicPolicyDecision;
|
||||
import edu.cornell.mannlib.vitro.webapp.auth.requestedAction.AddDataPropStmt;
|
||||
import edu.cornell.mannlib.vitro.webapp.auth.requestedAction.AddObjectPropStmt;
|
||||
import edu.cornell.mannlib.vitro.webapp.auth.requestedAction.AddResource;
|
||||
import edu.cornell.mannlib.vitro.webapp.auth.requestedAction.DropDataPropStmt;
|
||||
import edu.cornell.mannlib.vitro.webapp.auth.requestedAction.DropObjectPropStmt;
|
||||
import edu.cornell.mannlib.vitro.webapp.auth.requestedAction.DropResource;
|
||||
import edu.cornell.mannlib.vitro.webapp.auth.requestedAction.EditDataPropStmt;
|
||||
import edu.cornell.mannlib.vitro.webapp.auth.requestedAction.EditObjPropStmt;
|
||||
import edu.cornell.mannlib.vitro.webapp.auth.requestedAction.admin.AddNewUser;
|
||||
import edu.cornell.mannlib.vitro.webapp.auth.requestedAction.admin.LoadOntology;
|
||||
import edu.cornell.mannlib.vitro.webapp.auth.requestedAction.admin.RebuildTextIndex;
|
||||
import edu.cornell.mannlib.vitro.webapp.auth.requestedAction.admin.RemoveUser;
|
||||
import edu.cornell.mannlib.vitro.webapp.auth.requestedAction.admin.ServerStatus;
|
||||
import edu.cornell.mannlib.vitro.webapp.auth.requestedAction.admin.UpdateTextIndex;
|
||||
import edu.cornell.mannlib.vitro.webapp.auth.requestedAction.admin.UploadFile;
|
||||
import edu.cornell.mannlib.vitro.webapp.auth.requestedAction.ifaces.RequestedAction;
|
||||
import edu.cornell.mannlib.vitro.webapp.auth.requestedAction.ontology.CreateOwlClass;
|
||||
import edu.cornell.mannlib.vitro.webapp.auth.requestedAction.ontology.DefineDataProperty;
|
||||
import edu.cornell.mannlib.vitro.webapp.auth.requestedAction.ontology.DefineObjectProperty;
|
||||
import edu.cornell.mannlib.vitro.webapp.auth.requestedAction.ontology.RemoveOwlClass;
|
||||
|
||||
/**
|
||||
* A policy where every type of action is authorized as INCONCLUSIVE
|
||||
* by default.
|
||||
*
|
||||
* A policy where every type of action is authorized as INCONCLUSIVE by default.
|
||||
*
|
||||
* @author bdc34
|
||||
*
|
||||
*/
|
||||
public class DefaultInconclusivePolicy implements PolicyIface{
|
||||
public class DefaultInconclusivePolicy implements PolicyIface {
|
||||
protected static PolicyDecision INCONCLUSIVE_DECISION = new BasicPolicyDecision(
|
||||
Authorization.INCONCLUSIVE,
|
||||
"This is the default decision defined in DefaultInconclusivePolicy");
|
||||
|
||||
public PolicyDecision isAuthorized(IdentifierBundle whoToAuth,
|
||||
RequestedAction whatToAuth) {
|
||||
|
@ -44,7 +26,10 @@ public class DefaultInconclusivePolicy implements PolicyIface{
|
|||
"null was passed as whatToAuth");
|
||||
return INCONCLUSIVE_DECISION;
|
||||
}
|
||||
protected static PolicyDecision INCONCLUSIVE_DECISION = new BasicPolicyDecision(
|
||||
Authorization.INCONCLUSIVE,
|
||||
"This is the default decision defined in DefaultInconclusivePolicy");
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "DefaultInconclusivePolicy";
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -4,41 +4,19 @@ package edu.cornell.mannlib.vitro.webapp.auth.policy.ifaces;
|
|||
|
||||
import edu.cornell.mannlib.vitro.webapp.auth.identifier.IdentifierBundle;
|
||||
import edu.cornell.mannlib.vitro.webapp.auth.policy.BasicPolicyDecision;
|
||||
import edu.cornell.mannlib.vitro.webapp.auth.requestedAction.AddDataPropStmt;
|
||||
import edu.cornell.mannlib.vitro.webapp.auth.requestedAction.AddObjectPropStmt;
|
||||
import edu.cornell.mannlib.vitro.webapp.auth.requestedAction.AddResource;
|
||||
import edu.cornell.mannlib.vitro.webapp.auth.requestedAction.DropDataPropStmt;
|
||||
import edu.cornell.mannlib.vitro.webapp.auth.requestedAction.DropObjectPropStmt;
|
||||
import edu.cornell.mannlib.vitro.webapp.auth.requestedAction.DropResource;
|
||||
import edu.cornell.mannlib.vitro.webapp.auth.requestedAction.EditDataPropStmt;
|
||||
import edu.cornell.mannlib.vitro.webapp.auth.requestedAction.EditObjPropStmt;
|
||||
import edu.cornell.mannlib.vitro.webapp.auth.requestedAction.admin.AddNewUser;
|
||||
import edu.cornell.mannlib.vitro.webapp.auth.requestedAction.admin.LoadOntology;
|
||||
import edu.cornell.mannlib.vitro.webapp.auth.requestedAction.admin.RebuildTextIndex;
|
||||
import edu.cornell.mannlib.vitro.webapp.auth.requestedAction.admin.RemoveUser;
|
||||
import edu.cornell.mannlib.vitro.webapp.auth.requestedAction.admin.ServerStatus;
|
||||
import edu.cornell.mannlib.vitro.webapp.auth.requestedAction.admin.UpdateTextIndex;
|
||||
import edu.cornell.mannlib.vitro.webapp.auth.requestedAction.admin.UploadFile;
|
||||
import edu.cornell.mannlib.vitro.webapp.auth.requestedAction.ifaces.RequestedAction;
|
||||
import edu.cornell.mannlib.vitro.webapp.auth.requestedAction.ontology.CreateOwlClass;
|
||||
import edu.cornell.mannlib.vitro.webapp.auth.requestedAction.ontology.DefineDataProperty;
|
||||
import edu.cornell.mannlib.vitro.webapp.auth.requestedAction.ontology.DefineObjectProperty;
|
||||
import edu.cornell.mannlib.vitro.webapp.auth.requestedAction.ontology.RemoveOwlClass;
|
||||
|
||||
/**
|
||||
*
|
||||
*a policy where every type of action is authorized as UNAUTHORIZED
|
||||
* by default. This can be useful for a unauthenticated session or
|
||||
* as the last policy on a PolicyList to force INCONCLUSIVE decisions
|
||||
* to UNAUTHORIZED.
|
||||
*/
|
||||
public class DefaultUnauthorizedPolicy implements PolicyIface{
|
||||
|
||||
protected static PolicyDecision UNAUTHORIZED_DECISION = new BasicPolicyDecision(
|
||||
Authorization.UNAUTHORIZED,
|
||||
"This is the default decision defined in DefaultUnauthorizedPolicy");
|
||||
|
||||
|
||||
public PolicyDecision isAuthorized(IdentifierBundle whoToAuth,
|
||||
RequestedAction whatToAuth) {
|
||||
if (whoToAuth == null)
|
||||
|
@ -48,5 +26,10 @@ public class DefaultUnauthorizedPolicy implements PolicyIface{
|
|||
return new BasicPolicyDecision(Authorization.UNAUTHORIZED,
|
||||
"null was passed as whatToAuth");
|
||||
return UNAUTHORIZED_DECISION;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "DefaultInconclusivePolicy";
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue