Use login widget on login page.
This commit is contained in:
parent
2973ceebf2
commit
252edbe863
12 changed files with 79 additions and 76 deletions
|
@ -386,6 +386,15 @@
|
||||||
<url-pattern>/siteAdmin.jsp</url-pattern>
|
<url-pattern>/siteAdmin.jsp</url-pattern>
|
||||||
</servlet-mapping>
|
</servlet-mapping>
|
||||||
|
|
||||||
|
<servlet>
|
||||||
|
<servlet-name>EmptyController</servlet-name>
|
||||||
|
<servlet-class>edu.cornell.mannlib.vitro.webapp.controller.freemarker.EmptyController</servlet-class>
|
||||||
|
</servlet>
|
||||||
|
<servlet-mapping>
|
||||||
|
<servlet-name>EmptyController</servlet-name>
|
||||||
|
<url-pattern>/login</url-pattern>
|
||||||
|
</servlet-mapping>
|
||||||
|
|
||||||
<servlet>
|
<servlet>
|
||||||
<servlet-name>RevisionInfoController</servlet-name>
|
<servlet-name>RevisionInfoController</servlet-name>
|
||||||
<servlet-class>edu.cornell.mannlib.vitro.webapp.controller.freemarker.RevisionInfoController</servlet-class>
|
<servlet-class>edu.cornell.mannlib.vitro.webapp.controller.freemarker.RevisionInfoController</servlet-class>
|
||||||
|
@ -1239,10 +1248,12 @@
|
||||||
<servlet-name>authenticate</servlet-name>
|
<servlet-name>authenticate</servlet-name>
|
||||||
<url-pattern>/authenticate</url-pattern>
|
<url-pattern>/authenticate</url-pattern>
|
||||||
</servlet-mapping>
|
</servlet-mapping>
|
||||||
|
<!--
|
||||||
<servlet-mapping>
|
<servlet-mapping>
|
||||||
<servlet-name>login</servlet-name>
|
<servlet-name>login</servlet-name>
|
||||||
<url-pattern>/login</url-pattern>
|
<url-pattern>/login</url-pattern>
|
||||||
</servlet-mapping>
|
</servlet-mapping>
|
||||||
|
-->
|
||||||
<servlet-mapping>
|
<servlet-mapping>
|
||||||
<servlet-name>loginShibboleth</servlet-name>
|
<servlet-name>loginShibboleth</servlet-name>
|
||||||
<url-pattern>/loginShibboleth</url-pattern>
|
<url-pattern>/loginShibboleth</url-pattern>
|
||||||
|
|
|
@ -33,7 +33,7 @@ public class Controllers {
|
||||||
public static final String TAB_ENTITIES = "/TabEntitiesController";
|
public static final String TAB_ENTITIES = "/TabEntitiesController";
|
||||||
|
|
||||||
public static final String SITE_ADMIN = "/siteAdmin";
|
public static final String SITE_ADMIN = "/siteAdmin";
|
||||||
public static final String LOGIN = "/siteAdmin";
|
public static final String LOGIN = "/login";
|
||||||
public static final String AUTHENTICATE = "/authenticate";
|
public static final String AUTHENTICATE = "/authenticate";
|
||||||
|
|
||||||
public static final String EXPORT_RDF = "/export";
|
public static final String EXPORT_RDF = "/export";
|
||||||
|
|
|
@ -3,7 +3,6 @@
|
||||||
package edu.cornell.mannlib.vitro.webapp.controller.authenticate;
|
package edu.cornell.mannlib.vitro.webapp.controller.authenticate;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.UnsupportedEncodingException;
|
|
||||||
import java.net.URLEncoder;
|
import java.net.URLEncoder;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
@ -107,9 +106,9 @@ public class LoginRedirector {
|
||||||
|
|
||||||
/** What's the URL for the site admin screen? */
|
/** What's the URL for the site admin screen? */
|
||||||
private String getSiteAdminUrl(HttpServletRequest request) {
|
private String getSiteAdminUrl(HttpServletRequest request) {
|
||||||
|
// return Route.SITE_ADMIN.url();
|
||||||
String contextPath = request.getContextPath();
|
String contextPath = request.getContextPath();
|
||||||
String urlParams = "?login=block";
|
return contextPath + Controllers.SITE_ADMIN;
|
||||||
return contextPath + Controllers.SITE_ADMIN + urlParams;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Get a reference to the Authenticator. */
|
/** Get a reference to the Authenticator. */
|
||||||
|
|
|
@ -55,16 +55,6 @@ public class Authenticate extends VitroHttpServlet {
|
||||||
/** If this parameter is "true" (ignoring case), cancel the login. */
|
/** If this parameter is "true" (ignoring case), cancel the login. */
|
||||||
private static final String PARAMETER_CANCEL = "cancel";
|
private static final String PARAMETER_CANCEL = "cancel";
|
||||||
|
|
||||||
/** If they are logging in, show them this form. */
|
|
||||||
public static final String TEMPLATE_LOGIN = "login-form.ftl";
|
|
||||||
|
|
||||||
/** If they are changing their password on first login, show them this form. */
|
|
||||||
public static final String TEMPLATE_FORCE_PASSWORD_CHANGE = "login-forcedPasswordChange.ftl";
|
|
||||||
|
|
||||||
public static final String BODY_LOGIN_NAME = "loginName";
|
|
||||||
public static final String BODY_FORM_ACTION = "formAction";
|
|
||||||
public static final String BODY_ERROR_MESSAGE = "errorMessage";
|
|
||||||
|
|
||||||
/** Where do we find the User/Session map in the servlet context? */
|
/** Where do we find the User/Session map in the servlet context? */
|
||||||
public static final String USER_SESSION_MAP_ATTR = "userURISessionMap";
|
public static final String USER_SESSION_MAP_ATTR = "userURISessionMap";
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,36 @@
|
||||||
|
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
|
||||||
|
|
||||||
|
package edu.cornell.mannlib.vitro.webapp.controller.freemarker;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
import org.apache.commons.logging.Log;
|
||||||
|
import org.apache.commons.logging.LogFactory;
|
||||||
|
|
||||||
|
import edu.cornell.mannlib.vitro.webapp.beans.Portal;
|
||||||
|
import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest;
|
||||||
|
import edu.cornell.mannlib.vitro.webapp.controller.freemarker.FreemarkerHttpServlet.ResponseValues;
|
||||||
|
import edu.cornell.mannlib.vitro.webapp.controller.freemarker.FreemarkerHttpServlet.TemplateResponseValues;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Servlet that only specifies a template, without putting any data
|
||||||
|
* into the template model.
|
||||||
|
*/
|
||||||
|
public class EmptyController extends FreemarkerHttpServlet {
|
||||||
|
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
private static final Log log = LogFactory.getLog(EmptyController.class);
|
||||||
|
|
||||||
|
private static final Map<String, String> urlsToTemplates = new HashMap<String, String>(){
|
||||||
|
{
|
||||||
|
put("/login", "login.ftl");
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
protected ResponseValues processRequest(VitroRequest vreq) {
|
||||||
|
String requestedUrl = vreq.getServletPath();
|
||||||
|
String templateName = urlsToTemplates.get(requestedUrl);
|
||||||
|
return new TemplateResponseValues(templateName);
|
||||||
|
}
|
||||||
|
}
|
|
@ -82,8 +82,9 @@ public class FreemarkerHttpServlet extends VitroHttpServlet {
|
||||||
|
|
||||||
ResponseValues responseValues;
|
ResponseValues responseValues;
|
||||||
|
|
||||||
|
// checkLoginStatus() does a redirect if the user is not logged in.
|
||||||
if (requiresLogin() && !checkLoginStatus(request, response)) {
|
if (requiresLogin() && !checkLoginStatus(request, response)) {
|
||||||
responseValues = new RedirectResponseValues(UrlBuilder.Route.LOGIN.path());
|
return;
|
||||||
} else {
|
} else {
|
||||||
responseValues = processRequest(vreq);
|
responseValues = processRequest(vreq);
|
||||||
}
|
}
|
||||||
|
@ -299,7 +300,7 @@ public class FreemarkerHttpServlet extends VitroHttpServlet {
|
||||||
urls.put("termsOfUse", urlBuilder.getPortalUrl(Route.TERMS_OF_USE));
|
urls.put("termsOfUse", urlBuilder.getPortalUrl(Route.TERMS_OF_USE));
|
||||||
urls.put("login", urlBuilder.getPortalUrl(Route.LOGIN));
|
urls.put("login", urlBuilder.getPortalUrl(Route.LOGIN));
|
||||||
urls.put("logout", urlBuilder.getLogoutUrl());
|
urls.put("logout", urlBuilder.getLogoutUrl());
|
||||||
urls.put("siteAdmin", urlBuilder.getPortalUrl(Route.LOGIN));
|
urls.put("siteAdmin", urlBuilder.getPortalUrl(Route.SITE_ADMIN));
|
||||||
urls.put("siteIcons", urlBuilder.getPortalUrl(themeDir + "/site_icons"));
|
urls.put("siteIcons", urlBuilder.getPortalUrl(themeDir + "/site_icons"));
|
||||||
urls.put("themeImages", urlBuilder.getPortalUrl(themeDir + "/images"));
|
urls.put("themeImages", urlBuilder.getPortalUrl(themeDir + "/images"));
|
||||||
urls.put("images", urlBuilder.getUrl("/images"));
|
urls.put("images", urlBuilder.getUrl("/images"));
|
||||||
|
|
|
@ -34,13 +34,11 @@ public class SiteAdminController extends FreemarkerHttpServlet {
|
||||||
return siteName + " Site Administration";
|
return siteName + " Site Administration";
|
||||||
}
|
}
|
||||||
|
|
||||||
// Uncomment this once the login page has been separated from the site admin page.
|
@Override
|
||||||
// You also need to change UrlBuilder.Route.LOGIN path to "/login".
|
protected boolean requiresLogin() {
|
||||||
// @Override
|
// User must be logged in to view this page.
|
||||||
// protected boolean requiresLogin() {
|
return true;
|
||||||
// // User must be logged in to view this page.
|
}
|
||||||
// return true;
|
|
||||||
// }
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected ResponseValues processRequest(VitroRequest vreq) {
|
protected ResponseValues processRequest(VitroRequest vreq) {
|
||||||
|
@ -49,63 +47,28 @@ public class SiteAdminController extends FreemarkerHttpServlet {
|
||||||
|
|
||||||
Map<String, Object> body = new HashMap<String, Object>();
|
Map<String, Object> body = new HashMap<String, Object>();
|
||||||
|
|
||||||
// NOT LOGGED IN: just show login form
|
if (loginBean.isLoggedInAtLeast(LoginStatusBean.EDITOR)) {
|
||||||
if (!loginBean.isLoggedIn()) {
|
|
||||||
// Unlike the other panels on this page, we put the data directly in the body, because the templates are also used
|
|
||||||
// by the JSP version, where the data is placed directly in the body map.
|
|
||||||
body.putAll(getLoginPanelData(vreq));
|
|
||||||
|
|
||||||
// LOGGED IN: show editing options based on user role
|
UrlBuilder urlBuilder = new UrlBuilder(vreq.getPortal());
|
||||||
} else {
|
|
||||||
|
|
||||||
if (loginBean.isLoggedInAtLeast(LoginStatusBean.EDITOR)) {
|
body.put("dataInput", getDataInputData(vreq));
|
||||||
|
|
||||||
UrlBuilder urlBuilder = new UrlBuilder(vreq.getPortal());
|
if (loginBean.isLoggedInAtLeast(LoginStatusBean.CURATOR)) {
|
||||||
|
body.put("siteConfig", getSiteConfigurationData(vreq, urlBuilder));
|
||||||
|
body.put("ontologyEditor", getOntologyEditorData(vreq, urlBuilder));
|
||||||
|
|
||||||
body.put("dataInput", getDataInputData(vreq));
|
if (loginBean.isLoggedInAtLeast(LoginStatusBean.DBA)) {
|
||||||
|
body.put("dataTools", getDataToolsData(vreq, urlBuilder));
|
||||||
|
|
||||||
if (loginBean.isLoggedInAtLeast(LoginStatusBean.CURATOR)) {
|
// Only for DataStar. Should handle without needing a DataStar-specific version of this controller.
|
||||||
body.put("siteConfig", getSiteConfigurationData(vreq, urlBuilder));
|
//body.put("customReports", getCustomReportsData(vreq));
|
||||||
body.put("ontologyEditor", getOntologyEditorData(vreq, urlBuilder));
|
|
||||||
|
|
||||||
if (loginBean.isLoggedInAtLeast(LoginStatusBean.DBA)) {
|
|
||||||
body.put("dataTools", getDataToolsData(vreq, urlBuilder));
|
|
||||||
|
|
||||||
// Only for DataStar. Should handle without needing a DataStar-specific version of this controller.
|
|
||||||
//body.put("customReports", getCustomReportsData(vreq));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Not used
|
|
||||||
// int languageProfile = wadf.getLanguageProfile();
|
|
||||||
// String languageMode = null;
|
|
||||||
// if ( 200 <= languageProfile && languageProfile < 300 ) {
|
|
||||||
// languageMode = "OWL Mode";
|
|
||||||
// } else if ( 100 == languageProfile ) {
|
|
||||||
// languageMode = "RDF Schema Mode";
|
|
||||||
// }
|
|
||||||
// body.put("languageModeStr", languageMode);
|
|
||||||
|
|
||||||
return new TemplateResponseValues(TEMPLATE_DEFAULT, body);
|
return new TemplateResponseValues(TEMPLATE_DEFAULT, body);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private Map<String, Object> getLoginPanelData(VitroRequest vreq) {
|
|
||||||
Map<String, Object> map = null;
|
|
||||||
// This is somewhat awkward, because we are trying to use the login code with as few modifications as possible
|
|
||||||
// as it was set up for the JSP version as well. We have to unpack the TemplateResponseValues
|
|
||||||
// object and put everything in a map.
|
|
||||||
TemplateResponseValues trv = new LoginTemplateHelper(vreq).showLoginPanel(vreq);
|
|
||||||
if (trv != null) {
|
|
||||||
map = new HashMap<String, Object>();
|
|
||||||
map.putAll(trv.getMap());
|
|
||||||
map.put("loginTemplate", trv.getTemplateName());
|
|
||||||
}
|
|
||||||
return map;
|
|
||||||
}
|
|
||||||
|
|
||||||
private Map<String, Object> getDataInputData(VitroRequest vreq) {
|
private Map<String, Object> getDataInputData(VitroRequest vreq) {
|
||||||
|
|
||||||
Map<String, Object> map = new HashMap<String, Object>();
|
Map<String, Object> map = new HashMap<String, Object>();
|
||||||
|
|
|
@ -77,7 +77,8 @@ public class TemplateProcessingHelper {
|
||||||
try {
|
try {
|
||||||
template = config.getTemplate(templateName);
|
template = config.getTemplate(templateName);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
log.error("Cannot get template " + templateName);
|
// RY Should probably throw this error instead.
|
||||||
|
log.error("Cannot get template " + templateName, e);
|
||||||
}
|
}
|
||||||
return template;
|
return template;
|
||||||
}
|
}
|
||||||
|
|
|
@ -31,7 +31,7 @@ public class UrlBuilder {
|
||||||
INDIVIDUAL("/individual"),
|
INDIVIDUAL("/individual"),
|
||||||
INDIVIDUAL_EDIT("/entityEdit"),
|
INDIVIDUAL_EDIT("/entityEdit"),
|
||||||
INDIVIDUAL_LIST("/individuallist"),
|
INDIVIDUAL_LIST("/individuallist"),
|
||||||
LOGIN("/siteAdmin"), // when login page is separated from site admin page, change to "/login"
|
LOGIN("/login"),
|
||||||
LOGOUT("/login_process.jsp"),
|
LOGOUT("/login_process.jsp"),
|
||||||
SEARCH("/search"),
|
SEARCH("/search"),
|
||||||
SITE_ADMIN("/siteAdmin"),
|
SITE_ADMIN("/siteAdmin"),
|
||||||
|
|
|
@ -80,7 +80,7 @@ public class LoginWidget extends Widget {
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
log.error(e);
|
log.error(e);
|
||||||
values = showError(e);
|
values = showError(e);
|
||||||
}
|
}
|
||||||
values.put("urls", urls);
|
values.put("urls", urls);
|
||||||
return values;
|
return values;
|
||||||
|
|
|
@ -28,6 +28,7 @@ import edu.cornell.mannlib.vitro.testing.AbstractTestClass;
|
||||||
import edu.cornell.mannlib.vitro.webapp.beans.User;
|
import edu.cornell.mannlib.vitro.webapp.beans.User;
|
||||||
import edu.cornell.mannlib.vitro.webapp.controller.Controllers;
|
import edu.cornell.mannlib.vitro.webapp.controller.Controllers;
|
||||||
import edu.cornell.mannlib.vitro.webapp.controller.authenticate.AuthenticatorStub;
|
import edu.cornell.mannlib.vitro.webapp.controller.authenticate.AuthenticatorStub;
|
||||||
|
import edu.cornell.mannlib.vitro.webapp.controller.freemarker.UrlBuilder;
|
||||||
import edu.cornell.mannlib.vitro.webapp.controller.login.LoginProcessBean;
|
import edu.cornell.mannlib.vitro.webapp.controller.login.LoginProcessBean;
|
||||||
import edu.cornell.mannlib.vitro.webapp.controller.login.LoginProcessBean.State;
|
import edu.cornell.mannlib.vitro.webapp.controller.login.LoginProcessBean.State;
|
||||||
|
|
||||||
|
@ -46,8 +47,8 @@ public class AuthenticateTest extends AbstractTestClass {
|
||||||
|
|
||||||
private static final String URL_LOGIN_PAGE = "http://my.local.site/vivo/"
|
private static final String URL_LOGIN_PAGE = "http://my.local.site/vivo/"
|
||||||
+ Controllers.LOGIN;
|
+ Controllers.LOGIN;
|
||||||
private static final String URL_SITE_ADMIN_PAGE = Controllers.SITE_ADMIN
|
private static final String URL_SITE_ADMIN_PAGE = Controllers.SITE_ADMIN;
|
||||||
+ "?login=block";
|
|
||||||
private static final String URL_HOME_PAGE = "";
|
private static final String URL_HOME_PAGE = "";
|
||||||
private static final String URL_SESSION_REDIRECT = "/sessionRedirect";
|
private static final String URL_SESSION_REDIRECT = "/sessionRedirect";
|
||||||
private static final String URL_CONTEXT_REDIRECT_LOCAL = "/servletContextRedirect";
|
private static final String URL_CONTEXT_REDIRECT_LOCAL = "/servletContextRedirect";
|
||||||
|
@ -90,6 +91,7 @@ public class AuthenticateTest extends AbstractTestClass {
|
||||||
|
|
||||||
auth = new Authenticate();
|
auth = new Authenticate();
|
||||||
auth.init(servletConfig);
|
auth.init(servletConfig);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private User createNewDbaUser() {
|
private User createNewDbaUser() {
|
||||||
|
|
Loading…
Add table
Reference in a new issue