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.policy.RoleBasedPolicy;
|
||||
import edu.cornell.mannlib.vitro.webapp.beans.Individual;
|
||||
import edu.cornell.mannlib.vitro.webapp.dao.IndividualDao;
|
||||
import edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactory;
|
||||
|
||||
/**
|
||||
|
@ -57,4 +56,13 @@ public class FakeSelfEditingIdentifierFactory implements IdentifierBundleFactory
|
|||
public static void clearFakeIdInSession( HttpSession session){
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,123 +1,82 @@
|
|||
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
|
||||
|
||||
package edu.cornell.mannlib.vitro.webapp.controller;
|
||||
package edu.cornell.mannlib.vitro.webapp.controller;
|
||||
|
||||
import java.util.Enumeration;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import javax.servlet.RequestDispatcher;
|
||||
import javax.servlet.ServletException;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.IOException;
|
||||
|
||||
import javax.servlet.RequestDispatcher;
|
||||
import javax.servlet.ServletException;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import javax.servlet.http.HttpSession;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
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.controller.BaseEditController;
|
||||
import edu.cornell.mannlib.vitro.webapp.beans.Portal;
|
||||
import edu.cornell.mannlib.vitro.webapp.filters.VitroRequestPrep;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
|
||||
import edu.cornell.mannlib.vedit.beans.LoginFormBean;
|
||||
import edu.cornell.mannlib.vitro.webapp.auth.identifier.FakeSelfEditingIdentifierFactory;
|
||||
|
||||
public class FakeSelfEditController extends VitroHttpServlet {
|
||||
|
||||
private static final Log log = LogFactory.getLog(FakeSelfEditController.class.getName());
|
||||
|
||||
public void doGet( HttpServletRequest request, HttpServletResponse response )
|
||||
throws IOException, ServletException {
|
||||
|
||||
// if (!checkLoginStatus(request, response)) {
|
||||
// return;
|
||||
// }
|
||||
|
||||
String redirectUrl = null;
|
||||
String netid = null;
|
||||
String msg = null;
|
||||
|
||||
try {
|
||||
super.doGet(request,response);
|
||||
VitroRequest vreq = new VitroRequest(request);
|
||||
HttpSession session = request.getSession(true);
|
||||
|
||||
Object obj = vreq.getSession().getAttribute("loginHandler");
|
||||
LoginFormBean loginHandler = null;
|
||||
if( obj != null && obj instanceof LoginFormBean )
|
||||
loginHandler = ((LoginFormBean)obj);
|
||||
|
||||
// Not logged in to site admin
|
||||
if ( loginHandler == null ||
|
||||
! "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);
|
||||
netid = request.getParameter("netid");
|
||||
FakeSelfEditingIdentifierFactory.clearFakeIdInSession( session );
|
||||
FakeSelfEditingIdentifierFactory.putFakeIdInSession( netid , session );
|
||||
// Redirect to user's entity page
|
||||
redirectUrl = request.getContextPath() + Controllers.ENTITY + "?netid=" + netid;
|
||||
}
|
||||
|
||||
// Form to stop using netid submitted
|
||||
else if ( request.getParameter("stopfaking") != null) {
|
||||
VitroRequestPrep.forceOutOfSelfEditing(request);
|
||||
FakeSelfEditingIdentifierFactory.clearFakeIdInSession( session );
|
||||
// Redirect to home page
|
||||
redirectUrl = request.getContextPath() + "/";
|
||||
}
|
||||
}
|
||||
|
||||
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("bodyJsp", "/admin/fakeselfedit.jsp");
|
||||
|
||||
RequestDispatcher rd =
|
||||
request.getRequestDispatcher(Controllers.BASIC_JSP);
|
||||
rd.forward(request, response);
|
||||
|
||||
} catch (Throwable e) {
|
||||
log.error("FakeSelfEditController could not forward to view.");
|
||||
log.error(e.getMessage());
|
||||
log.error(e.getStackTrace());
|
||||
}
|
||||
}
|
||||
|
||||
public void doPost(HttpServletRequest request, HttpServletResponse response)
|
||||
throws ServletException, IOException {
|
||||
doGet(request, response);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
import edu.cornell.mannlib.vitro.webapp.filters.VitroRequestPrep;
|
||||
|
||||
public class FakeSelfEditController extends VitroHttpServlet {
|
||||
|
||||
private static final Log log = LogFactory
|
||||
.getLog(FakeSelfEditController.class.getName());
|
||||
|
||||
public void doGet(HttpServletRequest request, HttpServletResponse response)
|
||||
throws IOException, ServletException {
|
||||
|
||||
try {
|
||||
super.doGet(request, response);
|
||||
VitroRequest vreq = new VitroRequest(request);
|
||||
HttpSession session = request.getSession();
|
||||
|
||||
if (!LoginFormBean.loggedIn(request, LoginFormBean.CURATOR)) {
|
||||
// Not logged in as site admin
|
||||
session.setAttribute("postLoginRequest", vreq.getRequestURI());
|
||||
response.sendRedirect(request.getContextPath()
|
||||
+ Controllers.LOGIN + "?login=block");
|
||||
} else if (vreq.getParameter("force") != null) {
|
||||
// Logged in as site admin: Form to use netid
|
||||
VitroRequestPrep.forceToSelfEditing(request);
|
||||
String id = request.getParameter("netid");
|
||||
FakeSelfEditingIdentifierFactory.clearFakeIdInSession(session);
|
||||
FakeSelfEditingIdentifierFactory.putFakeIdInSession(id, session);
|
||||
response.sendRedirect(request.getContextPath()
|
||||
+ Controllers.ENTITY + "?netid=" + id);
|
||||
} else if (request.getParameter("stopfaking") != null) {
|
||||
// Logged in as site admin: Form to stop using netid
|
||||
VitroRequestPrep.forceOutOfSelfEditing(request);
|
||||
FakeSelfEditingIdentifierFactory.clearFakeIdInSession(session);
|
||||
response.sendRedirect(request.getContextPath() + "/");
|
||||
} else {
|
||||
// Logged in as site admin: Form not yet submitted
|
||||
request.setAttribute("msg", figureMessage(session));
|
||||
request.setAttribute("title", "Self-Edit Test");
|
||||
request.setAttribute("bodyJsp", "/admin/fakeselfedit.jsp");
|
||||
RequestDispatcher rd = request.getRequestDispatcher(Controllers.BASIC_JSP);
|
||||
rd.forward(request, response);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.error("FakeSelfEditController could not forward to view.");
|
||||
log.error(e, e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 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.";
|
||||
}
|
||||
}
|
||||
|
||||
public void doPost(HttpServletRequest request, HttpServletResponse response)
|
||||
throws ServletException, IOException {
|
||||
doGet(request, response);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue