Beispiel #1
0
 public void updateUserPassword(UserVO userToUpdate) throws MSMApplicationException {
   NdgUser user = findNdgUserByName(userToUpdate.getUsername());
   if (userToUpdate.getPassword() != null) {
     try {
       user.setPassword(MD5.createMD5(userToUpdate.getPassword()));
       user.setUserValidated('Y');
     } catch (NoSuchAlgorithmException e) {
       e.printStackTrace();
     }
   }
 }
Beispiel #2
0
  public UserVO createUser(UserVO vo) throws MSMApplicationException {
    UserVO newUser = null;
    NdgUser userPending = findNdgUserByName(vo.getUsername());
    UserVO userByEmail = getUserByEmail(vo.getEmail());

    if (userPending != null) {
      throw new UserAlreadyExistException();
    } else if (userByEmail != null) {
      throw new EmailAlreadyExistException();
    } else {
      userPending = new NdgUser();
      try {
        userPending.setPassword(MD5.createMD5(vo.getPassword()));
      } catch (NoSuchAlgorithmException e) {
        e.printStackTrace();
      }
      userPending.setUsername(vo.getUsername());
      userPending.setFirstName(vo.getFirstName());
      userPending.setLastName(vo.getLastName());
      userPending.setEmail(vo.getEmail());

      userPending.setPhoneNumber(vo.getPhoneNumber());
      userPending.setAreaCode(vo.getAreaCode());
      userPending.setCountryCode(vo.getCountryCode());

      NdgRole role = findNdgRoleByName(vo.getRole().getName());
      if (role != null) {
        userPending.setRole(role);
      }
      NdgUser userAdmin = findNdgUserByName(vo.getUserAdmin());
      if (userPending != null) {
        userPending.setUserAdmin(userAdmin.getUsername());
        userPending.setCompany(userAdmin.getCompany());
        userPending.setEmailPreferences(userAdmin.getEmailPreferences());
        userPending.setWhoUseIt(userAdmin.getWhoUseIt());
      }

      userPending.setValidationKey(generateValidationKey(vo.getEmail()));
      userPending.setHasFullPermissions(vo.getHasFullPermissions());
      userPending.setUserValidated('Y');
      userPending.setHowDoYouPlanUseNdg("");
      userPending.setFirstTimeUse('Y');

      manager.persist(userPending);

      newUser = userPojoToVo(userPending);
    }

    return newUser;
  }
Beispiel #3
0
  public void updateUser(UserVO userToUpdate) throws MSMApplicationException {
    NdgUser user = findNdgUserByName(userToUpdate.getUsername());

    if (user != null) {
      if (userToUpdate.getFirstName() != null) {
        user.setFirstName(userToUpdate.getFirstName());
      }
      if (userToUpdate.getLastName() != null) {
        user.setLastName(userToUpdate.getLastName());
      }
      if (userToUpdate.getEmail() != null) {
        user.setEmail(userToUpdate.getEmail());
      }
      if (userToUpdate.getCountryCode() != null) {
        user.setCountryCode(userToUpdate.getCountryCode());
      }
      if (userToUpdate.getAreaCode() != null) {
        user.setAreaCode(userToUpdate.getAreaCode());
      }
      if (userToUpdate.getPhoneNumber() != null) {
        user.setPhoneNumber(userToUpdate.getPhoneNumber());
      }
      if (userToUpdate.getRole() != null) {
        NdgRole role = findNdgRoleByName(userToUpdate.getRole().getName());
        if (role != null) {
          user.setRole(role);
        }
      }
      if (userToUpdate.getPassword() != null) {
        try {
          user.setPassword(MD5.createMD5(userToUpdate.getPassword()));
        } catch (NoSuchAlgorithmException e) {
          e.printStackTrace();
        }
      }

      user.setFirstTimeUse(userToUpdate.getFirstTimeUse());

      // if (userToUpdate.getHasFullPermissions() == 'y' ||
      //		userToUpdate.getHasFullPermissions() == 'Y') {
      //	user.setHasFullPermissions(userToUpdate.getHasFullPermissions());
      // }
      // user.setFirstTimeUse(userToUpdate.getFirstTimeUse());

      manager.merge(user);
    } else {
      throw new UserNotFoundException();
    }
  }
Beispiel #4
0
  public UserVO validateLogin(String username, String password) throws MSMApplicationException {
    NdgUser user = findNdgUserByName(username);
    UserVO vo = new UserVO();

    if (user != null) {
      try {
        if (user.getPassword().equals(MD5.createMD5(password))) {
          if ((user.getUserValidated() == 'y' || user.getUserValidated() == 'Y')) {
            vo = userPojoToVo(user);
            vo.setRetCode(UserVO.AUTHENTICATED);
            vo.setFirstTimeUse(user.getFirstTimeUse());

            try {
              NdgUser userAdmin = findNdgUserByName(user.getUserAdmin());
              vo.setHasFullPermissions(userAdmin.getHasFullPermissions());
            } catch (Exception e) {
              log.error("validateLogin: userAdmin not found - admin = " + user.getUserAdmin());
            }

            Query query = manager.createNamedQuery("userbalance.findByUserAdmin");
            query.setParameter("useradmin", user.getUserAdmin());
            UserBalance userAdminBalance = null;
            try {
              userAdminBalance = (UserBalance) query.getSingleResult();
            } catch (Exception e) {
              log.info("New user: "******"LIMIT_IMEIS")));
                initialUserBalance.setResults(
                    Integer.parseInt(properties.getProperty("LIMIT_RESULTS")));
                initialUserBalance.setSendAlerts(
                    Integer.parseInt(properties.getProperty("LIMIT_SEND_ALERTS")));
                initialUserBalance.setSurveys(
                    Integer.parseInt(properties.getProperty("LIMIT_SURVEYS")));
                initialUserBalance.setUser(findNdgUserByName(user.getUserAdmin()));
                initialUserBalance.setUsers(Integer.parseInt(properties.getProperty("LIMIT_USER")));
              } catch (Exception e) {
                initialUserBalance.setImeis(0);
                initialUserBalance.setResults(0);
                initialUserBalance.setSendAlerts(0);
                initialUserBalance.setSurveys(0);
                initialUserBalance.setUser(findNdgUserByName(user.getUserAdmin()));
                initialUserBalance.setUsers(0);
              }
              UserBalanceVO balanceVO = new UserBalanceVO();
              balanceVO.setImeis(initialUserBalance.getImeis());
              balanceVO.setResults(initialUserBalance.getResults());
              balanceVO.setSendAlerts(initialUserBalance.getSendAlerts());
              balanceVO.setSurveys(initialUserBalance.getSurveys());
              balanceVO.setUsers(initialUserBalance.getUsers());
              vo.setUserBalance(balanceVO);
              manager.persist(initialUserBalance);
            } else {
              UserBalanceVO balanceVO = new UserBalanceVO();
              balanceVO.setImeis(userAdminBalance.getImeis());
              balanceVO.setResults(userAdminBalance.getResults());
              balanceVO.setSendAlerts(userAdminBalance.getSendAlerts());
              balanceVO.setSurveys(userAdminBalance.getSurveys());
              balanceVO.setUsers(userAdminBalance.getUsers());
              vo.setUserBalance(balanceVO);
            }
          } else {
            vo.setRetCode(UserVO.EMAIL_NOT_VALIDATED);
            throw new UserEmailNotValidatedException();
          }
        } else {
          vo.setRetCode(UserVO.INVALID_PASSWORD);
          throw new InvalidPasswordException();
        }
      } catch (NoSuchAlgorithmException e) {
        throw new InvalidPasswordGenerationException();
      }
    } else {
      vo.setRetCode(UserVO.INVALID_USERNAME);
      throw new InvalidUsernameException();
    }
    return vo;
  }
Beispiel #5
0
  private void createUserSimpleSurvey(String username)
      throws MSMApplicationException, MSMSystemException {
    InputStreamReader in = null;
    String surveyString;
    StringBuffer surveyStringBuffer;
    MSMBusinessDelegate bd = new MSMBusinessDelegate();
    Pattern pattern = Pattern.compile("IDS");
    Matcher matcher;
    try {
      URL url = this.getClass().getClassLoader().getResource("META-INF/survey.xml");

      in = new InputStreamReader(url.openStream(), "UTF-8");

      BufferedReader survey = new BufferedReader(in);

      StringBuilder sb = new StringBuilder();

      String line = null;
      try {
        while ((line = survey.readLine()) != null) {
          sb.append(line + '\n');
        }
      } catch (IOException e) {
        e.printStackTrace();
      }
      surveyString = sb.toString();
      matcher = pattern.matcher(surveyString);
      surveyStringBuffer = new StringBuffer(matcher.replaceAll(idSimpleSurvey));

      surveyString = surveyStringBuffer.toString();
      pattern = Pattern.compile("CHKS");
      matcher = pattern.matcher(surveyString);

      // 1º - change string "CHKS" by dummy checksum key,
      // once the method getMD5FromSurvey will remove it
      surveyStringBuffer = new StringBuffer(matcher.replaceAll("00000000000000000000000000000000"));

      // 2º - generate MD5 from survey
      String md5FromSurvey = MD5.getMD5FromSurvey(surveyStringBuffer);

      // 3º - replace dummy checksum key by the real one
      surveyString = surveyStringBuffer.toString();
      pattern = Pattern.compile("00000000000000000000000000000000");
      matcher = pattern.matcher(surveyString);

      surveyStringBuffer = new StringBuffer(matcher.replaceAll(md5FromSurvey));

      // Saving transactionLog and Survey in Database
      TransactionLogVO tVo = new TransactionLogVO();
      tVo.setTransactionType(TransactionLogVO.NEW_USER_ADMIN);
      // tVo.setStatus(TransactionLogVO.STATUS_SUCCESS);
      tVo.setTransmissionMode(TransactionLogVO.MODE_HTTP);
      // tVo.setDtLog(new Timestamp(System.currentTimeMillis()));
      // tVo.setSurveyId(idSimpleSurvey);
      // tVo.setUser(username);

      try {
        bd.postSurvey(username, surveyStringBuffer, tVo, true);
      } catch (SurveyFileAlreadyExistsException e) {
        e.printStackTrace();
      }

    } catch (UnsupportedEncodingException e) {
      e.printStackTrace();
    } catch (IOException e) {
      e.printStackTrace();
    } catch (NoSuchAlgorithmException e) {
      e.printStackTrace();
    }
  }
Beispiel #6
0
  @Override
  public UserVO requestAccess(UserVO vo) throws MSMApplicationException, MSMSystemException {
    idSimpleSurvey = MD5.createIdSurvey();

    userDirectories =
        properties.getProperty(PropertiesUtil.SURVEY_ROOT)
            + SystemUtils.FILE_SEP
            + vo.getUsername()
            + SystemUtils.FILE_SEP
            + "survey"
            + idSimpleSurvey;

    UserVO newUser = null;

    NdgUser userPending = findNdgUserByName(vo.getUsername());
    if (userPending != null) {
      throw new UserAlreadyExistException();
    }
    UserVO userByEmail = getUserByEmail(vo.getEmail());
    if (userByEmail != null) {
      throw new EmailAlreadyExistException();
    }

    userPending = new NdgUser();
    userPending.setUsername(vo.getUsername());
    try {
      userPending.setPassword(MD5.createMD5(vo.getPassword()));
    } catch (NoSuchAlgorithmException e) {
      e.printStackTrace();
      userPending.setPassword(vo.getPassword());
    }

    userPending.setFirstName(vo.getFirstName());
    userPending.setLastName(vo.getLastName());
    userPending.setEmail(vo.getEmail());
    userPending.setWhoUseIt(vo.getWhoUseIt());
    userPending.setPhoneNumber(vo.getPhoneNumber());

    NdgRole role = findNdgRoleByName(vo.getRole().getName());
    if (role != null) {
      userPending.setRole(role);
    }

    Company company = findCompanyByName(vo.getCompany().getCompanyName());
    if (company != null) {
      userPending.setCompany(company);
    } else {
      Company newCompany = new Company();
      newCompany.setCompanyName(vo.getCompany().getCompanyName());
      newCompany.setCompanyType(vo.getCompany().getCompanyType());
      newCompany.setCompanyCountry(vo.getCompany().getCompanyCountry());
      newCompany.setCompanyIndustry(vo.getCompany().getCompanyIndustry());
      newCompany.setCompanySize(vo.getCompany().getCompanySize());
      userPending.setCompany(newCompany);
    }

    userPending.setAreaCode(vo.getAreaCode());
    userPending.setCountryCode(vo.getCountryCode());
    userPending.setEmailPreferences(vo.getEmailPreferences());
    userPending.setHowDoYouPlanUseNdg(vo.getHowDoYouPlanUseNdg());
    userPending.setValidationKey(generateValidationKey(vo.getEmail()));
    userPending.setUserValidated(vo.getUserValidated());
    userPending.setUserAdmin(userPending.getUsername());
    userPending.setFirstTimeUse(vo.getFirstTimeUse());
    userPending.setHasFullPermissions(vo.getHasFullPermissions());

    manager.persist(userPending);
    createUserFile(vo.getUsername());
    newUser = userPojoToVo(userPending);

    return newUser;
  }