CCM NG: Some work on the login form.
git-svn-id: https://svn.libreccm.org/ccm/ccm_ng@3848 8810af33-2d31-482b-a856-94f89814c4dfpull/2/head
parent
22dd841c11
commit
d6114efcf7
|
|
@ -53,8 +53,13 @@ import com.arsdigita.web.ParameterMap;
|
||||||
import com.arsdigita.web.RedirectSignal;
|
import com.arsdigita.web.RedirectSignal;
|
||||||
import com.arsdigita.web.ReturnSignal;
|
import com.arsdigita.web.ReturnSignal;
|
||||||
import com.arsdigita.web.URL;
|
import com.arsdigita.web.URL;
|
||||||
|
|
||||||
|
import org.apache.logging.log4j.LogManager;
|
||||||
|
import org.apache.logging.log4j.Logger;
|
||||||
|
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
import javax.enterprise.context.spi.CreationalContext;
|
import javax.enterprise.context.spi.CreationalContext;
|
||||||
import javax.enterprise.inject.spi.Bean;
|
import javax.enterprise.inject.spi.Bean;
|
||||||
import javax.enterprise.inject.spi.BeanManager;
|
import javax.enterprise.inject.spi.BeanManager;
|
||||||
|
|
@ -62,7 +67,6 @@ import javax.enterprise.inject.spi.CDI;
|
||||||
|
|
||||||
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
|
|
||||||
import org.apache.log4j.Logger;
|
|
||||||
import org.apache.shiro.authc.AuthenticationException;
|
import org.apache.shiro.authc.AuthenticationException;
|
||||||
import org.apache.shiro.authc.UsernamePasswordToken;
|
import org.apache.shiro.authc.UsernamePasswordToken;
|
||||||
import org.libreccm.cdi.utils.CdiUtil;
|
import org.libreccm.cdi.utils.CdiUtil;
|
||||||
|
|
@ -98,7 +102,8 @@ public class UserLoginForm extends Form implements LoginConstants,
|
||||||
FormValidationListener,
|
FormValidationListener,
|
||||||
FormProcessListener {
|
FormProcessListener {
|
||||||
|
|
||||||
private static final Logger s_log = Logger.getLogger(UserLoginForm.class);
|
private static final Logger LOGGER = LogManager.getLogger(
|
||||||
|
UserLoginForm.class);
|
||||||
|
|
||||||
// package friendly static form name makes writing HttpUnitTest easier
|
// package friendly static form name makes writing HttpUnitTest easier
|
||||||
final static String FORM_NAME = "user-login";
|
final static String FORM_NAME = "user-login";
|
||||||
|
|
@ -140,21 +145,22 @@ public class UserLoginForm extends Form implements LoginConstants,
|
||||||
// ConfigurationManager.class).get();
|
// ConfigurationManager.class).get();
|
||||||
final BeanManager beanManager = CDI.current().getBeanManager();
|
final BeanManager beanManager = CDI.current().getBeanManager();
|
||||||
final Set<Bean<?>> beans = beanManager.getBeans(
|
final Set<Bean<?>> beans = beanManager.getBeans(
|
||||||
ConfigurationManager.class);
|
ConfigurationManager.class);
|
||||||
final Iterator<Bean<?>> iterator = beans.iterator();
|
final Iterator<Bean<?>> iterator = beans.iterator();
|
||||||
final ConfigurationManager confManager;
|
final ConfigurationManager confManager;
|
||||||
if (iterator.hasNext()) {
|
if (iterator.hasNext()) {
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
final Bean<ConfigurationManager> bean = (Bean<ConfigurationManager>) iterator.
|
final Bean<ConfigurationManager> bean
|
||||||
next();
|
= (Bean<ConfigurationManager>) iterator
|
||||||
|
.next();
|
||||||
final CreationalContext<ConfigurationManager> ctx = beanManager.
|
final CreationalContext<ConfigurationManager> ctx = beanManager.
|
||||||
createCreationalContext(bean);
|
createCreationalContext(bean);
|
||||||
|
|
||||||
confManager = (ConfigurationManager) beanManager.getReference(
|
confManager = (ConfigurationManager) beanManager.getReference(
|
||||||
bean, ConfigurationManager.class, ctx);
|
bean, ConfigurationManager.class, ctx);
|
||||||
} else {
|
} else {
|
||||||
throw new UncheckedWrapperException(
|
throw new UncheckedWrapperException(
|
||||||
"Failed to lookup ConfigurationManager");
|
"Failed to lookup ConfigurationManager");
|
||||||
}
|
}
|
||||||
securityConfig = confManager.findConfiguration(SecurityConfig.class);
|
securityConfig = confManager.findConfiguration(SecurityConfig.class);
|
||||||
|
|
||||||
|
|
@ -164,7 +170,7 @@ public class UserLoginForm extends Form implements LoginConstants,
|
||||||
addProcessListener(this);
|
addProcessListener(this);
|
||||||
|
|
||||||
final KernelConfig kernelConfig = confManager.findConfiguration(
|
final KernelConfig kernelConfig = confManager.findConfiguration(
|
||||||
KernelConfig.class);
|
KernelConfig.class);
|
||||||
|
|
||||||
m_autoRegistrationOn = autoRegistrationOn;
|
m_autoRegistrationOn = autoRegistrationOn;
|
||||||
|
|
||||||
|
|
@ -172,14 +178,14 @@ public class UserLoginForm extends Form implements LoginConstants,
|
||||||
add(m_timestamp);
|
add(m_timestamp);
|
||||||
|
|
||||||
m_returnURL = new Hidden(new URLParameter(
|
m_returnURL = new Hidden(new URLParameter(
|
||||||
LoginHelper.RETURN_URL_PARAM_NAME));
|
LoginHelper.RETURN_URL_PARAM_NAME));
|
||||||
m_returnURL.setPassIn(true);
|
m_returnURL.setPassIn(true);
|
||||||
add(m_returnURL);
|
add(m_returnURL);
|
||||||
|
|
||||||
setupLogin();
|
setupLogin();
|
||||||
|
|
||||||
add(new Label(LoginHelper.getMessage(
|
add(new Label(LoginHelper.getMessage(
|
||||||
"login.userRegistrationForm.password")));
|
"login.userRegistrationForm.password")));
|
||||||
m_password = new Password(new StringParameter(FORM_PASSWORD));
|
m_password = new Password(new StringParameter(FORM_PASSWORD));
|
||||||
// Since new users should not enter a password, allow null.
|
// Since new users should not enter a password, allow null.
|
||||||
//m_password.addValidationListener(new NotNullValidationListener());
|
//m_password.addValidationListener(new NotNullValidationListener());
|
||||||
|
|
@ -188,7 +194,7 @@ public class UserLoginForm extends Form implements LoginConstants,
|
||||||
SimpleContainer cookiePanel = new BoxPanel(BoxPanel.HORIZONTAL);
|
SimpleContainer cookiePanel = new BoxPanel(BoxPanel.HORIZONTAL);
|
||||||
m_isPersistent = new CheckboxGroup(FORM_PERSISTENT_LOGIN_P);
|
m_isPersistent = new CheckboxGroup(FORM_PERSISTENT_LOGIN_P);
|
||||||
Label optLabel = new Label(LoginHelper.getMessage(
|
Label optLabel = new Label(LoginHelper.getMessage(
|
||||||
"login.userRegistrationForm.cookieOption"));
|
"login.userRegistrationForm.cookieOption"));
|
||||||
Option opt = new Option(FORM_PERSISTENT_LOGIN_P_DEFAULT, optLabel);
|
Option opt = new Option(FORM_PERSISTENT_LOGIN_P_DEFAULT, optLabel);
|
||||||
m_isPersistent.addOption(opt);
|
m_isPersistent.addOption(opt);
|
||||||
if (kernelConfig.isRememberLoginEnabled()) {
|
if (kernelConfig.isRememberLoginEnabled()) {
|
||||||
|
|
@ -197,8 +203,8 @@ public class UserLoginForm extends Form implements LoginConstants,
|
||||||
cookiePanel.add(m_isPersistent);
|
cookiePanel.add(m_isPersistent);
|
||||||
|
|
||||||
cookiePanel.add(new DynamicLink(
|
cookiePanel.add(new DynamicLink(
|
||||||
"login.userRegistrationForm.explainCookieLink",
|
"login.userRegistrationForm.explainCookieLink",
|
||||||
LoginServlet.getCookiesExplainPageURL()));
|
LoginServlet.getCookiesExplainPageURL()));
|
||||||
add(cookiePanel);
|
add(cookiePanel);
|
||||||
|
|
||||||
add(new Submit(SUBMIT), ColumnPanel.CENTER | ColumnPanel.FULL_WIDTH);
|
add(new Submit(SUBMIT), ColumnPanel.CENTER | ColumnPanel.FULL_WIDTH);
|
||||||
|
|
@ -222,8 +228,8 @@ public class UserLoginForm extends Form implements LoginConstants,
|
||||||
*/
|
*/
|
||||||
private void setupLogin() {
|
private void setupLogin() {
|
||||||
SimpleContainer loginMessage = new SimpleContainer(
|
SimpleContainer loginMessage = new SimpleContainer(
|
||||||
"subsite:loginPromptMsg",
|
"subsite:loginPromptMsg",
|
||||||
LoginServlet.SUBSITE_NS_URI);
|
LoginServlet.SUBSITE_NS_URI);
|
||||||
|
|
||||||
final KernelConfig kernelConfig = KernelConfig.getConfig();
|
final KernelConfig kernelConfig = KernelConfig.getConfig();
|
||||||
|
|
||||||
|
|
@ -237,17 +243,17 @@ public class UserLoginForm extends Form implements LoginConstants,
|
||||||
|
|
||||||
if (kernelConfig.emailIsPrimaryIdentifier()) {
|
if (kernelConfig.emailIsPrimaryIdentifier()) {
|
||||||
add(new Label(LoginHelper.getMessage(
|
add(new Label(LoginHelper.getMessage(
|
||||||
"login.userRegistrationForm.email")));
|
"login.userRegistrationForm.email")));
|
||||||
m_loginName = new TextField(new EmailParameter(FORM_LOGIN));
|
m_loginName = new TextField(new EmailParameter(FORM_LOGIN));
|
||||||
addInitListener(new EmailInitListener((EmailParameter) m_loginName.
|
addInitListener(new EmailInitListener((EmailParameter) m_loginName.
|
||||||
getParameterModel()));
|
getParameterModel()));
|
||||||
} else {
|
} else {
|
||||||
add(new Label(LoginHelper.getMessage(
|
add(new Label(LoginHelper.getMessage(
|
||||||
"login.userRegistrationForm.screenName")));
|
"login.userRegistrationForm.screenName")));
|
||||||
m_loginName = new TextField(new StringParameter(FORM_LOGIN));
|
m_loginName = new TextField(new StringParameter(FORM_LOGIN));
|
||||||
addInitListener(new ScreenNameInitListener(
|
addInitListener(new ScreenNameInitListener(
|
||||||
(StringParameter) m_loginName.
|
(StringParameter) m_loginName.
|
||||||
getParameterModel()));
|
getParameterModel()));
|
||||||
}
|
}
|
||||||
m_loginName.addValidationListener(new NotNullValidationListener());
|
m_loginName.addValidationListener(new NotNullValidationListener());
|
||||||
add(m_loginName);
|
add(m_loginName);
|
||||||
|
|
@ -261,17 +267,17 @@ public class UserLoginForm extends Form implements LoginConstants,
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void init(FormSectionEvent event)
|
public void init(FormSectionEvent event)
|
||||||
throws FormProcessException {
|
throws FormProcessException {
|
||||||
s_log.info("In init");
|
LOGGER.info("In init");
|
||||||
|
|
||||||
final KernelConfig kernelConfig = KernelConfig.getConfig();
|
final KernelConfig kernelConfig = KernelConfig.getConfig();
|
||||||
|
|
||||||
if (kernelConfig.isSsoEnabled()) {
|
if (kernelConfig.isSsoEnabled()) {
|
||||||
// try SSO login
|
// try SSO login
|
||||||
s_log.info("trying SSO");
|
LOGGER.info("trying SSO");
|
||||||
// try {
|
// try {
|
||||||
throw new UnsupportedOperationException(
|
throw new UnsupportedOperationException(
|
||||||
"SSO currently not supported");
|
"SSO currently not supported");
|
||||||
// Web.getUserContext().loginSSO();
|
// Web.getUserContext().loginSSO();
|
||||||
// s_log.info("loginSSO ok, now processing redirect_url");
|
// s_log.info("loginSSO ok, now processing redirect_url");
|
||||||
// process(event);
|
// process(event);
|
||||||
|
|
@ -302,9 +308,9 @@ public class UserLoginForm extends Form implements LoginConstants,
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void validate(FormSectionEvent event)
|
public void validate(FormSectionEvent event)
|
||||||
throws FormProcessException {
|
throws FormProcessException {
|
||||||
|
|
||||||
s_log.debug("In validate");
|
LOGGER.debug("In validate");
|
||||||
|
|
||||||
FormData data = event.getFormData();
|
FormData data = event.getFormData();
|
||||||
PageState state = event.getPageState();
|
PageState state = event.getPageState();
|
||||||
|
|
@ -341,8 +347,8 @@ public class UserLoginForm extends Form implements LoginConstants,
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void process(final FormSectionEvent event)
|
public void process(final FormSectionEvent event)
|
||||||
throws FormProcessException {
|
throws FormProcessException {
|
||||||
s_log.debug("In process");
|
LOGGER.debug("In process");
|
||||||
|
|
||||||
final PageState state = event.getPageState();
|
final PageState state = event.getPageState();
|
||||||
final HttpServletRequest req = state.getRequest();
|
final HttpServletRequest req = state.getRequest();
|
||||||
|
|
@ -367,15 +373,15 @@ public class UserLoginForm extends Form implements LoginConstants,
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
protected void loginUser(final FormSectionEvent event)
|
protected void loginUser(final FormSectionEvent event)
|
||||||
throws FormProcessException {
|
throws FormProcessException {
|
||||||
PageState state = event.getPageState();
|
PageState state = event.getPageState();
|
||||||
|
|
||||||
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 UsernamePasswordToken token = new UsernamePasswordToken(
|
final UsernamePasswordToken token = new UsernamePasswordToken(
|
||||||
(String) m_loginName.getValue(state),
|
m_loginName.getValue(state).toString(),
|
||||||
(String) m_password.getValue(state)
|
(String) m_password.getValue(state)
|
||||||
);
|
);
|
||||||
token.setRememberMe(getPersistentLoginValue(state, false));
|
token.setRememberMe(getPersistentLoginValue(state, false));
|
||||||
try {
|
try {
|
||||||
|
|
@ -383,6 +389,8 @@ public class UserLoginForm extends Form implements LoginConstants,
|
||||||
} catch (AuthenticationException ex) {
|
} catch (AuthenticationException ex) {
|
||||||
onLoginFail(event, ex);
|
onLoginFail(event, ex);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
LOGGER.debug("User {} logged in successfully.", token.getUsername());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -394,7 +402,7 @@ public class UserLoginForm extends Form implements LoginConstants,
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
protected void onLoginSuccess(final FormSectionEvent event)
|
protected void onLoginSuccess(final FormSectionEvent event)
|
||||||
throws FormProcessException {
|
throws FormProcessException {
|
||||||
// do nothing
|
// do nothing
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -423,8 +431,8 @@ public class UserLoginForm extends Form implements LoginConstants,
|
||||||
*/
|
*/
|
||||||
protected void onLoginFail(final FormSectionEvent event,
|
protected void onLoginFail(final FormSectionEvent event,
|
||||||
final AuthenticationException ex)
|
final AuthenticationException ex)
|
||||||
throws FormProcessException {
|
throws FormProcessException {
|
||||||
s_log.debug("Login fail");
|
LOGGER.debug("Login fail");
|
||||||
event.getFormData().addError(ERROR_LOGIN_FAIL);
|
event.getFormData().addError(ERROR_LOGIN_FAIL);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -41,8 +41,9 @@ public class SystemUsersSetup {
|
||||||
private static final Logger LOGGER = LogManager.getLogger(
|
private static final Logger LOGGER = LogManager.getLogger(
|
||||||
SystemUsersSetup.class);
|
SystemUsersSetup.class);
|
||||||
|
|
||||||
|
//Default password is "libreccm"
|
||||||
private static final String DEFAULT_ADMIN_PW
|
private static final String DEFAULT_ADMIN_PW
|
||||||
= "$shiro1$SHA-512$500000$MFPkVikNoRrBZ8R8CxQIHA==$UvgO2K+poSRGw5co63P3ygpWsX7H9N0TgqdrZPBqdXv6Q+/OCL/qOocVbg65/Yjv5hyri6A3zhw7K8mEgpISoA==";
|
= "$shiro1$SHA-512$500000$MFPkVikNoRrBZ8R8CxQIHA==$ybEECtSPukmXDbV27a3LnWktFsh9lQl2ZYqCUtV0NF9G35Rt0+Tzp1msNLBQUVv15SrsdFgBSfhgWfZFyTva+Q==";
|
||||||
|
|
||||||
private final EntityManager entityManager;
|
private final EntityManager entityManager;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -94,7 +94,7 @@ processor, some are read from the configuration files of Foundry and some are de
|
||||||
</foundry:doc-desc>
|
</foundry:doc-desc>
|
||||||
</foundry:doc>
|
</foundry:doc>
|
||||||
<xsl:param name="theme-prefix"
|
<xsl:param name="theme-prefix"
|
||||||
select="concat($context-prefix, 'themes/libreccm-default/')"/>
|
select="concat($context-prefix, '/themes/libreccm-default')"/>
|
||||||
|
|
||||||
<foundry:doc section="devel" type="env-var">
|
<foundry:doc section="devel" type="env-var">
|
||||||
<foundry:doc-desc>
|
<foundry:doc-desc>
|
||||||
|
|
|
||||||
|
|
@ -17,6 +17,6 @@
|
||||||
|
|
||||||
<setting id="log-level">warn</setting>
|
<setting id="log-level">warn</setting>
|
||||||
|
|
||||||
<setting id="site-logo">images/cms-logo.png</setting>
|
<setting id="site-logo">images/libreccm.png</setting>
|
||||||
|
|
||||||
</foundry:configuration>
|
</foundry:configuration>
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue