Clean up the logic and reformat the FakeSelfEditing code. No functional change.
This commit is contained in:
parent
2e609225de
commit
83c1043c9f
2 changed files with 85 additions and 118 deletions
|
@ -9,7 +9,6 @@ import javax.servlet.http.HttpSession;
|
||||||
import edu.cornell.mannlib.vitro.webapp.auth.identifier.SelfEditingIdentifierFactory.NetId;
|
import edu.cornell.mannlib.vitro.webapp.auth.identifier.SelfEditingIdentifierFactory.NetId;
|
||||||
import edu.cornell.mannlib.vitro.webapp.auth.policy.RoleBasedPolicy;
|
import edu.cornell.mannlib.vitro.webapp.auth.policy.RoleBasedPolicy;
|
||||||
import edu.cornell.mannlib.vitro.webapp.beans.Individual;
|
import edu.cornell.mannlib.vitro.webapp.beans.Individual;
|
||||||
import edu.cornell.mannlib.vitro.webapp.dao.IndividualDao;
|
|
||||||
import edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactory;
|
import edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactory;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -57,4 +56,13 @@ public class FakeSelfEditingIdentifierFactory implements IdentifierBundleFactory
|
||||||
public static void clearFakeIdInSession( HttpSession session){
|
public static void clearFakeIdInSession( HttpSession session){
|
||||||
session.removeAttribute(FAKE_SELF_EDIT_NETID);
|
session.removeAttribute(FAKE_SELF_EDIT_NETID);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static String getFakeIdFromSession(HttpSession session) {
|
||||||
|
Object netid = session.getAttribute(FAKE_SELF_EDIT_NETID);
|
||||||
|
if (netid instanceof String) {
|
||||||
|
return (String) netid;
|
||||||
|
} else {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,8 +2,6 @@
|
||||||
|
|
||||||
package edu.cornell.mannlib.vitro.webapp.controller;
|
package edu.cornell.mannlib.vitro.webapp.controller;
|
||||||
|
|
||||||
import java.util.Enumeration;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
import javax.servlet.RequestDispatcher;
|
import javax.servlet.RequestDispatcher;
|
||||||
|
@ -15,102 +13,64 @@ import javax.servlet.http.HttpSession;
|
||||||
import org.apache.commons.logging.Log;
|
import org.apache.commons.logging.Log;
|
||||||
import org.apache.commons.logging.LogFactory;
|
import org.apache.commons.logging.LogFactory;
|
||||||
|
|
||||||
import edu.cornell.mannlib.vitro.webapp.controller.Controllers;
|
|
||||||
import edu.cornell.mannlib.vedit.beans.LoginFormBean;
|
import edu.cornell.mannlib.vedit.beans.LoginFormBean;
|
||||||
//import edu.cornell.mannlib.vedit.controller.BaseEditController;
|
|
||||||
import edu.cornell.mannlib.vitro.webapp.beans.Portal;
|
|
||||||
import edu.cornell.mannlib.vitro.webapp.filters.VitroRequestPrep;
|
|
||||||
import edu.cornell.mannlib.vitro.webapp.auth.identifier.FakeSelfEditingIdentifierFactory;
|
import edu.cornell.mannlib.vitro.webapp.auth.identifier.FakeSelfEditingIdentifierFactory;
|
||||||
|
import edu.cornell.mannlib.vitro.webapp.filters.VitroRequestPrep;
|
||||||
|
|
||||||
public class FakeSelfEditController extends VitroHttpServlet {
|
public class FakeSelfEditController extends VitroHttpServlet {
|
||||||
|
|
||||||
private static final Log log = LogFactory.getLog(FakeSelfEditController.class.getName());
|
private static final Log log = LogFactory
|
||||||
|
.getLog(FakeSelfEditController.class.getName());
|
||||||
|
|
||||||
public void doGet( HttpServletRequest request, HttpServletResponse response )
|
public void doGet(HttpServletRequest request, HttpServletResponse response)
|
||||||
throws IOException, ServletException {
|
throws IOException, ServletException {
|
||||||
|
|
||||||
// if (!checkLoginStatus(request, response)) {
|
|
||||||
// return;
|
|
||||||
// }
|
|
||||||
|
|
||||||
String redirectUrl = null;
|
|
||||||
String netid = null;
|
|
||||||
String msg = null;
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
super.doGet(request,response);
|
super.doGet(request, response);
|
||||||
VitroRequest vreq = new VitroRequest(request);
|
VitroRequest vreq = new VitroRequest(request);
|
||||||
HttpSession session = request.getSession(true);
|
HttpSession session = request.getSession();
|
||||||
|
|
||||||
Object obj = vreq.getSession().getAttribute("loginHandler");
|
if (!LoginFormBean.loggedIn(request, LoginFormBean.CURATOR)) {
|
||||||
LoginFormBean loginHandler = null;
|
// Not logged in as site admin
|
||||||
if( obj != null && obj instanceof LoginFormBean )
|
session.setAttribute("postLoginRequest", vreq.getRequestURI());
|
||||||
loginHandler = ((LoginFormBean)obj);
|
response.sendRedirect(request.getContextPath()
|
||||||
|
+ Controllers.LOGIN + "?login=block");
|
||||||
// Not logged in to site admin
|
} else if (vreq.getParameter("force") != null) {
|
||||||
if ( loginHandler == null ||
|
// Logged in as site admin: Form to use netid
|
||||||
! "authenticated".equalsIgnoreCase(loginHandler.getLoginStatus()) ||
|
|
||||||
Integer.parseInt(loginHandler.getLoginRole()) <= LoginFormBean.CURATOR ) {
|
|
||||||
|
|
||||||
session.setAttribute("postLoginRequest",
|
|
||||||
vreq.getRequestURI()); //+( vreq.getQueryString()!=null?('?' + vreq.getQueryString()):"" ));
|
|
||||||
// Redirect to site admin login page
|
|
||||||
redirectUrl=request.getContextPath() + Controllers.LOGIN + "?login=block";
|
|
||||||
}
|
|
||||||
|
|
||||||
// Logged in to site admin
|
|
||||||
else {
|
|
||||||
// Handle form submission
|
|
||||||
// Form to use netid submitted
|
|
||||||
if( vreq.getParameter("force") != null ){
|
|
||||||
VitroRequestPrep.forceToSelfEditing(request);
|
VitroRequestPrep.forceToSelfEditing(request);
|
||||||
netid = request.getParameter("netid");
|
String id = request.getParameter("netid");
|
||||||
FakeSelfEditingIdentifierFactory.clearFakeIdInSession( session );
|
FakeSelfEditingIdentifierFactory.clearFakeIdInSession(session);
|
||||||
FakeSelfEditingIdentifierFactory.putFakeIdInSession( netid , session );
|
FakeSelfEditingIdentifierFactory.putFakeIdInSession(id, session);
|
||||||
// Redirect to user's entity page
|
response.sendRedirect(request.getContextPath()
|
||||||
redirectUrl = request.getContextPath() + Controllers.ENTITY + "?netid=" + netid;
|
+ Controllers.ENTITY + "?netid=" + id);
|
||||||
}
|
} else if (request.getParameter("stopfaking") != null) {
|
||||||
|
// Logged in as site admin: Form to stop using netid
|
||||||
// Form to stop using netid submitted
|
|
||||||
else if ( request.getParameter("stopfaking") != null) {
|
|
||||||
VitroRequestPrep.forceOutOfSelfEditing(request);
|
VitroRequestPrep.forceOutOfSelfEditing(request);
|
||||||
FakeSelfEditingIdentifierFactory.clearFakeIdInSession( session );
|
FakeSelfEditingIdentifierFactory.clearFakeIdInSession(session);
|
||||||
// Redirect to home page
|
response.sendRedirect(request.getContextPath() + "/");
|
||||||
redirectUrl = request.getContextPath() + "/";
|
} else {
|
||||||
}
|
// Logged in as site admin: Form not yet submitted
|
||||||
}
|
request.setAttribute("msg", figureMessage(session));
|
||||||
|
|
||||||
if (redirectUrl != null) {
|
|
||||||
response.sendRedirect(redirectUrl);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// On page, form not yet submitted
|
|
||||||
// Check if already logged in from previous form submission
|
|
||||||
netid = (String)session.getAttribute(FakeSelfEditingIdentifierFactory.FAKE_SELF_EDIT_NETID);
|
|
||||||
|
|
||||||
// Already logged in from a previous request
|
|
||||||
if ( netid != null ) {
|
|
||||||
msg = "You are testing self-editing as '" + netid + "'.";
|
|
||||||
}
|
|
||||||
// Not logged in
|
|
||||||
else {
|
|
||||||
msg = "You have not configured a netid to test self-editing.";
|
|
||||||
}
|
|
||||||
|
|
||||||
request.setAttribute("msg", msg);
|
|
||||||
|
|
||||||
request.setAttribute("title", "Self-Edit Test");
|
request.setAttribute("title", "Self-Edit Test");
|
||||||
request.setAttribute("bodyJsp", "/admin/fakeselfedit.jsp");
|
request.setAttribute("bodyJsp", "/admin/fakeselfedit.jsp");
|
||||||
|
RequestDispatcher rd = request.getRequestDispatcher(Controllers.BASIC_JSP);
|
||||||
RequestDispatcher rd =
|
|
||||||
request.getRequestDispatcher(Controllers.BASIC_JSP);
|
|
||||||
rd.forward(request, response);
|
rd.forward(request, response);
|
||||||
|
}
|
||||||
} catch (Throwable e) {
|
} catch (Exception e) {
|
||||||
log.error("FakeSelfEditController could not forward to view.");
|
log.error("FakeSelfEditController could not forward to view.");
|
||||||
log.error(e.getMessage());
|
log.error(e, e);
|
||||||
log.error(e.getStackTrace());
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check if already logged in from previous form submission
|
||||||
|
*/
|
||||||
|
private String figureMessage(HttpSession session) {
|
||||||
|
String netid = FakeSelfEditingIdentifierFactory.getFakeIdFromSession(session);
|
||||||
|
if (netid != null) {
|
||||||
|
return "You are testing self-editing as '" + netid + "'.";
|
||||||
|
} else {
|
||||||
|
return "You have not configured a netid to test self-editing.";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -119,5 +79,4 @@ public class FakeSelfEditController extends VitroHttpServlet {
|
||||||
doGet(request, response);
|
doGet(request, response);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue