CCM NG: Todays progress of getting Bebop running in full Java EE 7 environment

git-svn-id: https://svn.libreccm.org/ccm/ccm_ng@3839 8810af33-2d31-482b-a856-94f89814c4df
pull/2/head
jensp 2016-02-03 19:00:18 +00:00
parent 9b6c50fd8a
commit f446d50fc7
10 changed files with 183 additions and 103 deletions

View File

@ -0,0 +1,3 @@
version = 7.0.0-SNAPSHOT
appname = LibreCCM
apphomepage = http://www.libreccm.org

View File

@ -18,6 +18,7 @@
*/ */
package com.arsdigita.ui.admin; package com.arsdigita.ui.admin;
import com.arsdigita.bebop.Label;
import com.arsdigita.bebop.Page; import com.arsdigita.bebop.Page;
import com.arsdigita.bebop.PageFactory; import com.arsdigita.bebop.PageFactory;
import com.arsdigita.bebop.TabbedPane; import com.arsdigita.bebop.TabbedPane;
@ -31,6 +32,7 @@ import com.arsdigita.xml.Document;
import org.apache.shiro.subject.Subject; import org.apache.shiro.subject.Subject;
import org.libreccm.cdi.utils.CdiUtil; import org.libreccm.cdi.utils.CdiUtil;
import org.libreccm.configuration.ConfigurationManager;
import org.libreccm.security.PermissionChecker; import org.libreccm.security.PermissionChecker;
import org.libreccm.web.CcmApplication; import org.libreccm.web.CcmApplication;
@ -38,6 +40,7 @@ import java.io.IOException;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import javax.inject.Inject;
import javax.servlet.ServletException; import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet; import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
@ -61,10 +64,12 @@ import static com.arsdigita.ui.admin.AdminConstants.*;
* @author pb * @author pb
*/ */
@WebServlet(urlPatterns = {ADMIN_SERVLET_PATH}) @WebServlet(urlPatterns = {ADMIN_SERVLET_PATH})
public class AdminServlet extends BaseApplicationServlet implements public class AdminServlet
AdminConstants { extends BaseApplicationServlet
implements AdminConstants {
private static final long serialVersionUID = -3912367600768871630L; private static final long serialVersionUID = -3912367600768871630L;
/** /**
* Logger instance for debugging * Logger instance for debugging
*/ */
@ -82,7 +87,7 @@ public class AdminServlet extends BaseApplicationServlet implements
*/ */
@Override @Override
public void doInit() throws ServletException { public void doInit() throws ServletException {
addPage("/", buildAdminIndexPage()); // index page at address ~/ds //addPage("/", buildAdminIndexPage()); // index page at address ~/ds
// addPage("/index.jsp", buildIndexPage()); // index page at address ~/ds // addPage("/index.jsp", buildIndexPage()); // index page at address ~/ds
} }
@ -107,7 +112,8 @@ public class AdminServlet extends BaseApplicationServlet implements
/* Determine access privilege: only logged in users may access */ /* Determine access privilege: only logged in users may access */
final CdiUtil cdiUtil = new CdiUtil(); final CdiUtil cdiUtil = new CdiUtil();
final Subject subject = cdiUtil.findBean(Subject.class); final Subject subject = cdiUtil.findBean(Subject.class);
final PermissionChecker permissionChecker = cdiUtil.findBean(PermissionChecker.class); final PermissionChecker permissionChecker = cdiUtil.findBean(
PermissionChecker.class);
if (!subject.isAuthenticated()) { if (!subject.isAuthenticated()) {
throw new LoginSignal(sreq); throw new LoginSignal(sreq);
@ -133,14 +139,19 @@ public class AdminServlet extends BaseApplicationServlet implements
pathInfo = pathInfo.substring(0, pathInfo.length() - 1); pathInfo = pathInfo.substring(0, pathInfo.length() - 1);
} }
final Page page = pages.get(pathInfo); // final Page page = pages.get(pathInfo);
if (page == null) { // if (page == null) {
sresp.sendError(404, "No such page for path " + pathInfo); // sresp.sendError(404, "No such page for path " + pathInfo);
} else { // } else {
// final Document doc = page.buildDocument(sreq, sresp);
// Templating.getPresentationManager().servePage(doc, sreq, sresp);
// }
final Page page = new Page();
page.add(new Label("admin"));
final Document doc = page.buildDocument(sreq, sresp); final Document doc = page.buildDocument(sreq, sresp);
Templating.getPresentationManager().servePage(doc, sreq, sresp); Templating.getPresentationManager().servePage(doc, sreq, sresp);
} }
}
/** /**
* Adds one pair of Url - Page to the internal hash map, used as a cache. * Adds one pair of Url - Page to the internal hash map, used as a cache.

View File

@ -129,11 +129,20 @@ public class ChangePasswordForm extends Form
final KernelConfig kernelConfig = KernelConfig.getConfig(); final KernelConfig kernelConfig = KernelConfig.getConfig();
final User user = shiro.getUser(); final User user = shiro.getUser();
final Label greeting = new Label(LoginHelper.getMessage( final Label greeting;
if (user == null) {
greeting = new Label(LoginHelper.getMessage(
"login.changePasswordForm.greeting",
new Object[]{String.format("%s %s",
"",
"")}));
} else {
greeting = new Label(LoginHelper.getMessage(
"login.changePasswordForm.greeting", "login.changePasswordForm.greeting",
new Object[]{String.format("%s %s", new Object[]{String.format("%s %s",
user.getGivenName(), user.getGivenName(),
user.getFamilyName())})); user.getFamilyName())}));
}
greeting.setFontWeight(Label.BOLD); greeting.setFontWeight(Label.BOLD);
greeting.setClassAttr("greeting"); greeting.setClassAttr("greeting");
add(greeting); add(greeting);

View File

@ -35,7 +35,9 @@ import com.arsdigita.web.ReturnSignal;
import com.arsdigita.web.URL; import com.arsdigita.web.URL;
import org.apache.log4j.Logger; import org.apache.log4j.Logger;
import org.libreccm.configuration.ConfigurationManager;
import javax.inject.Inject;
import javax.servlet.ServletException; import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet; import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
@ -125,6 +127,9 @@ public class LoginServlet extends BebopApplicationServlet {
public static final String APPLICATION_NAME = "login"; public static final String APPLICATION_NAME = "login";
@Inject
private ConfigurationManager confManager;
/** /**
* User extension point used to create the pages to server and setup a * User extension point used to create the pages to server and setup a
* URL_MSG - page mapping. * URL_MSG - page mapping.
@ -133,6 +138,9 @@ public class LoginServlet extends BebopApplicationServlet {
*/ */
@Override @Override
public void doInit() throws ServletException { public void doInit() throws ServletException {
final SecurityConfig securityConfig = confManager.findConfiguration(
SecurityConfig.class);
// Allow world caching for pages without authentication, // Allow world caching for pages without authentication,
// ie, /register, /register/explain-persistent-cookies, // ie, /register, /register/explain-persistent-cookies,
// /register/login-expired, /register/recover-password // /register/login-expired, /register/recover-password
@ -145,8 +153,7 @@ public class LoginServlet extends BebopApplicationServlet {
put("/", put("/",
buildSimplePage( buildSimplePage(
"login.userRegistrationForm.title", "login.userRegistrationForm.title",
new UserLoginForm(SecurityConfig.getConfig() new UserLoginForm(securityConfig.isAutoRegistrationEnabled()),
.isAutoRegistrationEnabled()),
"login")); "login"));
disableClientCaching("/"); disableClientCaching("/");

View File

@ -100,7 +100,7 @@ public class UserLoginForm extends Form implements LoginConstants,
private TextField m_loginName; private TextField m_loginName;
private final Password m_password; private final Password m_password;
private final boolean m_autoRegistrationOn; private final boolean m_autoRegistrationOn;
private final SecurityConfig securityConfig = SecurityConfig.getConfig(); private final SecurityConfig securityConfig;// = SecurityConfig.getConfig();
/** /**
* Default constructor delegates to a constructor which creates a LoginForm * Default constructor delegates to a constructor which creates a LoginForm
@ -128,6 +128,8 @@ public class UserLoginForm extends Form implements LoginConstants,
final boolean autoRegistrationOn) { final boolean autoRegistrationOn) {
super(FORM_NAME, panel); super(FORM_NAME, panel);
securityConfig = SecurityConfig.getConfig();
setMethod(Form.POST); setMethod(Form.POST);
addInitListener(this); addInitListener(this);
addValidationListener(this); addValidationListener(this);

View File

@ -25,6 +25,7 @@ import org.libreccm.web.CcmApplication;
import java.io.IOException; import java.io.IOException;
import javax.inject.Inject;
import javax.servlet.ServletException; import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
@ -86,6 +87,12 @@ public abstract class BaseApplicationServlet extends BaseServlet {
*/ */
public static final String APPLICATION_ID_PARAMETER = "app-id"; public static final String APPLICATION_ID_PARAMETER = "app-id";
/**
* {@link ApplicationRepository} provided by CDI.
*/
@Inject
private ApplicationRepository appRepository;
/** /**
* <p> * <p>
* Augments the context of the request and delegates to {@link * Augments the context of the request and delegates to {@link
@ -174,10 +181,7 @@ public abstract class BaseApplicationServlet extends BaseServlet {
+ "database"); + "database");
} }
final CdiUtil cdiUtil = new CdiUtil(); return appRepository.findById(appId);
final ApplicationRepository appRepo = cdiUtil.findBean(
ApplicationRepository.class);
return appRepo.findById(appId);
} }
/** /**

View File

@ -86,11 +86,23 @@ public abstract class BaseServlet extends HttpServlet {
private void internalService(final HttpServletRequest request, private void internalService(final HttpServletRequest request,
final HttpServletResponse response) final HttpServletResponse response)
throws ServletException, IOException { throws ServletException, IOException {
//This method was present in the old implemention and was responsible
//for managing the application managed transactions. Because we now use
//container managed transactions we may don't need this method anymore.
Web.init(request, getServletContext());
Web.getWebContext().setRequestURL(getRequestURL(request));
try {
doService(request, response); doService(request, response);
} catch (RedirectSignal signal) {
redirect(response, signal);
} catch (ServletException ex) {
final RedirectSignal signal = findRedirectSignal(ex);
if (signal == null) {
throw ex;
} else {
redirect(response, signal);
}
}
} }
/** /**
@ -135,14 +147,17 @@ public abstract class BaseServlet extends HttpServlet {
} }
/** /**
* <p>Processes HTTP POST requests.</p> * <p>
* Processes HTTP POST requests.</p>
* *
* @param request * @param request
* @param response * @param response
*
* @throws javax.servlet.ServletException * @throws javax.servlet.ServletException
* @throws java.io.IOException * @throws java.io.IOException
* *
* @see javax.servlet.http.HttpServlet#doPost(HttpServletRequest,HttpServletResponse) * @see
* javax.servlet.http.HttpServlet#doPost(HttpServletRequest,HttpServletResponse)
*/ */
@Override @Override
protected final void doPost(final HttpServletRequest request, protected final void doPost(final HttpServletRequest request,
@ -156,4 +171,37 @@ public abstract class BaseServlet extends HttpServlet {
internalService(request, response); internalService(request, response);
} }
private URL getRequestURL(final HttpServletRequest request) {
URL url = (URL) request.getAttribute(REQUEST_URL_ATTRIBUTE);
if (url == null) {
url = new URL(request);
}
return url;
}
private RedirectSignal findRedirectSignal(final ServletException ex) {
Throwable root = ex.getRootCause();
while (root instanceof ServletException) {
root = ((ServletException) root).getRootCause();
}
if (root instanceof RedirectSignal) {
return (RedirectSignal) root;
} else {
return null;
}
}
private void redirect(final HttpServletResponse response,
final RedirectSignal redirectSignal)
throws IOException {
final String url = response.encodeRedirectURL(redirectSignal
.getDestinationURL());
response.sendRedirect(url);
}
} }

View File

@ -40,6 +40,7 @@ import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
import org.apache.shiro.subject.Subject; import org.apache.shiro.subject.Subject;
import org.libreccm.configuration.ConfigurationManager;
import org.libreccm.web.ApplicationManager; import org.libreccm.web.ApplicationManager;
import org.libreccm.web.ApplicationType; import org.libreccm.web.ApplicationType;

View File

@ -47,8 +47,7 @@ public class Web {
*/ */
private static final Logger s_log = Logger.getLogger(Web.class); private static final Logger s_log = Logger.getLogger(Web.class);
private static final WebConfig s_config = WebConfig.getConfig(); // private static final WebConfig s_config = WebConfig.getConfig();
private static final ThreadLocal s_request = new InternalRequestLocal(); private static final ThreadLocal s_request = new InternalRequestLocal();
private static final ThreadLocal s_servletContext private static final ThreadLocal s_servletContext
= new InternalRequestLocal(); = new InternalRequestLocal();
@ -93,7 +92,8 @@ public class Web {
* @return A <code>WebConfig</code> configuration record; it cannot be null * @return A <code>WebConfig</code> configuration record; it cannot be null
*/ */
public static WebConfig getConfig() { public static WebConfig getConfig() {
return s_config; // return s_config;
return WebConfig.getConfig();
} }
/** /**
@ -129,12 +129,12 @@ public class Web {
/** /**
* Gets the webapp context path portion of the WEB application where this * Gets the webapp context path portion of the WEB application where this
* CCM instance is executed. (I.e. where the WEB-INF directory is located * CCM instance is executed. (I.e. where the WEB-INF directory is located in
* in the servlet container webapps directory, known as ServletContext in * the servlet container webapps directory, known as ServletContext in the
* the Servlet API) * Servlet API)
* *
* @return web context path portion as a String, may be used to construct * @return web context path portion as a String, may be used to construct a
* a URL (NOT the RealPath!). The ROOT context returns an empty * URL (NOT the RealPath!). The ROOT context returns an empty
* String(""). * String("").
*/ */
public static String getWebappContextPath() { public static String getWebappContextPath() {
@ -143,10 +143,9 @@ public class Web {
/** /**
* Sets the webapp context path portion of the WEB application where this * Sets the webapp context path portion of the WEB application where this
* CCM instance is executed. (I.e. where the WEB-INF directory is located * CCM instance is executed. (I.e. where the WEB-INF directory is located in
* in the servlet container webapps directory, known as ServletContext in * the servlet container webapps directory, known as ServletContext in the
* the Servlet API) * Servlet API) Meant to be executed by CCMDispatcherServlet only.
* Meant to be executed by CCMDispatcherServlet only.
* *
* @param contextPath * @param contextPath
*/ */
@ -154,7 +153,6 @@ public class Web {
s_contextPath = contextPath; s_contextPath = contextPath;
} }
/** /**
* Processes an URL String trying to identify a corresponding recource which * Processes an URL String trying to identify a corresponding recource which
* is mapped to the given path String. The method ensures that the resource * is mapped to the given path String. The method ensures that the resource
@ -249,11 +247,9 @@ public class Web {
s_log.debug("Got URL " + url + " for " + path); s_log.debug("Got URL " + url + " for " + path);
} }
return url; // Return adjusted resourcePath url return url; // Return adjusted resourcePath url
} else { } else if (s_log.isDebugEnabled()) {
if (s_log.isDebugEnabled()) {
s_log.debug("No URL present for " + path); s_log.debug("No URL present for " + path);
} }
}
} catch (MalformedURLException exc) { } catch (MalformedURLException exc) {
if (s_log.isDebugEnabled()) { if (s_log.isDebugEnabled()) {
s_log.debug("cannot get resource for " + path); s_log.debug("cannot get resource for " + path);
@ -299,11 +295,9 @@ public class Web {
s_log.debug("Got URL " + url + " for " + path); s_log.debug("Got URL " + url + " for " + path);
} }
return url; // Return adjusted resourcePath url return url; // Return adjusted resourcePath url
} else { } else if (s_log.isDebugEnabled()) {
if (s_log.isDebugEnabled()) {
s_log.debug("No URL present for " + path); s_log.debug("No URL present for " + path);
} }
}
} catch (MalformedURLException ex) { } catch (MalformedURLException ex) {
if (s_log.isDebugEnabled()) { if (s_log.isDebugEnabled()) {
s_log.debug("cannot get resource for " + path); s_log.debug("cannot get resource for " + path);

View File

@ -31,6 +31,7 @@ import java.util.Set;
import javax.persistence.Column; import javax.persistence.Column;
import javax.persistence.ElementCollection; import javax.persistence.ElementCollection;
import javax.persistence.Embeddable; import javax.persistence.Embeddable;
import javax.persistence.FetchType;
import javax.persistence.Lob; import javax.persistence.Lob;
import javax.persistence.MapKeyColumn; import javax.persistence.MapKeyColumn;
import javax.xml.bind.annotation.XmlElement; import javax.xml.bind.annotation.XmlElement;
@ -54,7 +55,7 @@ public class LocalizedString implements Serializable {
/** /**
* The localised values of the string. * The localised values of the string.
*/ */
@ElementCollection @ElementCollection(fetch = FetchType.EAGER)
@MapKeyColumn(name = "LOCALE") @MapKeyColumn(name = "LOCALE")
@Column(name = "LOCALIZED_VALUE") @Column(name = "LOCALIZED_VALUE")
@Lob @Lob