From 579ce5fdd8d27614369a83c46c5acd23b24fe564 Mon Sep 17 00:00:00 2001 From: jeb228 Date: Wed, 13 Oct 2010 20:13:17 +0000 Subject: [PATCH] NIHVIVO-736 transitioning from LoginFormBean to LoginStatusBean. --- .../auth/policy/CuratorEditingPolicy.java | 9 ++++----- .../auth/policy/DbAdminEditingPolicy.java | 4 ++-- .../webapp/auth/policy/EditorEditingPolicy.java | 6 ++---- .../webapp/auth/policy/RoleBasedPolicy.java | 13 ++++++------- .../vitro/webapp/beans/BaseResourceBean.java | 12 ++++++------ .../vitro/webapp/controller/edit/Logout.java | 12 ++++++------ .../controller/jena/RDFUploadController.java | 3 ++- .../controller/login/LoginTemplateHelper.java | 17 ++++------------- 8 files changed, 32 insertions(+), 44 deletions(-) diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/auth/policy/CuratorEditingPolicy.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/auth/policy/CuratorEditingPolicy.java index a05ba592f..028f1baf9 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/auth/policy/CuratorEditingPolicy.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/auth/policy/CuratorEditingPolicy.java @@ -5,13 +5,13 @@ package edu.cornell.mannlib.vitro.webapp.auth.policy; import java.util.Collections; import java.util.HashSet; import java.util.Set; -import java.util.regex.Matcher; -import java.util.regex.Pattern; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import edu.cornell.mannlib.vedit.beans.LoginFormBean; +import com.hp.hpl.jena.rdf.model.impl.Util; + +import edu.cornell.mannlib.vedit.beans.LoginStatusBean; import edu.cornell.mannlib.vitro.webapp.auth.identifier.CuratorEditingIdentifierFactory; import edu.cornell.mannlib.vitro.webapp.auth.identifier.Identifier; import edu.cornell.mannlib.vitro.webapp.auth.identifier.IdentifierBundle; @@ -41,7 +41,6 @@ import edu.cornell.mannlib.vitro.webapp.auth.requestedAction.ontology.DefineData import edu.cornell.mannlib.vitro.webapp.auth.requestedAction.ontology.DefineObjectProperty; import edu.cornell.mannlib.vitro.webapp.auth.requestedAction.ontology.RemoveOwlClass; import edu.cornell.mannlib.vitro.webapp.dao.VitroVocabulary; -import com.hp.hpl.jena.rdf.model.impl.Util; /** * Policy to use for Vivo Curator-Editing for use at Cornell. @@ -136,7 +135,7 @@ public class CuratorEditingPolicy implements VisitingPolicyIface { return pd.setMessage("Unable to get a role for the curator from IdBundle"); try{ - if( Integer.parseInt( roleStr ) /*<*/ != LoginFormBean.CURATOR) + if( Integer.parseInt( roleStr ) /*<*/ != LoginStatusBean.CURATOR) return pd.setMessage("CuratorEditingPolicy found role of "+roleStr+" but only authorizes for users logged in as CURATOR or higher"); }catch(NumberFormatException nef){} diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/auth/policy/DbAdminEditingPolicy.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/auth/policy/DbAdminEditingPolicy.java index 944a98485..3b835e335 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/auth/policy/DbAdminEditingPolicy.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/auth/policy/DbAdminEditingPolicy.java @@ -11,7 +11,7 @@ import org.apache.commons.logging.LogFactory; import com.hp.hpl.jena.rdf.model.impl.Util; -import edu.cornell.mannlib.vedit.beans.LoginFormBean; +import edu.cornell.mannlib.vedit.beans.LoginStatusBean; import edu.cornell.mannlib.vitro.webapp.auth.identifier.DbAdminEditingIdentifierFactory; import edu.cornell.mannlib.vitro.webapp.auth.identifier.Identifier; import edu.cornell.mannlib.vitro.webapp.auth.identifier.IdentifierBundle; @@ -137,7 +137,7 @@ public class DbAdminEditingPolicy implements VisitingPolicyIface { return pd.setMessage("Unable to get a role for the dbAdmin from IdBundle"); try{ - if( Integer.parseInt( roleStr ) /*<*/ != LoginFormBean.DBA) { + if( Integer.parseInt( roleStr ) /*<*/ != LoginStatusBean.DBA) { return pd.setMessage("DbAdminEditingPolicy found role of "+roleStr+" and only authorizes for users logged in as DB_ADMIN"); } } catch(NumberFormatException nef){ diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/auth/policy/EditorEditingPolicy.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/auth/policy/EditorEditingPolicy.java index 54d6a96bd..55b069f81 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/auth/policy/EditorEditingPolicy.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/auth/policy/EditorEditingPolicy.java @@ -5,15 +5,13 @@ package edu.cornell.mannlib.vitro.webapp.auth.policy; import java.util.Collections; import java.util.HashSet; import java.util.Set; -import java.util.regex.Matcher; -import java.util.regex.Pattern; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import com.hp.hpl.jena.rdf.model.impl.Util; -import edu.cornell.mannlib.vedit.beans.LoginFormBean; +import edu.cornell.mannlib.vedit.beans.LoginStatusBean; import edu.cornell.mannlib.vitro.webapp.auth.identifier.EditorEditingIdentifierFactory; import edu.cornell.mannlib.vitro.webapp.auth.identifier.Identifier; import edu.cornell.mannlib.vitro.webapp.auth.identifier.IdentifierBundle; @@ -137,7 +135,7 @@ public class EditorEditingPolicy implements VisitingPolicyIface{ return pd.setMessage("Unable to get a role for the editor from IdBundle"); try{ - if( Integer.parseInt( roleStr ) /*<*/ != LoginFormBean.EDITOR) + if( Integer.parseInt( roleStr ) /*<*/ != LoginStatusBean.EDITOR) return pd.setMessage("EditorEditingPolicy found role of "+roleStr+" but only authorizes for users logged in as EDITOR or higher"); }catch(NumberFormatException nef){} diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/auth/policy/RoleBasedPolicy.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/auth/policy/RoleBasedPolicy.java index 9f83f5653..d66ed8a2b 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/auth/policy/RoleBasedPolicy.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/auth/policy/RoleBasedPolicy.java @@ -8,14 +8,13 @@ import java.util.Map; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import edu.cornell.mannlib.vedit.beans.LoginFormBean; +import edu.cornell.mannlib.vedit.beans.LoginStatusBean; import edu.cornell.mannlib.vitro.webapp.auth.identifier.Identifier; import edu.cornell.mannlib.vitro.webapp.auth.identifier.IdentifierBundle; import edu.cornell.mannlib.vitro.webapp.auth.policy.ifaces.Authorization; import edu.cornell.mannlib.vitro.webapp.auth.policy.ifaces.DefaultInconclusivePolicy; import edu.cornell.mannlib.vitro.webapp.auth.policy.ifaces.PolicyDecision; import edu.cornell.mannlib.vitro.webapp.auth.policy.ifaces.PolicyIface; -import edu.cornell.mannlib.vitro.webapp.auth.policy.ifaces.VisitingPolicyIface; 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; @@ -146,11 +145,11 @@ public class RoleBasedPolicy extends DefaultInconclusivePolicy implements Polic // CURATOR("http://vitro.mannlib.cornell.edu/authRole#curator",3), // DBA("http://vitro.mannlib.cornell.edu/authRole#dba",50); - ANYBODY( "role:/0" ,LoginFormBean.ANYBODY), - USER( "role:/1" ,LoginFormBean.NON_EDITOR), - EDITOR( "role:/4" ,LoginFormBean.EDITOR), - CURATOR( "role:/5" ,LoginFormBean.CURATOR), - DBA( "role:/50",LoginFormBean.DBA); + ANYBODY( "role:/0" ,LoginStatusBean.ANYBODY), + USER( "role:/1" ,LoginStatusBean.NON_EDITOR), + EDITOR( "role:/4" ,LoginStatusBean.EDITOR), + CURATOR( "role:/5" ,LoginStatusBean.CURATOR), + DBA( "role:/50",LoginStatusBean.DBA); private final String roleUri; private final int level; diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/beans/BaseResourceBean.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/beans/BaseResourceBean.java index 7fc85a87c..3c9a2833e 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/beans/BaseResourceBean.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/beans/BaseResourceBean.java @@ -6,7 +6,7 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.openrdf.model.impl.URIImpl; -import edu.cornell.mannlib.vedit.beans.LoginFormBean; +import edu.cornell.mannlib.vedit.beans.LoginStatusBean; import edu.cornell.mannlib.vitro.webapp.dao.VitroVocabulary; import edu.cornell.mannlib.vitro.webapp.flags.AuthFlag; @@ -69,15 +69,15 @@ public class BaseResourceBean implements ResourceBean { public static RoleLevel getRoleFromAuth(AuthFlag ar){ int level = ar.getUserSecurityLevel(); - if( level == LoginFormBean.ANYBODY) // 0 + if( level == LoginStatusBean.ANYBODY) // 0 return PUBLIC; - if( level == LoginFormBean.NON_EDITOR) // 1 + if( level == LoginStatusBean.NON_EDITOR) // 1 return PUBLIC; // no correspondence with self-editing, which does not authorize through the LoginFormBean - if( level == LoginFormBean.EDITOR ) // 4 + if( level == LoginStatusBean.EDITOR ) // 4 return EDITOR; - if( level == LoginFormBean.CURATOR ) // 5 + if( level == LoginStatusBean.CURATOR ) // 5 return CURATOR; - if( level == LoginFormBean.DBA ) // 50 + if( level == LoginStatusBean.DBA ) // 50 return DB_ADMIN; else return null; diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/edit/Logout.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/edit/Logout.java index 6314eb869..95e41e753 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/edit/Logout.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/edit/Logout.java @@ -10,7 +10,7 @@ import javax.servlet.http.HttpSession; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import edu.cornell.mannlib.vedit.beans.LoginFormBean; +import edu.cornell.mannlib.vedit.beans.LoginStatusBean; import edu.cornell.mannlib.vitro.webapp.beans.User; import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest; import edu.cornell.mannlib.vitro.webapp.dao.UserDao; @@ -32,12 +32,12 @@ public class Logout extends HttpServlet { UserDao userDao = ((WebappDaoFactory) session .getServletContext().getAttribute("webappDaoFactory")) .getUserDao(); - LoginFormBean f = (LoginFormBean) session - .getAttribute("loginHandler"); - if (f != null) { - User user = userDao.getUserByUsername(f.getLoginName()); + + LoginStatusBean loginBean = LoginStatusBean.getBean(session); + if (loginBean.isLoggedIn()) { + User user = userDao.getUserByUsername(loginBean.getUsername()); if (user == null) { - log.error("Unable to retrieve user " + f.getLoginName() + log.error("Unable to retrieve user " + loginBean.getUsername() + " from model"); } else { Authenticate.sendLoginNotifyEvent( diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/jena/RDFUploadController.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/jena/RDFUploadController.java index 913a3a3e6..dba0bbd93 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/jena/RDFUploadController.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/jena/RDFUploadController.java @@ -27,6 +27,7 @@ import com.hp.hpl.jena.shared.JenaException; import com.hp.hpl.jena.shared.Lock; import edu.cornell.mannlib.vedit.beans.LoginFormBean; +import edu.cornell.mannlib.vedit.beans.LoginStatusBean; import edu.cornell.mannlib.vedit.controller.BaseEditController; import edu.cornell.mannlib.vitro.webapp.beans.Portal; import edu.cornell.mannlib.vitro.webapp.controller.Controllers; @@ -66,7 +67,7 @@ public class RDFUploadController extends BaseEditController { return; } - LoginFormBean loginBean = (LoginFormBean) request.getSession().getAttribute("loginHandler"); + LoginStatusBean loginBean = LoginStatusBean.getBean(request); try { super.doGet(request,response); diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/login/LoginTemplateHelper.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/login/LoginTemplateHelper.java index cb3baa8e5..b56ec2c4d 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/login/LoginTemplateHelper.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/login/LoginTemplateHelper.java @@ -3,7 +3,6 @@ package edu.cornell.mannlib.vitro.webapp.controller.login; import java.io.IOException; -import java.util.Collections; import java.util.HashMap; import java.util.Map; @@ -13,11 +12,10 @@ import javax.servlet.http.HttpSession; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import edu.cornell.mannlib.vedit.beans.LoginFormBean; +import edu.cornell.mannlib.vedit.beans.LoginStatusBean; import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest; import edu.cornell.mannlib.vitro.webapp.controller.edit.Authenticate; import edu.cornell.mannlib.vitro.webapp.controller.freemarker.FreemarkerHttpServlet; -import edu.cornell.mannlib.vitro.webapp.controller.freemarker.UrlBuilder; import edu.cornell.mannlib.vitro.webapp.controller.login.LoginProcessBean.State; import freemarker.template.Configuration; @@ -178,18 +176,11 @@ public class LoginTemplateHelper extends LoginTemplateHelperBase { * Where are we in the process? Logged in? Not? Somewhere in between? */ private State getCurrentLoginState(HttpServletRequest request) { - HttpSession session = request.getSession(false); - if (session == null) { - return State.NOWHERE; - } - - LoginFormBean lfb = (LoginFormBean) session - .getAttribute("loginHandler"); - if ((lfb != null) && (lfb.getLoginStatus().equals("authenticated"))) { + if (LoginStatusBean.getBean(request).isLoggedIn()) { return State.LOGGED_IN; + } else { + return getLoginProcessBean(request).getState(); } - - return getLoginProcessBean(request).getState(); } /**