Search in sources :

Example 1 with Parameters

use of com.joliciel.jochre.security.Parameters in project jochre by urieli.

the class LoginController method doAfterCompose.

@Override
public void doAfterCompose(Window window) throws Exception {
    super.doAfterCompose(window);
    String pageTitle = Labels.getLabel("login.title");
    winLogin.getPage().setTitle(pageTitle);
    Session session = Sessions.getCurrent();
    session.removeAttribute(SESSION_JOCHRE_USER);
    HttpServletRequest request = (HttpServletRequest) Executions.getCurrent().getNativeRequest();
    String failed = request.getParameter("failed");
    if (failed == null)
        lblError.setVisible(false);
    else
        lblError.setVisible(true);
    SecurityDao securityDao = SecurityDao.getInstance(jochreSession);
    Parameters parameters = securityDao.loadParameters();
    Date lastFailedLoginAttempt = parameters.getLastFailedLoginAttempt();
    Date now = new Date();
    long diff = now.getTime() - lastFailedLoginAttempt.getTime();
    LOG.debug("time since last failed login: " + diff);
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) Parameters(com.joliciel.jochre.security.Parameters) Date(java.util.Date) Session(org.zkoss.zk.ui.Session) JochreSession(com.joliciel.jochre.JochreSession) SecurityDao(com.joliciel.jochre.security.SecurityDao)

Example 2 with Parameters

use of com.joliciel.jochre.security.Parameters in project jochre by urieli.

the class LoginController method onClick$btnLogin.

@Listen("onClick = #btnLogin")
public void onClick$btnLogin(Event event) {
    try {
        LOG.debug("onClick$btnLogin");
        Session session = Sessions.getCurrent();
        SecurityDao securityDao = SecurityDao.getInstance(jochreSession);
        User user = null;
        try {
            user = securityDao.findUser(txtUserName.getValue());
        } catch (EntityNotFoundException enfe) {
            LOG.debug("Unknown user: " + txtUserName.getValue());
            lblError.setVisible(true);
        }
        if (user != null) {
            boolean success = user.login(txtPassword.getValue());
            if (!success) {
                LOG.debug("Login failed");
                lblError.setVisible(true);
                Parameters parameters = securityDao.loadParameters();
                Date lastFailedLoginAttempt = parameters.getLastFailedLoginAttempt();
                Date now = new Date();
                long diff = now.getTime() - lastFailedLoginAttempt.getTime();
                LOG.debug("time since last failed login: " + diff);
            } else {
                LOG.debug("Login success");
                session.setAttribute(SESSION_JOCHRE_USER, user);
                Executions.sendRedirect("docs.zul");
            }
        }
    } catch (Exception e) {
        LOG.error("Failure in onClick$btnLogin", e);
        throw new RuntimeException(e);
    }
}
Also used : User(com.joliciel.jochre.security.User) Parameters(com.joliciel.jochre.security.Parameters) EntityNotFoundException(com.joliciel.jochre.EntityNotFoundException) Date(java.util.Date) EntityNotFoundException(com.joliciel.jochre.EntityNotFoundException) Session(org.zkoss.zk.ui.Session) JochreSession(com.joliciel.jochre.JochreSession) SecurityDao(com.joliciel.jochre.security.SecurityDao) Listen(org.zkoss.zk.ui.select.annotation.Listen)

Aggregations

JochreSession (com.joliciel.jochre.JochreSession)2 Parameters (com.joliciel.jochre.security.Parameters)2 SecurityDao (com.joliciel.jochre.security.SecurityDao)2 Date (java.util.Date)2 Session (org.zkoss.zk.ui.Session)2 EntityNotFoundException (com.joliciel.jochre.EntityNotFoundException)1 User (com.joliciel.jochre.security.User)1 HttpServletRequest (javax.servlet.http.HttpServletRequest)1 Listen (org.zkoss.zk.ui.select.annotation.Listen)1