Refinements to infrastructure that allows freemarker controllers to block access to pages if user is not logged in.
This commit is contained in:
parent
e7e5cefb29
commit
57750cd789
4 changed files with 68 additions and 52 deletions
|
@ -76,10 +76,6 @@ public class FreemarkerHttpServlet extends VitroHttpServlet {
|
|||
|
||||
public void doGet( HttpServletRequest request, HttpServletResponse response )
|
||||
throws IOException, ServletException {
|
||||
|
||||
if (requiresLogin() && !checkLoginStatus(request, response)) {
|
||||
return;
|
||||
}
|
||||
|
||||
super.doGet(request,response);
|
||||
|
||||
|
@ -89,7 +85,14 @@ public class FreemarkerHttpServlet extends VitroHttpServlet {
|
|||
Configuration config = getConfig(vreq);
|
||||
vreq.setAttribute("freemarkerConfig", config);
|
||||
|
||||
ResponseValues responseValues = processRequest(vreq);
|
||||
ResponseValues responseValues;
|
||||
|
||||
if (requiresLogin() && !checkLoginStatus(request, response)) {
|
||||
responseValues = new RedirectResponseValues(UrlBuilder.Route.LOGIN.path());
|
||||
} else {
|
||||
responseValues = processRequest(vreq);
|
||||
}
|
||||
|
||||
doResponse(vreq, response, responseValues);
|
||||
|
||||
} catch (Throwable e) {
|
||||
|
@ -207,6 +210,9 @@ public class FreemarkerHttpServlet extends VitroHttpServlet {
|
|||
protected boolean requiresLogin() {
|
||||
// By default, user does not need to be logged in to view pages.
|
||||
// Subclasses that require login to process their page will override to return true.
|
||||
// NB This method can't be static, because then the superclass method gets called rather than
|
||||
// the subclass method. For the same reason, it can't refer to a static or instance field
|
||||
// REQUIRES_LOGIN which is overridden in the subclass.
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
|
@ -113,9 +113,11 @@ public class IndividualController extends FreemarkerHttpServlet {
|
|||
body.put("relatedSubject", getRelatedSubject(vreq));
|
||||
|
||||
IndividualTemplateModel ind = getIndividualTemplateModel(vreq, individual);
|
||||
body.put("individual", ind);
|
||||
body.put("individual", ind);
|
||||
|
||||
String template = getIndividualTemplate(individual);
|
||||
|
||||
return new TemplateResponseValues(TEMPLATE_INDIVIDUAL_DEFAULT, body);
|
||||
return new TemplateResponseValues(template, body);
|
||||
|
||||
} catch (Throwable e) {
|
||||
log.error(e);
|
||||
|
@ -124,7 +126,7 @@ public class IndividualController extends FreemarkerHttpServlet {
|
|||
}
|
||||
|
||||
private void cleanUpSession(VitroRequest vreq) {
|
||||
// Session cleanup: anytime we are at an entity page we shouldn't have an editing config or submission
|
||||
// Session cleanup: any time we are at an entity page we shouldn't have an editing config or submission
|
||||
HttpSession session = vreq.getSession();
|
||||
session.removeAttribute("editjson");
|
||||
EditConfiguration.clearAllConfigsInSession(session);
|
||||
|
@ -189,52 +191,57 @@ public class IndividualController extends FreemarkerHttpServlet {
|
|||
individual.setKeywords(iwDao.getKeywordsForIndividualByMode(individual.getURI(),"visible"));
|
||||
individual.sortForDisplay();
|
||||
|
||||
// String vclassName = "unknown";
|
||||
// String customView = null;
|
||||
// String customCss = null;
|
||||
// if( individual.getVClass() != null ){
|
||||
// vclassName = individual.getVClass().getName();
|
||||
// List<VClass> clasList = individual.getVClasses(true);
|
||||
// for (VClass clas : clasList) {
|
||||
// customView = clas.getCustomDisplayView();
|
||||
// if (customView != null) {
|
||||
// if (customView.length()>0) {
|
||||
// vclassName = clas.getName(); // reset entity vclassname to name of class where a custom view
|
||||
// log.debug("Found direct class ["+clas.getName()+"] with custom view "+customView+"; resetting entity vclassName to this class");
|
||||
// break;
|
||||
// } else {
|
||||
// customView = null;
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// if (customView == null) { //still
|
||||
// clasList = individual.getVClasses(false);
|
||||
// for (VClass clas : clasList) {
|
||||
// customView = clas.getCustomDisplayView();
|
||||
// if (customView != null) {
|
||||
// if (customView.length()>0) {
|
||||
// // note that NOT changing entity vclassName here yet
|
||||
// log.debug("Found inferred class ["+clas.getName()+"] with custom view "+customView);
|
||||
// break;
|
||||
// } else {
|
||||
// customView = null;
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// } else if (individual.getVClassURI() != null) {
|
||||
// log.debug("Individual " + individual.getURI() + " with class URI " +
|
||||
// individual.getVClassURI() + ": no class found with that URI");
|
||||
// }
|
||||
// if (customView!=null) {
|
||||
// // insert test for whether a css files of the same name exists, and populate the customCss string for use when construction the header
|
||||
// }
|
||||
|
||||
//setup highlighter for search terms
|
||||
//checkForSearch(vreq, individual);
|
||||
|
||||
|
||||
return new IndividualTemplateModel(individual, vreq);
|
||||
}
|
||||
|
||||
// Determine whether the individual has a custom display template based on its class membership.
|
||||
// If not, return the default individual template.
|
||||
private String getIndividualTemplate(Individual individual) {
|
||||
|
||||
String vclassName = "unknown";
|
||||
String customTemplate = null;
|
||||
|
||||
if( individual.getVClass() != null ){
|
||||
vclassName = individual.getVClass().getName();
|
||||
List<VClass> clasList = individual.getVClasses(true);
|
||||
for (VClass clas : clasList) {
|
||||
customTemplate = clas.getCustomDisplayView();
|
||||
if (customTemplate != null) {
|
||||
if (customTemplate.length()>0) {
|
||||
vclassName = clas.getName(); // reset entity vclassname to name of class where a custom view
|
||||
log.debug("Found direct class ["+clas.getName()+"] with custom view "+customTemplate+"; resetting entity vclassName to this class");
|
||||
break;
|
||||
} else {
|
||||
customTemplate = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (customTemplate == null) { //still
|
||||
clasList = individual.getVClasses(false);
|
||||
for (VClass clas : clasList) {
|
||||
customTemplate = clas.getCustomDisplayView();
|
||||
if (customTemplate != null) {
|
||||
if (customTemplate.length()>0) {
|
||||
// note that NOT changing entity vclassName here yet
|
||||
log.debug("Found inferred class ["+clas.getName()+"] with custom view "+customTemplate);
|
||||
break;
|
||||
} else {
|
||||
customTemplate = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} else if (individual.getVClassURI() != null) {
|
||||
log.debug("Individual " + individual.getURI() + " with class URI " +
|
||||
individual.getVClassURI() + ": no class found with that URI");
|
||||
}
|
||||
|
||||
return customTemplate != null ? customTemplate : TEMPLATE_INDIVIDUAL_DEFAULT;
|
||||
|
||||
}
|
||||
|
||||
private ResponseValues doRdf(VitroRequest vreq, Individual individual,
|
||||
ContentType rdfFormat) throws IOException, ServletException {
|
||||
|
@ -251,6 +258,7 @@ public class IndividualController extends FreemarkerHttpServlet {
|
|||
return new RdfResponseValues(rdfFormat, newModel);
|
||||
}
|
||||
|
||||
// RY **** Remove "fm" from the patterns when switching web.xml to this controller.
|
||||
private static Pattern LINKED_DATA_URL = Pattern.compile("^/individualfm/([^/]*)$");
|
||||
private static Pattern NS_PREFIX_URL = Pattern.compile("^/individualfm/([^/]*)/([^/]*)$");
|
||||
|
||||
|
|
|
@ -27,13 +27,15 @@ public class SiteAdminController extends FreemarkerHttpServlet {
|
|||
|
||||
private static final long serialVersionUID = 1L;
|
||||
private static final Log log = LogFactory.getLog(SiteAdminController.class);
|
||||
|
||||
private static final String TEMPLATE_DEFAULT = "siteAdmin-main.ftl";
|
||||
|
||||
@Override
|
||||
public String getTitle(String siteName) {
|
||||
return siteName + " Site Administration";
|
||||
}
|
||||
|
||||
// Uncomment this once the login page has been separated from the site admin page.
|
||||
// You also need to change UrlBuilder.Route.LOGIN path to "/login".
|
||||
// @Override
|
||||
// protected boolean requiresLogin() {
|
||||
// // User must be logged in to view this page.
|
||||
|
|
|
@ -31,7 +31,7 @@ public class UrlBuilder {
|
|||
INDIVIDUAL("/individual"),
|
||||
INDIVIDUAL_EDIT("/entityEdit"),
|
||||
INDIVIDUAL_LIST("/individuallist"),
|
||||
LOGIN("/siteAdmin"),
|
||||
LOGIN("/siteAdmin"), // when login page is separated from site admin page, change to "/login"
|
||||
LOGOUT("/login_process.jsp"),
|
||||
SEARCH("/search"),
|
||||
SITE_ADMIN("/siteAdmin"),
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue