CCM NG: Some work on the login form.

git-svn-id: https://svn.libreccm.org/ccm/ccm_ng@3848 8810af33-2d31-482b-a856-94f89814c4df
pull/2/head
jensp 2016-02-08 18:15:46 +00:00
parent 22dd841c11
commit d6114efcf7
4 changed files with 48 additions and 39 deletions

View File

@ -53,8 +53,13 @@ import com.arsdigita.web.ParameterMap;
import com.arsdigita.web.RedirectSignal;
import com.arsdigita.web.ReturnSignal;
import com.arsdigita.web.URL;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import java.util.Iterator;
import java.util.Set;
import javax.enterprise.context.spi.CreationalContext;
import javax.enterprise.inject.spi.Bean;
import javax.enterprise.inject.spi.BeanManager;
@ -62,7 +67,6 @@ import javax.enterprise.inject.spi.CDI;
import javax.servlet.http.HttpServletRequest;
import org.apache.log4j.Logger;
import org.apache.shiro.authc.AuthenticationException;
import org.apache.shiro.authc.UsernamePasswordToken;
import org.libreccm.cdi.utils.CdiUtil;
@ -98,7 +102,8 @@ public class UserLoginForm extends Form implements LoginConstants,
FormValidationListener,
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
final static String FORM_NAME = "user-login";
@ -140,21 +145,22 @@ public class UserLoginForm extends Form implements LoginConstants,
// ConfigurationManager.class).get();
final BeanManager beanManager = CDI.current().getBeanManager();
final Set<Bean<?>> beans = beanManager.getBeans(
ConfigurationManager.class);
ConfigurationManager.class);
final Iterator<Bean<?>> iterator = beans.iterator();
final ConfigurationManager confManager;
if (iterator.hasNext()) {
@SuppressWarnings("unchecked")
final Bean<ConfigurationManager> bean = (Bean<ConfigurationManager>) iterator.
next();
final Bean<ConfigurationManager> bean
= (Bean<ConfigurationManager>) iterator
.next();
final CreationalContext<ConfigurationManager> ctx = beanManager.
createCreationalContext(bean);
createCreationalContext(bean);
confManager = (ConfigurationManager) beanManager.getReference(
bean, ConfigurationManager.class, ctx);
bean, ConfigurationManager.class, ctx);
} else {
throw new UncheckedWrapperException(
"Failed to lookup ConfigurationManager");
"Failed to lookup ConfigurationManager");
}
securityConfig = confManager.findConfiguration(SecurityConfig.class);
@ -164,7 +170,7 @@ public class UserLoginForm extends Form implements LoginConstants,
addProcessListener(this);
final KernelConfig kernelConfig = confManager.findConfiguration(
KernelConfig.class);
KernelConfig.class);
m_autoRegistrationOn = autoRegistrationOn;
@ -172,14 +178,14 @@ public class UserLoginForm extends Form implements LoginConstants,
add(m_timestamp);
m_returnURL = new Hidden(new URLParameter(
LoginHelper.RETURN_URL_PARAM_NAME));
LoginHelper.RETURN_URL_PARAM_NAME));
m_returnURL.setPassIn(true);
add(m_returnURL);
setupLogin();
add(new Label(LoginHelper.getMessage(
"login.userRegistrationForm.password")));
"login.userRegistrationForm.password")));
m_password = new Password(new StringParameter(FORM_PASSWORD));
// Since new users should not enter a password, allow null.
//m_password.addValidationListener(new NotNullValidationListener());
@ -188,7 +194,7 @@ public class UserLoginForm extends Form implements LoginConstants,
SimpleContainer cookiePanel = new BoxPanel(BoxPanel.HORIZONTAL);
m_isPersistent = new CheckboxGroup(FORM_PERSISTENT_LOGIN_P);
Label optLabel = new Label(LoginHelper.getMessage(
"login.userRegistrationForm.cookieOption"));
"login.userRegistrationForm.cookieOption"));
Option opt = new Option(FORM_PERSISTENT_LOGIN_P_DEFAULT, optLabel);
m_isPersistent.addOption(opt);
if (kernelConfig.isRememberLoginEnabled()) {
@ -197,8 +203,8 @@ public class UserLoginForm extends Form implements LoginConstants,
cookiePanel.add(m_isPersistent);
cookiePanel.add(new DynamicLink(
"login.userRegistrationForm.explainCookieLink",
LoginServlet.getCookiesExplainPageURL()));
"login.userRegistrationForm.explainCookieLink",
LoginServlet.getCookiesExplainPageURL()));
add(cookiePanel);
add(new Submit(SUBMIT), ColumnPanel.CENTER | ColumnPanel.FULL_WIDTH);
@ -222,8 +228,8 @@ public class UserLoginForm extends Form implements LoginConstants,
*/
private void setupLogin() {
SimpleContainer loginMessage = new SimpleContainer(
"subsite:loginPromptMsg",
LoginServlet.SUBSITE_NS_URI);
"subsite:loginPromptMsg",
LoginServlet.SUBSITE_NS_URI);
final KernelConfig kernelConfig = KernelConfig.getConfig();
@ -237,17 +243,17 @@ public class UserLoginForm extends Form implements LoginConstants,
if (kernelConfig.emailIsPrimaryIdentifier()) {
add(new Label(LoginHelper.getMessage(
"login.userRegistrationForm.email")));
"login.userRegistrationForm.email")));
m_loginName = new TextField(new EmailParameter(FORM_LOGIN));
addInitListener(new EmailInitListener((EmailParameter) m_loginName.
getParameterModel()));
getParameterModel()));
} else {
add(new Label(LoginHelper.getMessage(
"login.userRegistrationForm.screenName")));
"login.userRegistrationForm.screenName")));
m_loginName = new TextField(new StringParameter(FORM_LOGIN));
addInitListener(new ScreenNameInitListener(
(StringParameter) m_loginName.
getParameterModel()));
(StringParameter) m_loginName.
getParameterModel()));
}
m_loginName.addValidationListener(new NotNullValidationListener());
add(m_loginName);
@ -261,17 +267,17 @@ public class UserLoginForm extends Form implements LoginConstants,
*/
@Override
public void init(FormSectionEvent event)
throws FormProcessException {
s_log.info("In init");
throws FormProcessException {
LOGGER.info("In init");
final KernelConfig kernelConfig = KernelConfig.getConfig();
if (kernelConfig.isSsoEnabled()) {
// try SSO login
s_log.info("trying SSO");
LOGGER.info("trying SSO");
// try {
throw new UnsupportedOperationException(
"SSO currently not supported");
"SSO currently not supported");
// Web.getUserContext().loginSSO();
// s_log.info("loginSSO ok, now processing redirect_url");
// process(event);
@ -302,9 +308,9 @@ public class UserLoginForm extends Form implements LoginConstants,
*/
@Override
public void validate(FormSectionEvent event)
throws FormProcessException {
throws FormProcessException {
s_log.debug("In validate");
LOGGER.debug("In validate");
FormData data = event.getFormData();
PageState state = event.getPageState();
@ -341,8 +347,8 @@ public class UserLoginForm extends Form implements LoginConstants,
*/
@Override
public void process(final FormSectionEvent event)
throws FormProcessException {
s_log.debug("In process");
throws FormProcessException {
LOGGER.debug("In process");
final PageState state = event.getPageState();
final HttpServletRequest req = state.getRequest();
@ -367,15 +373,15 @@ public class UserLoginForm extends Form implements LoginConstants,
*
*/
protected void loginUser(final FormSectionEvent event)
throws FormProcessException {
throws FormProcessException {
PageState state = event.getPageState();
final CdiUtil cdiUtil = new CdiUtil();
final Subject subject = cdiUtil.findBean(Subject.class);
final UsernamePasswordToken token = new UsernamePasswordToken(
(String) m_loginName.getValue(state),
(String) m_password.getValue(state)
m_loginName.getValue(state).toString(),
(String) m_password.getValue(state)
);
token.setRememberMe(getPersistentLoginValue(state, false));
try {
@ -383,6 +389,8 @@ public class UserLoginForm extends Form implements LoginConstants,
} catch (AuthenticationException 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)
throws FormProcessException {
throws FormProcessException {
// do nothing
}
@ -423,8 +431,8 @@ public class UserLoginForm extends Form implements LoginConstants,
*/
protected void onLoginFail(final FormSectionEvent event,
final AuthenticationException ex)
throws FormProcessException {
s_log.debug("Login fail");
throws FormProcessException {
LOGGER.debug("Login fail");
event.getFormData().addError(ERROR_LOGIN_FAIL);
}

View File

@ -41,8 +41,9 @@ public class SystemUsersSetup {
private static final Logger LOGGER = LogManager.getLogger(
SystemUsersSetup.class);
//Default password is "libreccm"
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;

View File

@ -94,7 +94,7 @@ processor, some are read from the configuration files of Foundry and some are de
</foundry:doc-desc>
</foundry:doc>
<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-desc>

View File

@ -17,6 +17,6 @@
<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>