Package tifauv.jplop.core.auth

Examples of tifauv.jplop.core.auth.UserBase


  // CONSTRUCTORS \\
  public BackendImpl() {
    m_config = new PropertiesConfiguration();
    m_history = new History();
    m_users = new UserBase();
    m_storage = new StorageManagerImpl();
  }
View Full Code Here


      getServletContext().getRequestDispatcher(FAILURE_PAGE).forward(p_request, p_response);
      currentUser = null;
      return;
    }
   
    UserBase users = Main.get().getUserBase();
    if (users != null) {
      // Check the parameters are all there
      String username = p_request.getParameter(CommonConstants.LOGIN_PARAM);
      if (username == null || username.length() == 0) {
        m_logger.warn("The '" + CommonConstants.LOGIN_PARAM + "' request parameter is null or empty.");
View Full Code Here

      getServletContext().getRequestDispatcher(FAILURE_PAGE).forward(p_request, p_response);
      currentUser = null;
      return;
    }
   
    UserBase users = Main.get().getUserBase();
    if (users != null) {
      // Check the parameters are all there
      String username = p_request.getParameter(CommonConstants.LOGIN_PARAM);
      if (username == null || username.trim().length() == 0) {
        m_logger.warn("The '" + CommonConstants.LOGIN_PARAM + "' is null or empty.");
        p_request.setAttribute(CommonConstants.ERROR_REQUEST_ATTR, "Le login est obligatoire.");
        p_response.setStatus(HttpServletResponse.SC_BAD_REQUEST);
        p_response.addHeader(CommonConstants.ERROR_HDR, "Missing " + CommonConstants.LOGIN_PARAM + " parameter");
        getServletContext().getRequestDispatcher(FAILURE_PAGE).forward(p_request, p_response);
        return;
      }

      String password = p_request.getParameter(CommonConstants.PASSWORD_PARAM);
      if (password == null || password.length() == 0) {
        m_logger.warn("The '" + CommonConstants.PASSWORD_PARAM + "' is null or empty.");
        p_request.setAttribute(CommonConstants.ERROR_REQUEST_ATTR, "Le mot de passe est obligatoire.");
        p_response.setStatus(HttpServletResponse.SC_BAD_REQUEST);
        p_response.addHeader(CommonConstants.ERROR_HDR, "Missing " + CommonConstants.PASSWORD_PARAM + " parameter");
        getServletContext().getRequestDispatcher(FAILURE_PAGE).forward(p_request, p_response);
        return;
      }

      String confirm  = p_request.getParameter(CommonConstants.PASSWORD_CONFIRM_PARAM);
      if (confirm == null || confirm.length() == 0) {
        m_logger.warn("The '" + CommonConstants.PASSWORD_CONFIRM_PARAM + "' is null or empty.");
        p_request.setAttribute(CommonConstants.ERROR_REQUEST_ATTR, "La confirmation du mot de passe est obligatoire.");
        p_response.setStatus(HttpServletResponse.SC_BAD_REQUEST);
        p_response.addHeader(CommonConstants.ERROR_HDR, "Missing " + CommonConstants.PASSWORD_CONFIRM_PARAM + " parameter");
        getServletContext().getRequestDispatcher(FAILURE_PAGE).forward(p_request, p_response);
        return;
      }

      // OK, now we are sure we got all the required fields
      m_logger.info("Account creation request for user '" + username + "'.");
   
      // Fail if the password and confirmation don't match
      if (!password.equals(confirm)) {
        m_logger.warn("The password and confirmation for user '" + username + "' don't match.");
        p_request.setAttribute(CommonConstants.ERROR_REQUEST_ATTR, "Le mot de passe et sa confirmation ne correspondent pas, veuillez réessayer.");
        p_response.setStatus(HttpServletResponse.SC_UNAUTHORIZED);
        p_response.addHeader(CommonConstants.ERROR_HDR, "Password confirmation failed");
        getServletContext().getRequestDispatcher(FAILURE_PAGE).forward(p_request, p_response);
        return;
      }

      synchronized (users) {
        // Fail if there is already an account for that username
        if (users.containsUser(username)) {
          m_logger.warn("There is already an account for user '" + username + "'.");
          p_request.setAttribute(CommonConstants.ERROR_REQUEST_ATTR, "Le compte \"" + username + "\" existe déjà, veuillez choisir un autre login.");
          p_response.setStatus(HttpServletResponse.SC_CONFLICT);
          p_response.addHeader(CommonConstants.ERROR_HDR, "Account already exists");
          getServletContext().getRequestDispatcher(FAILURE_PAGE).forward(p_request, p_response);
          return;
        }
       
        // Create the user
        User user = new User();
        try {
          user.setLogin(username);
          user.setPassword(password);
          user.setRoles(users.getDefaultRoles());
        } catch (PasswordException e) {
          user = null;
          m_logger.warn("Could not create the user '" + username + "' : " + e.getMessage());
          p_request.setAttribute(CommonConstants.ERROR_REQUEST_ATTR, "Le mot de passe ne correspond pas aux critères exigés.");
          p_response.setStatus(HttpServletResponse.SC_UNAUTHORIZED);
          p_response.addHeader(CommonConstants.ERROR_HDR, "Invalid password");
          getServletContext().getRequestDispatcher(FAILURE_PAGE).forward(p_request, p_response);
          return;
        }
       
        // Add the user
        users.addUser(user);
        p_request.getSession().removeAttribute(CommonConstants.NICK_SESSION_ATTR);
        p_request.getSession().setAttribute(CommonConstants.USER_SESSION_ATTR, user);
        p_response.setStatus(HttpServletResponse.SC_CREATED);
        getServletContext().getRequestDispatcher(SUCCESS_PAGE).forward(p_request, p_response);
        return;
View Full Code Here

TOP

Related Classes of tifauv.jplop.core.auth.UserBase

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.