diff --git a/ccm-core/src/main/java/com/arsdigita/ui/login/LoginApplicationCreator.java b/ccm-core/src/main/java/com/arsdigita/ui/login/LoginApplicationCreator.java new file mode 100644 index 000000000..4474c522c --- /dev/null +++ b/ccm-core/src/main/java/com/arsdigita/ui/login/LoginApplicationCreator.java @@ -0,0 +1,53 @@ +/* + * Copyright (C) 2015 LibreCCM Foundation. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, + * MA 02110-1301 USA + */ +package com.arsdigita.ui.login; + +import javax.enterprise.context.RequestScoped; +import javax.inject.Inject; +import org.libreccm.web.ApplicationCreator; +import org.libreccm.web.ApplicationRepository; +import org.libreccm.web.ApplicationType; +import org.libreccm.web.CcmApplication; + +import static com.arsdigita.ui.login.LoginConstants.*; + +/** + * + * @author Jens Pelzetter + */ +@RequestScoped +public class LoginApplicationCreator implements + ApplicationCreator { + + @Inject + private ApplicationRepository appRepository; + + @Override + public CcmApplication createInstance(final String primaryUrl, + final ApplicationType type) { + if (!LOGIN_PAGE_URL.equals(primaryUrl)) { + throw new IllegalArgumentException( + "Login is a singleton application" + + "which is mounted at /login"); + } + + return appRepository.retrieveApplicationForPath(primaryUrl); + } + +} diff --git a/ccm-core/src/main/java/com/arsdigita/ui/login/LoginConstants.java b/ccm-core/src/main/java/com/arsdigita/ui/login/LoginConstants.java index 2ceebd0a0..fc59f8c31 100644 --- a/ccm-core/src/main/java/com/arsdigita/ui/login/LoginConstants.java +++ b/ccm-core/src/main/java/com/arsdigita/ui/login/LoginConstants.java @@ -47,7 +47,7 @@ public interface LoginConstants { .getMessage("login.passwordQuestion"); public final static GlobalizedMessage PASSWORD_ANSWER = LoginHelper .getMessage("login.passwordAnswer"); - public final static GlobalizedMessage URL = LoginHelper.getMessage( + public final static GlobalizedMessage URL_MSG = LoginHelper.getMessage( "login.url"); public final static GlobalizedMessage BIO = LoginHelper.getMessage( "login.bio"); @@ -95,5 +95,14 @@ public interface LoginConstants { public final static int TIMESTAMP_LIFETIME_SECS = 300; public final static int MAX_NAME_LEN = 60; + + /** URL_MSG stub of Login page in ServletPath format (with leading slash and + without trailing slash */ + // Don't modify without adapting instantiation in Loader class and + // updating existing databases (table applications)! + public final static String LOGIN_PAGE_URL = "/register"; + + public final static String LOGIN_SERVLET_PATH = "/login/*"; + } diff --git a/ccm-core/src/main/java/com/arsdigita/ui/login/LoginServlet.java b/ccm-core/src/main/java/com/arsdigita/ui/login/LoginServlet.java index f8349e8cb..8bfdfbc28 100644 --- a/ccm-core/src/main/java/com/arsdigita/ui/login/LoginServlet.java +++ b/ccm-core/src/main/java/com/arsdigita/ui/login/LoginServlet.java @@ -41,21 +41,23 @@ import javax.servlet.ServletException; import javax.servlet.annotation.WebServlet; import javax.servlet.http.HttpServletRequest; +import static com.arsdigita.ui.login.LoginConstants.*; + /** * Login Application Servlet class, central entry point to create and process * the Login application UI. * * It manages user registration page, new user page, user workspace, logout, and - * permissions admin pages. - * - * It just defines a mapping URL <-> various pages and uses the super class to - * actually server the pages. Additionally is provides service methods to expose - * various properties, especially the URL's of public subpages (e.g. logout) and - * initializes the creation of the UI. + permissions admin pages. + + It just defines a mapping URL_MSG <-> various pages and uses the super class to + actually server the pages. Additionally is provides service methods to expose + various properties, especially the URL_MSG's of public subpages (e.g. logout) and + initializes the creation of the UI. * * @author Peter Boy */ -@WebServlet(urlPatterns = {"/register*"}) +@WebServlet(urlPatterns = {LOGIN_SERVLET_PATH}) public class LoginServlet extends BebopApplicationServlet { private static final long serialVersionUID = 7783916040158924516L; @@ -114,16 +116,8 @@ public class LoginServlet extends BebopApplicationServlet { public static final String LOGOUT_PATH_INFO = "/logout/"; /** - * URL stub of Login page in ServletPath format (with leading slash and - * without trailing slash - */ - // Don't modify without adapting instantiation in Loader class and - // updating existing databases (table applications)! - public static final String LOGIN_PAGE_URL = "/register"; - - /** - * Base URL of the Login application for internal use, fetched from Login - * domain class. + * Base URL_MSG of the Login application for internal use, fetched from Login + domain class. */ private final static String s_loginURL = LOGIN_PAGE_URL; @@ -133,8 +127,8 @@ public class LoginServlet extends BebopApplicationServlet { public static final String APPLICATION_NAME = "login"; /** - * User extension point used to create the pages to server and setup a URL - - * page mapping. + * User extension point used to create the pages to server and setup a URL_MSG - + page mapping. * * @throws ServletException */ @@ -190,13 +184,13 @@ public class LoginServlet extends BebopApplicationServlet { //Disabled until we decide what procedure we will use in the future. //Certainly not the old question/answer approach because it not secure //and not user friendly. - /* Build the password recover page, retrieve its URL and store in map */ + /* Build the password recover page, retrieve its URL_MSG and store in map */ // put(RECOVER_USER_PASSWORD_PATH_INFO, // buildSimplePage("login.recoverPasswordPage.title", // new RecoverPasswordPanel(), // "recoverpassword")); - // Build the login expire page, retrieve its URL and store in map + // Build the login expire page, retrieve its URL_MSG and store in map put(LOGIN_EXPIRED_PATH_INFO, buildExpiredPage()); /* Create Logout Page and add to the page map */ @@ -325,15 +319,15 @@ public class LoginServlet extends BebopApplicationServlet { } /** - * Provides an (absolute) URL to a user profile editig page. It is relative - * to document root without any constant prefix if there is one configured. - * - * XXX This implementation starts with a leading slash and ends with a - * slash. In previous configurations String urls began without a slash in - * order to be able to provide a full URL which also contains the context - * part. Since version 5.2 the context part is handled by (new) dispatcher. - * The leading slash it API change! It's impacts have to be checked. - * (2011-02) + * Provides an (absolute) URL_MSG to a user profile editig page. It is relative + to document root without any constant prefix if there is one configured. + + XXX This implementation starts with a leading slash and ends with a + slash. In previous configurations String urls began without a slash in + order to be able to provide a full URL_MSG which also contains the context + part. Since version 5.2 the context part is handled by (new) dispatcher. + The leading slash it API change! It's impacts have to be checked. + (2011-02) * * @return url to EditUserProfile page as String */ @@ -346,16 +340,16 @@ public class LoginServlet extends BebopApplicationServlet { } /** - * Provides an (absolute URL) to an optional new user registration page - * (accessible only if activated). It is relative to document root without - * any constant prefix if there is one configured. - * - * XXX This implementation starts with a leading slash and ends with a - * slash. In previous configurations String urls began without a slash in - * order to be able to provide a full URL which also contains the context - * part. Since version 5.2 the context part is handled by (new) dispatcher. - * The leading slash it API change! It's impacts have to be checked. - * (2011-02) + * Provides an (absolute URL_MSG) to an optional new user registration page + (accessible only if activated). It is relative to document root without + any constant prefix if there is one configured. + + XXX This implementation starts with a leading slash and ends with a + slash. In previous configurations String urls began without a slash in + order to be able to provide a full URL_MSG which also contains the context + part. Since version 5.2 the context part is handled by (new) dispatcher. + The leading slash it API change! It's impacts have to be checked. + (2011-02) * * @return url to new user registration page as String */ @@ -364,16 +358,16 @@ public class LoginServlet extends BebopApplicationServlet { } /** - * Provides an absolute URL (leading slash) for a password recovery page. It - * is relative to document root without any constant prefix if there is one - * configured. - * - * XXX This implementation starts with a leading slash and ends with a - * slash. In previous configurations String urls began without a slash in - * order to be able to provide a full URL which also contains the context - * part. Since version 5.2 the context part is handled by (new) dispatcher. - * The leading slash it API change! It's impacts have tp be checked. - * (2011-02) + * Provides an absolute URL_MSG (leading slash) for a password recovery page. It + is relative to document root without any constant prefix if there is one + configured. + + XXX This implementation starts with a leading slash and ends with a + slash. In previous configurations String urls began without a slash in + order to be able to provide a full URL_MSG which also contains the context + part. Since version 5.2 the context part is handled by (new) dispatcher. + The leading slash it API change! It's impacts have tp be checked. + (2011-02) * * @return url String for new user registration page as String */ @@ -382,16 +376,16 @@ public class LoginServlet extends BebopApplicationServlet { } /** - * Provides an absolute URL (leading slash) for a cookie explanation page. + * Provides an absolute URL_MSG (leading slash) for a cookie explanation page. * It is relative to document root without any constant prefix if there is - * one configured. - * - * XXX This implementation starts with a leading slash and ends with a - * slash. In previous configurations String urls began without a slash in - * order to be able to provide a full URL which also contains the context - * part. Since version 5.2 the context part is handled by (new) dispatcher. - * The leading slash it API change! It's impacts have tp be checked. - * (2011-02) + one configured. + + XXX This implementation starts with a leading slash and ends with a + slash. In previous configurations String urls began without a slash in + order to be able to provide a full URL_MSG which also contains the context + part. Since version 5.2 the context part is handled by (new) dispatcher. + The leading slash it API change! It's impacts have tp be checked. + (2011-02) * * @return url String for new user registration page as String */ @@ -400,16 +394,16 @@ public class LoginServlet extends BebopApplicationServlet { } /** - * Provides an absolute URL (leading slash) for a login expired info page. + * Provides an absolute URL_MSG (leading slash) for a login expired info page. * It is relative to document root without any constant prefix if there is - * one configured. - * - * XXX This implementation starts with a leading slash and ends with a - * slash. In previous configurations String urls began without a slash in - * order to be able to provide a full URL which also contains the context - * part. Since version 5.2 the context part is handled by (new) dispatcher. - * The leading slash it API change! It's impacts have tp be checked. - * (2011-02) + one configured. + + XXX This implementation starts with a leading slash and ends with a + slash. In previous configurations String urls began without a slash in + order to be able to provide a full URL_MSG which also contains the context + part. Since version 5.2 the context part is handled by (new) dispatcher. + The leading slash it API change! It's impacts have tp be checked. + (2011-02) * * @return url String for new user registration page as String */ @@ -418,18 +412,18 @@ public class LoginServlet extends BebopApplicationServlet { } /** - * Provides an absolute URL (leading slash) for the system logout page. It - * is relative to document root without any constant prefix if there is one - * configured. + * Provides an absolute URL_MSG (leading slash) for the system logout page. It + is relative to document root without any constant prefix if there is one + configured. + + XXX This implementation starts with a leading slash and ends with a + slash. In previous configurations String urls began without a slash in + order to be able to provide a full URL_MSG which also contains the context + part. Since version 5.2 the context part is handled by (new) dispatcher. + The leading slash it API change! It's impacts have tp be checked. + (2011-02) * - * XXX This implementation starts with a leading slash and ends with a - * slash. In previous configurations String urls began without a slash in - * order to be able to provide a full URL which also contains the context - * part. Since version 5.2 the context part is handled by (new) dispatcher. - * The leading slash it API change! It's impacts have tp be checked. - * (2011-02) - * - * @return URL for logout page as String + * @return URL_MSG for logout page as String */ public static String getLogoutPageURL() { return s_loginURL + LOGOUT_PATH_INFO; diff --git a/ccm-core/src/main/java/com/arsdigita/ui/login/UserEditForm.java b/ccm-core/src/main/java/com/arsdigita/ui/login/UserEditForm.java index 26d5b939a..653c9240e 100644 --- a/ccm-core/src/main/java/com/arsdigita/ui/login/UserEditForm.java +++ b/ccm-core/src/main/java/com/arsdigita/ui/login/UserEditForm.java @@ -46,7 +46,7 @@ import org.libreccm.security.UserRepository; /** * Edits a user. If returnURL is passed in to the form, then redirects to that - * URL; otherwise redirects to the user workspace. + URL_MSG; otherwise redirects to the user workspace. * * * @author Sameer Ajmani @@ -85,7 +85,7 @@ public class UserEditForm extends UserForm addProcessListener(this); - // export return URL + // export return URL_MSG m_returnURL = new Hidden(new URLParameter( LoginHelper.RETURN_URL_PARAM_NAME)); m_returnURL.setPassIn(true); @@ -131,7 +131,7 @@ public class UserEditForm extends UserForm user.setPrimaryEmailAddress(newAddress); userRepository.save(user); - // redirect to workspace or return URL, if specified + // redirect to workspace or return URL_MSG, if specified final HttpServletRequest req = state.getRequest(); final String path = UI.getWorkspaceURL(); final URL fallback = com.arsdigita.web.URL.there(req, path); diff --git a/ccm-core/src/main/java/com/arsdigita/ui/login/UserForm.java b/ccm-core/src/main/java/com/arsdigita/ui/login/UserForm.java index fc47b831b..900f5d39a 100644 --- a/ccm-core/src/main/java/com/arsdigita/ui/login/UserForm.java +++ b/ccm-core/src/main/java/com/arsdigita/ui/login/UserForm.java @@ -85,7 +85,7 @@ public abstract class UserForm extends Form protected Submit m_submit = new Submit(SUBMIT); protected Label m_firstNameLabel = new Label(FIRST_NAME); protected Label m_lastNameLabel = new Label(LAST_NAME); - protected Label m_urlLabel = new Label(URL); + protected Label m_urlLabel = new Label(URL_MSG); protected Label m_screenNameLabel = new Label(SCREEN_NAME); protected Label m_emailLabel = new Label(PRIMARY_EMAIL); diff --git a/ccm-core/src/main/java/com/arsdigita/ui/login/UserLoginForm.java b/ccm-core/src/main/java/com/arsdigita/ui/login/UserLoginForm.java index 8916d6ccf..75b43f1aa 100644 --- a/ccm-core/src/main/java/com/arsdigita/ui/login/UserLoginForm.java +++ b/ccm-core/src/main/java/com/arsdigita/ui/login/UserLoginForm.java @@ -281,7 +281,7 @@ public class UserLoginForm extends Form implements LoginConstants, // s_log.info("Invalid credential"); // // final String path = LoginServlet.getLoginExpiredPageURL(); -// final URL url = com.arsdigita.web.URL.there(state.getRequest(), +// final URL_MSG url = com.arsdigita.web.URL_MSG.there(state.getRequest(), // path); // // throw new RedirectSignal(url, false); @@ -312,7 +312,7 @@ public class UserLoginForm extends Form implements LoginConstants, final PageState state = event.getPageState(); final HttpServletRequest req = state.getRequest(); - // Redirect to workspace or return URL, if specified. + // Redirect to workspace or return URL_MSG, if specified. final String path = UI.getUserRedirectURL(req); final URL url = com.arsdigita.web.URL.there(req, path); diff --git a/ccm-core/src/main/java/com/arsdigita/ui/login/UserNewForm.java b/ccm-core/src/main/java/com/arsdigita/ui/login/UserNewForm.java index 02f6ce680..b1ddfcf0d 100644 --- a/ccm-core/src/main/java/com/arsdigita/ui/login/UserNewForm.java +++ b/ccm-core/src/main/java/com/arsdigita/ui/login/UserNewForm.java @@ -55,9 +55,9 @@ import org.libreccm.security.UserRepository; /** * Creates a new user. Collects user's basic info, such as email, password, - * first name, last name, etc; then tries to create the user in the database. If - * returnURL is passed in to the form, then redirects to that URL; otherwise - * redirects to the user workspace. + first name, last name, etc; then tries to create the user in the database. If + returnURL is passed in to the form, then redirects to that URL_MSG; otherwise + redirects to the user workspace. * * * @author Michael Bryzek @@ -96,7 +96,7 @@ public class UserNewForm extends UserForm implements FormInitListener, addValidationListener(this); addProcessListener(this); - // save return URL + // save return URL_MSG m_returnURL = new Hidden(new URLParameter( LoginHelper.RETURN_URL_PARAM_NAME)); m_returnURL.setPassIn(true); @@ -206,7 +206,7 @@ public class UserNewForm extends UserForm implements FormInitListener, throw new FormProcessException(ex); } - // redirect to workspace or return URL, if specified + // redirect to workspace or return URL_MSG, if specified final HttpServletRequest req = state.getRequest(); final String url = UI.getWorkspaceURL(); final URL fallback = com.arsdigita.web.URL.there(req, url); diff --git a/ccm-core/src/main/java/org/libreccm/core/CcmCore.java b/ccm-core/src/main/java/org/libreccm/core/CcmCore.java index dcde25a5a..86cd13ad8 100644 --- a/ccm-core/src/main/java/org/libreccm/core/CcmCore.java +++ b/ccm-core/src/main/java/org/libreccm/core/CcmCore.java @@ -18,6 +18,8 @@ */ package org.libreccm.core; +import com.arsdigita.ui.login.LoginApplicationCreator; +import com.arsdigita.ui.login.LoginServlet; import org.libreccm.modules.CcmModule; import org.libreccm.modules.InitEvent; import org.libreccm.modules.InstallEvent; @@ -28,12 +30,18 @@ import org.libreccm.security.SystemUsersSetup; import org.libreccm.security.User; import javax.persistence.EntityManager; +import org.libreccm.web.ApplicationType; /** * * @author Jens Pelzetter */ -@Module(entities = {org.libreccm.auditing.CcmRevision.class, +@Module(applicationTypes = {@ApplicationType(name = "Login", + description = "Login Application", + singleton = true, + creator = LoginApplicationCreator.class, + servlet = LoginServlet.class)}, + entities = {org.libreccm.auditing.CcmRevision.class, org.libreccm.categorization.Categorization.class, org.libreccm.categorization.Category.class, org.libreccm.categorization.Domain.class,