Package it.eng.spagobi.profiling.dao

Examples of it.eng.spagobi.profiling.dao.ISbiUserDAO


        }         
      }
      //finally default users with associations
      List defaultsUsers = _config.getAttributeAsList("DEFAULT_USERS.USER");
      Iterator it = defaultsUsers.iterator();
      ISbiUserDAO userDAO= DAOFactory.getSbiUserDAO();

      while (it.hasNext()) {
          SourceBean user = (SourceBean) it.next();
         
          SbiUser sbiUser = new SbiUser();
          String userId = (String) user.getAttribute("userId");
          sbiUser.setUserId(userId);
          String password = (String) user.getAttribute("password");
        if (password!=null){
            try {
              sbiUser.setPassword(Password.encriptPassword(password));
          } catch (Exception e) {
            logger.error("Impossible to encript Password", e);
          }
        }
          String fullName = (String) user.getAttribute("fullName");
          if(fullName != null){
            sbiUser.setFullName(fullName);
          }

          try {
            //checks if user already exists
            Integer existingId = userDAO.loadByUserId(userId);
            Integer idUser =existingId;
            if(existingId == null){
              //create user id
              idUser = userDAO.saveSbiUser(sbiUser);
            }

           
            List<SourceBean> attributes = user.getAttributeAsList("ATTRIBUTE");
            if(attributes != null){
              for(int i= 0; i< attributes.size(); i++){
                SourceBean attribute = attributes.get(i);
                String name = (String)attribute.getAttribute("name");
                String value = (String)attribute.getAttribute("value");
               
                SbiUserAttributes sbiUserAttr = new SbiUserAttributes();
                sbiUserAttr.setAttributeValue(value);
               
                Integer attrID = attributesLookup.get(name);
               
                SbiUserAttributesId sbiUserAttrID = new SbiUserAttributesId();
                sbiUserAttrID.setId(idUser);//user ID
                sbiUserAttrID.setAttributeId(attrID.intValue());
                sbiUserAttr.setId(sbiUserAttrID);
               
                userDAO.updateSbiUserAttributes(sbiUserAttr);

              }
            }
            List<SourceBean> userroles = user.getAttributeAsList("ROLE");
            if(userroles != null){
              for(int i= 0; i< userroles.size(); i++){
                SourceBean role = userroles.get(i);
                String name = (String)role.getAttribute("name");
                SbiExtUserRoles sbiExtUserRole = new SbiExtUserRoles();
                SbiExtUserRolesId id = new SbiExtUserRolesId();
               
                Integer extRoleId = rolesLookup.get(name);

                int userIdInt= idUser.intValue();
                id.setExtRoleId(extRoleId);//role Id
                id.setId(userIdInt);//user ID
               
                sbiExtUserRole.setId(id);
                sbiExtUserRole.setSbiUser(sbiUser);
           
                userDAO.updateSbiUserRoles(sbiExtUserRole);


              }
            }
View Full Code Here


  public static Integer LIMIT_DEFAULT = 16;

  @Override
  public void doService() {
    logger.debug("IN");
    ISbiUserDAO userDao;
    try {
      userDao = DAOFactory.getSbiUserDAO();
      userDao.setUserProfile(getUserProfile());
    } catch (EMFUserError e1) {
      logger.error(e1.getMessage(), e1);
      throw new SpagoBIServiceException(SERVICE_NAME,  "Error occurred");
    }
    Locale locale = getLocale();

    String serviceType = this.getAttributeAsString(MESSAGE_DET);
    logger.debug("Service type "+serviceType);
    if (serviceType != null && serviceType.equalsIgnoreCase(USERS_LIST)) {
     
      try {       
        Integer start = getAttributeAsInteger( START );
        Integer limit = getAttributeAsInteger( LIMIT );
       
        if(start==null){
          start = START_DEFAULT;
        }
        if(limit==null){
          limit = LIMIT_DEFAULT;
        }

        Integer totalResNum = userDao.countUsers();
        List<UserBO> users = userDao.loadPagedUsersList(start, limit);
        logger.debug("Loaded users list");
        JSONArray usersJSON = (JSONArray) SerializerFactory.getSerializer("application/json").serialize(users,  locale);
        JSONObject usersResponseJSON = createJSONResponseUsers(usersJSON, totalResNum);

        writeBackToClient(new JSONSuccess(usersResponseJSON));

      } catch (Throwable e) {
        logger.error("Exception occurred while retrieving users", e);
        throw new SpagoBIServiceException(SERVICE_NAME,
            "Exception occurred while retrieving users", e);
      }
    } else if (serviceType != null  && serviceType.equalsIgnoreCase(USER_INSERT)) {
      Integer id = getAttributeAsInteger(ID);
      String userId = getAttributeAsString(USER_ID);
      String fullName = getAttributeAsString(FULL_NAME);
      String password = getAttributeAsString(PASSWORD);
      JSONArray rolesJSON = getAttributeAsJSONArray(ROLES);
      JSONArray attributesJSON = getAttributeAsJSONArray(ATTRIBUTES);
      if (userId != null) {
        SbiUser user = new SbiUser();
        user.setUserId(userId);
        user.setFullName(fullName);
        if(password != null && password.length() > 0){
          try {
            user.setPassword(Password.encriptPassword(password));
          } catch (Exception e) {
            logger.error("Impossible to encript Password", e);
            throw new SpagoBIServiceException(SERVICE_NAME,
                "Impossible to encript Password",e);
          }
        }
       
        if(id!=null){
          user.setId(id);
        }
        try {
          HashMap<Integer, String> attrList = null;
          if(attributesJSON != null){
            attrList = deserializeAttributesJSONArray(attributesJSON);
          }
         
          List rolesList = null;
          if(rolesJSON != null){
            rolesList = deserializeRolesJSONArray(rolesJSON);
          }
         
          id = userDao.fullSaveOrUpdateSbiUser(user, rolesList, attrList);
          logger.debug("User updated or Inserted");
          JSONObject attributesResponseSuccessJSON = new JSONObject();
          attributesResponseSuccessJSON.put("success", true);
          attributesResponseSuccessJSON.put("responseText", "Operation succeded");
          attributesResponseSuccessJSON.put("id", id);
          writeBackToClient( new JSONSuccess(attributesResponseSuccessJSON) );

        } catch (EMFUserError e) {
          logger.error("Exception occurred while saving new user", e);
          writeErrorsBackToClient();
          throw new SpagoBIServiceException(SERVICE_NAME,  "Exception occurred while saving new user",  e);
        } catch (IOException e) {
          logger.error("Exception occurred while writing response to client", e);
          throw new SpagoBIServiceException(SERVICE_NAME,
              "Exception occurred while writing response to client",
              e);
        } catch (JSONException e) {
          logger.error("JSON Exception", e);
          e.printStackTrace();
        }
      }else{
        logger.error("User name missing");
        throw new SpagoBIServiceException(SERVICE_NAME,  "Please enter user name");
      }
    } else if (serviceType != null  && serviceType.equalsIgnoreCase(USER_DELETE)) {
      Integer id = getAttributeAsInteger(ID);
      try {
        userDao.deleteSbiUserById(id);
        logger.debug("User deleted");
        writeBackToClient( new JSONAcknowledge("Operation succeded") );

      } catch (Throwable e) {
        logger.error("Exception occurred while retrieving user to delete", e);
View Full Code Here

      //getting security type: if it's internal (SpagoBI) active pwd management and checks
      boolean isInternalSecurity = ("true".equalsIgnoreCase((String)request.getAttribute("isInternalSecurity")))?true:false;
      logger.debug("isInternalSecurity: " + isInternalSecurity);
      if (isInternalSecurity)  {      
        //gets the user bo
        ISbiUserDAO userDao = DAOFactory.getSbiUserDAO();
        SbiUser user = userDao.loadSbiUserByUserId(userId);

        //check user's role: if he's admin it doesn't apply checks on password
        String strAdminPatter =  SingletonConfig.getInstance().getConfigValue("SPAGOBI.SECURITY.ROLE-TYPE-PATTERNS.ADMIN-PATTERN");
        int sbiUserId=-1;
        if (user!=null)sbiUserId=user.getId();
        List lstRoles = userDao.loadSbiUserRolesById(sbiUserId);
        boolean isAdminUser = false;

        for (int i=0; i<lstRoles.size(); i++){
          SbiExtRoles tmpRole = (SbiExtRoles)lstRoles.get(i);
          Role role = DAOFactory.getRoleDAO().loadByID(tmpRole.getExtRoleId());
          if (role.getName().equals(strAdminPatter)){
            isAdminUser = true;
            logger.debug("User is administrator. Checks on the password are not applied !");
            break;
          }
        }

        if (!isAdminUser){
          //check validation of the password
          logger.debug("Validation password starting...");

          boolean goToChangePwd = checkPwd(user);
          if (goToChangePwd){
            response.setAttribute("user_id", user.getUserId());
            String url = servletRequest.getProtocol().substring(0,servletRequest.getProtocol().indexOf("/")) +
            "://"+servletRequest.getServerName()+":"+servletRequest.getLocalPort()+servletRequest.getContextPath();
            response.setAttribute("start_url", url);
            response.setAttribute(SpagoBIConstants.PUBLISHER_NAME, "ChangePwdPublisher");
            return;
          }

          logger.info("The pwd is active!");
          //update lastAccessDate on db with current date
          try{
            if (user!=null){
              user.setDtLastAccess(new Date());
              userDao.updateSbiUser(user, user.getId());
            }
          }catch(Exception e){
            logger.error("Error while update user's dtLastAccess: " + e);
          }
        }
View Full Code Here

        getServletContext().getRequestDispatcher(targetJsp).forward(request, response);
        return;
      }

      //gets the user bo from db
      ISbiUserDAO userDao = DAOFactory.getSbiUserDAO();
      tmpUser = userDao.loadSbiUserByUserId(userId);
     
      if (message.trim().equalsIgnoreCase("CHANGE_PWD")){ 
        if (PWD_OK == CheckPwd(tmpUser)){         
          //getting days number for calculate new expiration date
          IConfigDAO configDao = DAOFactory.getSbiConfigDAO();
          List lstConfigChecks = configDao.loadConfigParametersByProperties("changepwd.expired_time");
          Date beginDate = new Date();
          if (lstConfigChecks.size() > 0){
            Config check = (Config)lstConfigChecks.get(0);           
            if (check.isActive()){
              //define the new expired date             
              Date endDate = null;
              SimpleDateFormat sdf = new SimpleDateFormat(DATE_FORMAT);
              Calendar cal = Calendar.getInstance();
              cal.set(beginDate.getYear()+1900, beginDate.getMonth(), beginDate.getDate());
              //adds n days (getted from db)
              cal.add(Calendar.DATE, Integer.parseInt(check.getValueCheck()));
              try{
                endDate = StringUtilities.stringToDate(sdf.format(cal.getTime()), DATE_FORMAT);
                logger.debug ("End Date for expiration calculeted: " + endDate);
                tmpUser.setDtPwdBegin(beginDate);
                tmpUser.setDtPwdEnd(endDate);
              }catch(Exception e){
                logger.error("The control pwd goes on error: "+e);
                throw new EMFUserError(EMFErrorSeverity.ERROR, 14008, new Vector(), new HashMap());
              }
            }           
          }
          tmpUser.setDtLastAccess(beginDate); //reset last access date
          tmpUser.setPassword(Password.encriptPassword(newPwd));//SHA encrypt
          tmpUser.setFlgPwdBlocked(false); //reset blocking flag
          userDao.updateSbiUser(tmpUser, tmpUser.getId());
          logger.debug("Updated properties for user with id " + tmpUser.getId() + " - DtLastAccess: " + tmpUser.getDtLastAccess().toString());
          //if it's all ok, redirect on login page
          response.sendRedirect(url);
        }                   
      }
View Full Code Here

TOP

Related Classes of it.eng.spagobi.profiling.dao.ISbiUserDAO

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.