Package it.eng.spagobi.commons.bo

Examples of it.eng.spagobi.commons.bo.UserProfile


      httpSession.setAttribute(SpagoBIConstants.BACK_URL, backUrl);   
    }

    errorHandler = getErrorHandler();

    UserProfile previousProfile = (UserProfile) permSess.getAttribute(IEngUserProfile.ENG_USER_PROFILE);

    String userId=null;
    if (!activeSoo) {
      userId = (String)request.getAttribute("userID");
      logger.debug("userID="+userId);
      if (userId == null) {
        if (previousProfile != null) {
          profile = previousProfile;
          // user is authenticated, nothing to do
          logger.debug("User is authenticated");
          // fill response
          MenuUtilities.getMenuItems(request, response, profile);
          // set publisher name
          response.setAttribute(SpagoBIConstants.PUBLISHER_NAME, "userhome");
          return;
        } else {
          // user must authenticate
          logger.debug("User must authenticate");
          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, "login");
          logger.debug("OUT");
          return;
        }
        //logger.error("User identifier not found. Cannot build user profile object");
        //throw new SecurityException("User identifier not found.");
      }     
    } else {

      SsoServiceInterface userProxy = SsoServiceFactory.createProxyService();
      userId = userProxy.readUserIdentifier(servletRequest);
      logger.debug("OUT,userId:"+userId);
      // if we are in SSO and user has a previous profile keep it!
      if (previousProfile != null && previousProfile.getUserId().equals(userId)) {
        if (previousProfile != null) {
          profile = previousProfile;
          // user is authenticated, nothing to do
          logger.debug("User is authenticated");
          // fill response
          MenuUtilities.getMenuItems(request, response, profile);
          // set publisher name
          response.setAttribute(SpagoBIConstants.PUBLISHER_NAME, "userhome");
          return;
        }
      } 

    }
   
   
    ISecurityServiceSupplier supplier=SecurityServiceSupplierFactory.createISecurityServiceSupplier();
    // If SSO is not active, check username and password, i.e. performs the authentication;
    // instead, if SSO is active, the authentication mechanism is provided by the SSO itself, so SpagoBI does not make
    // any authentication, just creates the user profile object and puts it into Spago permanent container
    if (!activeSoo) {
      String pwd=(String)request.getAttribute("password");      
      try {
        Object ris=supplier.checkAuthentication(userId, pwd);
        if (ris==null){
          logger.error("pwd uncorrect");
          EMFUserError emfu = new EMFUserError(EMFErrorSeverity.ERROR, 501);
          errorHandler.addError(emfu);          
          return;
        }
      } catch (Exception e) {
        logger.error("Reading user information... ERROR");
        throw new SecurityException("Reading user information... ERROR",e);
      }
      //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);
          }
        }
      }
    }

    try {
      profile=UserUtilities.getUserProfile(userId);
      if (profile == null){                 
        logger.error("user not created");
        EMFUserError emfu = new EMFUserError(EMFErrorSeverity.ERROR, 501);
        errorHandler.addError(emfu);          
        return;
      }

      Boolean userHasChanged = Boolean.TRUE;
      // try to find if the user has changed: if so, the session parameters must be reset, see also homebis.jsp
      // check previous userId with current one: if they are equals, user has not changed
      if (previousProfile != null && previousProfile.getUserId().equals(((UserProfile)profile).getUserId())) {
        userHasChanged = Boolean.FALSE;
      }
      response.setAttribute("USER_HAS_CHANGED", userHasChanged);
      // put user profile into session
      permSess.setAttribute(IEngUserProfile.ENG_USER_PROFILE, profile);
View Full Code Here


  public void doService() {
    logger.debug("IN");
    try {
      BIObject obj = getRequiredBIObject();
      if (obj != null) {
        UserProfile profile = (UserProfile) this.getUserProfile();
          boolean canSee = ObjectsAccessVerifier.canSee(obj, profile);
          if (!canSee) {
            logger.error("User [" + profile.getUserId() + "] cannot see document [id: '" + obj.getId() + "', label: '" + obj.getLabel() + "'].");
          } else {
          this.getServiceResponse().setAttribute(SpagoBIConstants.OBJECT, obj);
          SubObject subObject = getRequiredSubObject(obj);
          if (subObject != null) {
            if (profile.isAbleToExecuteAction(SpagoBIConstants.DOCUMENT_MANAGEMENT_ADMIN) ||
                (subObject.getIsPublic().booleanValue() || subObject.getOwner().equals(profile.getUserId()))) {
              this.getServiceResponse().setAttribute(SpagoBIConstants.SUBOBJECT, subObject);
            } else {
              logger.warn("User cannot see subobject [" + subObject.getName() + "] of document with label [" + obj.getLabel() + "].");
            }
          }
View Full Code Here

      // retrieving execution instance from session, no need to check if user is able to execute the current document
      ExecutionInstance executionInstance = getContext().getExecutionInstance( ExecutionInstance.class.getName() );
      BIObject obj = executionInstance.getBIObject();
      String name = getAttributeAsString("name");
      String description = getAttributeAsString("description");
      UserProfile profile = (UserProfile) this.getUserProfile();
      SubObject subobject = executionInstance.getSubObject();
      Integer subobjectId = null;
      if (subobject != null) {
        subobjectId = subobject.getId();
      }
      String parameters = getParametersQueryString(executionInstance);
     
      String message = null;
      boolean inserted;
      try {
        IRememberMeDAO dao=DAOFactory.getRememberMeDAO();
        dao.setUserProfile(profile);
        inserted = dao.saveRememberMe(name, description, obj.getId(), subobjectId, profile.getUserId().toString(), parameters);
      } catch (Exception e) {
        throw new SpagoBIServiceException(SERVICE_NAME, "Cannot save remember me", e);
      }
      if (inserted) {
        message = "ok";
View Full Code Here

  }

  private void eraseSnapshotHandler(SourceBean request, SourceBean response)
  throws EMFUserError, SourceBeanException, NumberFormatException, EMFInternalError {
    logger.debug("IN");
    UserProfile profile = (UserProfile) this.getUserProfile();
    // only if user is administrator, he can erase snapshots
    if (profile.isAbleToExecuteAction(SpagoBIConstants.DOCUMENT_MANAGEMENT_ADMIN)) {
      ISnapshotDAO snapdao = DAOFactory.getSnapshotDAO();
      List snapshotIdsList = request.getAttributeAsList(SpagoBIConstants.SNAPSHOT_ID);
      if (snapshotIdsList != null && !snapshotIdsList.isEmpty()) {
        Iterator it = snapshotIdsList.iterator();
        while (it.hasNext()) {
          String snapshotIdStr = (String) it.next();
          Integer snapId = new Integer(snapshotIdStr);
          logger.error("Deleting snaphost with id = " + snapId + " ...");
          snapdao.deleteSnapshot(snapId);
        }
      }
    } else {
      logger.error("Current user [" + profile.getUserId().toString() + "] CANNOT erase snapshots!!");
    }
    response.setAttribute(SpagoBIConstants.PUBLISHER_NAME, "ExecuteBIObjectPageParameter");
    logger.debug("OUT");
  }
View Full Code Here

   *            The response SourceBean
   */
  private void deleteSubObjectHandler(SourceBean request, SourceBean response)
  throws Exception {
    logger.debug("IN");
    UserProfile profile = (UserProfile) getUserProfile();
    String userId = profile.getUserId().toString();
    ISubObjectDAO subobjdao = DAOFactory.getSubObjectDAO();
    List subobjectsIdsList = request.getAttributeAsList(SpagoBIConstants.SUBOBJECT_ID);
    if (subobjectsIdsList != null && !subobjectsIdsList.isEmpty()) {
      Iterator it = subobjectsIdsList.iterator();
      while (it.hasNext()) {
        String subobjectIdStr = (String) it.next();
        Integer subobjectId = new Integer(subobjectIdStr);
        // check if the user is able to erase the subobject
        boolean canDelete = false;
        // if user is administrator, he can delete it
        if (profile.isAbleToExecuteAction(SpagoBIConstants.DOCUMENT_MANAGEMENT_ADMIN)) {
          canDelete = true;
        } else {
          // if user is not administrator, he can delete it only if he is the owner
          SubObject subobject = subobjdao.getSubObject(subobjectId);
          if (subobject == null) {
View Full Code Here

   * @throws EMFInternalError
   */
  private void eraseViewpoint(SourceBean request, SourceBean response)
  throws EMFUserError, SourceBeanException, EMFInternalError {
    logger.debug("IN");
    UserProfile profile = (UserProfile) getUserProfile();
    String userId = profile.getUserId().toString();
    IViewpointDAO vpDAO = DAOFactory.getViewpointDAO();
    List viewpointsIdsList = request.getAttributeAsList("vpId");
    if (viewpointsIdsList != null && !viewpointsIdsList.isEmpty()) {
      Iterator it = viewpointsIdsList.iterator();
      while (it.hasNext()) {
        String vpIdStr = (String) it.next();
        Integer vpId = new Integer(vpIdStr);
        // check if the user is able to erase the viewpoint
        boolean canDelete = false;
        // if user is administrator, he can delete it
        if (profile.isAbleToExecuteAction(SpagoBIConstants.DOCUMENT_MANAGEMENT_ADMIN)) {
          canDelete = true;
        } else {
          // if user is not administrator, he can delete it only if he is the owner
          Viewpoint vp = vpDAO.loadViewpointByID(vpId);
          if (vp == null) {
View Full Code Here

    return response;
  }

  protected JSONObject handleSubObjectExecution(Integer subObjectId, boolean isFromCross) {
    ExecutionInstance executionInstance;
    UserProfile userProfile;
   
    logger.debug("IN");
    JSONObject response = new JSONObject();
    try {
      executionInstance = getContext().getExecutionInstance( ExecutionInstance.class.getName() );
      Assert.assertNotNull(executionInstance, "Execution instance cannot be null in order to properly generate execution url");
     
      userProfile = (UserProfile) this.getUserProfile();
     
      // we are not executing a snapshot, so delete snapshot if existing
      executionInstance.setSnapshot(null);
     
      Locale locale = this.getLocale();
     
      List errors = null;
      //if (executionInstance.getBIObject().getBiObjectTypeCode().equalsIgnoreCase("DATAMART")) {
        // parameters are applied to datamarts' subobjects, so you must validate them
        JSONObject executionInstanceJSON = this.getAttributeAsJSONObject( PARAMETERS );
        executionInstance.refreshParametersValues(executionInstanceJSON, false);
        try {
          errors = executionInstance.getParametersErrors();
        } catch (Exception e) {
          throw new SpagoBIServiceException(SERVICE_NAME, "Cannot evaluate errors on parameters validation", e);
        }
      //}

      if ( errors != null && errors.size() > 0) {
        // there are errors on parameters validation, send errors' descriptions to the client
        JSONArray errorsArray = new JSONArray();
        Iterator errorsIt = errors.iterator();
        while (errorsIt.hasNext()) {
          EMFUserError error = (EMFUserError) errorsIt.next();
          errorsArray.put(error.getDescription());
        }
        try {
          response.put("errors", errorsArray);
        } catch (JSONException e) {
          throw new SpagoBIServiceException(SERVICE_NAME, "Cannot serialize errors to the client", e);
        }
      } else {
     
        ISubObjectDAO dao = null;
        try {
          dao = DAOFactory.getSubObjectDAO();
        } catch (EMFUserError e) {
          logger.error("Error while istantiating DAO", e);
          throw new SpagoBIServiceException(SERVICE_NAME, "Cannot access database", e);
        }
 
        SubObject subObject = null;
        try {
          subObject = dao.getSubObject(subObjectId);
        } catch (EMFUserError e) {
          logger.error("SubObject with id = " + subObjectId + " not found", e);
          throw new SpagoBIServiceException(SERVICE_NAME, "Customized view not found", e);
        }
       
        BIObject obj = executionInstance.getBIObject();
        if (obj.getId().equals(subObject.getBiobjId())) {
          boolean canExecuteSubObject = false;
          if (userProfile.isAbleToExecuteAction(SpagoBIConstants.DOCUMENT_MANAGEMENT_ADMIN)) {
            canExecuteSubObject = true;
          } else {
            if (subObject.getIsPublic() || subObject.getOwner().equals(userProfile.getUserId().toString())) {
              canExecuteSubObject = true;
            }
          }
          if (canExecuteSubObject) {
            executionInstance.setSubObject(subObject);
View Full Code Here

  public void doService() {
    logger.debug("IN");

    try {
      // BIObject obj = executionInstance.getBIObject();
      UserProfile userProfile = (UserProfile) this.getUserProfile();
      IBIObjectDAO dao = null;
      try {
        dao = DAOFactory.getBIObjectDAO();
      } catch (EMFUserError e) {
        logger.error("Error while istantiating DAO", e);
        throw new SpagoBIServiceException(SERVICE_NAME, "Cannot access database", e);
      }
      String ids = this.getAttributeAsString(OBJECT_ID);
      String func = this.getAttributeAsString(FUNCT_ID);
      Integer iFunc = new Integer(func);
      logger.debug("Input Folder:" + func);
      logger.debug("Input Object:" + ids);
      // ids contains the id of the object to be deleted separated by ,
      String[] idArray = ids.split(",");
      for (int i = 0; i < idArray.length; i++) {
        Integer id = new Integer(idArray[i]);
        BIObject biObject = null;
        try {
          biObject = dao.loadBIObjectById(id);
        } catch (EMFUserError e) {
          logger.error("BIObject with id = " + id + " not found", e);
          throw new SpagoBIServiceException(SERVICE_NAME, "Customized view not found", e);
        }

        if (userProfile.isAbleToExecuteAction(SpagoBIConstants.DOCUMENT_MANAGEMENT_ADMIN)) {
          // delete document
          try {
            dao.eraseBIObject(biObject, iFunc);
            logger.debug("Object deleted by administrator");
          } catch (EMFUserError e) {
View Full Code Here

    Connection conn = null;
      String schema = null;
      try {
        if (getDataSource().checkIsMultiSchema()){
          String attrname = getDataSource().getSchemaAttribute();
          UserProfile userProfile = (UserProfile)getEnv().get(EngineConstants.ENV_USER_PROFILE);
          if (attrname != null) schema = (String)userProfile.getUserAttribute(attrname);
        }
      } catch (Throwable t1) {
        logger.error("Impossible to manage properly multiSchema attribute", t1);
      }
     
View Full Code Here

    IEngUserProfile profile = null;
    try {
      ISecurityServiceSupplier supplier = SecurityServiceSupplierFactory.createISecurityServiceSupplier();
      SpagoBIUserProfile user = supplier.createUserProfile(userId);
      user.setFunctions(UserUtilities.readFunctionality(user.getRoles()));
      profile = new UserProfile(user);
    } catch (Exception e) {
      logger.error("An error occurred while creating user profile for user [" + userId + "]");
      throw new SecurityException("An error occurred while creating user profile for user [" + userId + "]", e);
    } finally {
      logger.debug("OUT");
View Full Code Here

TOP

Related Classes of it.eng.spagobi.commons.bo.UserProfile

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.