Package com.dotmarketing.beans

Examples of com.dotmarketing.beans.Permission


      String[] formTypes = WebFormFactory.getWebFormsTypes();
      ArrayList<PermissionAsset> pas = ReportFactory.getAllReports();
      Report report, newReport;
//      User user = PublicUserFactory.getDefaultUser();
//      List<Role> userRoles;
      Permission permission;
      boolean reportExists;
      for (String formType: formTypes) {
        reportExists = false;
        for (PermissionAsset asset: pas) {
          report = (Report) asset.getAsset();
View Full Code Here


    perAPI.setDefaultCMSAdminPermissions(structure);

    User systemUser = APILocator.getUserAPI().getSystemUser();
   
    /*Permission for cmsanonymous*/
    Permission p = new Permission(structure.getPermissionId(), APILocator.getRoleAPI().loadCMSAnonymousRole().getId(), PermissionAPI.PERMISSION_READ + PermissionAPI.PERMISSION_EDIT + PermissionAPI.PERMISSION_PUBLISH, true);   
    try{
      perAPI.save(p, structure, systemUser, false);
    }catch(Exception e){
      Logger.debug(FormAPIImpl.class, "Permission with Inode" + p + " cannot be saved over this asset: " + structure);
    }
       
    /*Permission for form editor*/   
    p = new Permission();
    p.setRoleId(APILocator.getRoleAPI().loadRoleByKey("Form Editor").getId());
    p.setPermission(PermissionAPI.PERMISSION_READ);
    p.setInode(structure.getPermissionId());
    try {
      perAPI.save(p, structure, systemUser, false);
    } catch (DataAccessException e) {
      Logger.debug(FormAPIImpl.class, "Permission with Inode" + p + " cannot be saved over this asset: " + structure);
    } catch (DotSecurityException e) {
      Logger.debug(FormAPIImpl.class, "Permission with Inode" + p + " cannot be saved over this asset: " + structure);
    }
   
    p = new Permission();
    p.setRoleId(APILocator.getRoleAPI().loadRoleByKey("Form Editor").getId());
    p.setPermission(PermissionAPI.PERMISSION_WRITE);
    p.setInode(structure.getPermissionId());
    try {
      perAPI.save(p, structure, systemUser, false);
    } catch (DataAccessException e) {
      Logger.debug(FormAPIImpl.class, "Permission with Inode" + p + " cannot be saved over this asset: " + structure);
    } catch (DotSecurityException e) {
      Logger.debug(FormAPIImpl.class, "Permission with Inode" + p + " cannot be saved over this asset: " + structure);
    }
   
    p = new Permission();
    p.setRoleId(APILocator.getRoleAPI().loadRoleByKey("Form Editor").getId());
    p.setPermission(PermissionAPI.PERMISSION_PUBLISH);
    p.setInode(structure.getPermissionId());
    try {
      perAPI.save(p, structure, systemUser, false);
    } catch (DataAccessException e) {
      Logger.debug(FormAPIImpl.class, "Permission with Inode" + p + " cannot be saved over this asset: " + structure);
    } catch (DotSecurityException e) {
View Full Code Here

                if ( !UtilMethods.isSet( perm ) ) {
                    continue;
                }

                Role role = resolveRole( perm );
                Permission p = new Permission( newAction.getId(), role.getId(), PermissionAPI.PERMISSION_USE );

                boolean exists = false;
                for ( Permission curr : permissions ) {
                    exists = exists || curr.getRoleId().equals( p.getRoleId() );
                }

                if ( !exists ) {
                    permissions.add( p );
                }
View Full Code Here

   * @see com.dotmarketing.business.PermissionFactory#getPermission(java.lang.String)
   */
  @Override
  protected Permission getPermission(String x) {
    try {
      Permission p = (Permission) new HibernateUtil(Permission.class).load(Long.parseLong(x));
      p.setBitPermission(true);
      return p;
    } catch (Exception e) {
      try {
        return (Permission) new HibernateUtil(Permission.class).load(x);
      } catch (DotHibernateException e1) {
View Full Code Here

    NEW, UPDATED, REMOVED, NOTHING;
  };

  private PersistResult persistPermission(Permission p) throws DotDataException {
    // Persisting changes
    Permission toPersist;
    boolean newPermission = false;
    boolean persist = true;
    if (p.isBitPermission()) {
      toPersist = findPermissionByInodeAndRole(p.getInode(), p.getRoleId(), p.getType());
      if (toPersist == null || toPersist.getId()== 0 ) {
        toPersist = p;
        newPermission = true;
      }

      if(toPersist.getPermission() == p.getPermission() && !newPermission) {
        persist = false;
      }

      toPersist.setPermission(p.getPermission());
    } else {
      toPersist = findPermissionByInodeAndRole(p.getInode(), p.getRoleId(), p.getType());
      if (toPersist == null || toPersist.getId()== 0 ) {
        toPersist = new Permission(p.getType(), p.getInode(), p.getRoleId(), 0);
        newPermission = true;
      }
      if((toPersist.getPermission() | p.getPermission()) == toPersist.getPermission() && !newPermission)
        persist = false;
      toPersist.setPermission(toPersist.getPermission() | p.getPermission());
    }

    if(toPersist.getPermission() == 0 && toPersist.getId() > 0) {
      deletePermission(toPersist);
      return PersistResult.REMOVED;
    } else if(toPersist.getPermission() != 0 && persist) {
      if(newPermission)
        HibernateUtil.save(toPersist);
      else
        HibernateUtil.saveOrUpdate(toPersist);
      return newPermission?PersistResult.NEW:PersistResult.UPDATED;
View Full Code Here

   */
  private boolean permissionExists(Permission p) {
    HibernateUtil persistanceService = new HibernateUtil(Permission.class);
    try {
      if (p.isBitPermission()) {
        Permission permission = (Permission) persistanceService.load(p.getId());
        if (permission != null) {
          return true;
        }
      } else {
        Permission permission = findPermissionByInodeAndRole(p.getInode(), p.getRoleId(), p.getType());
        if (permission != null && permission.getId() > 0 && ((permission.getPermission() & p.getPermission()) > 0)) {
          return true;
        }
      }
      return false;
    } catch (DotHibernateException e) {
View Full Code Here

    for(Permission p : bitPermissionsList) {
      if(p.isBitPermission()) {
        for(String mask : PERMISION_TYPES.keySet()) {
          if((p.getPermission() & PERMISION_TYPES.get(mask)) > 0){
            permissionsSet.add(new Permission(p.getType(), p.getInode(), p.getRoleId(), PERMISION_TYPES.get(mask)));
          }
        }
      } else {
        permissionsSet.add(p);
      }
View Full Code Here

    Map<String, Permission> tempList = new HashMap<String, Permission>();

    for(Permission p : nonbitPermissionsList) {
      if(!p.isBitPermission()) {
        Permission pt = tempList.get(p.getInode() + "-" + p.getRoleId());
        if(pt == null)
          pt = new Permission(p.getInode(), p.getRoleId(), p.getPermission());
        else
          pt = new Permission(p.getInode(), p.getRoleId(), pt.getPermission() | p.getPermission());
        tempList.put(pt.getInode() + "-" + pt.getRoleId(), pt);
      } else {
        tempList.put(p.getInode() + "-" + p.getRoleId(), p);
      }
    }
    return new ArrayList<Permission> (tempList.values());
View Full Code Here

      try{

        HibernateUtil persistenceService = new HibernateUtil();

        if(p.isBitPermission()) {
          Permission pToDel = null;

          pToDel = findPermissionByInodeAndRole(p.getInode(), p.getRoleId(), p.getType());
          if( pToDel != null )
          {
            HibernateUtil.delete(pToDel);
            Logger.debug(this.getClass(), String.format("deletePermission: %s deleted successful!", p.toString()));
            permissionCache.remove(pToDel.getInode());
          }
          else
          {
            // This should not happen unless it's with the cms admin role which we synthetically generate, but just in case... log it
            Logger.debug(this.getClass(), String.format("deletePermission: Trying to load a non-existent permission (%s)", p.toString()));
          }
        } else {
          persistenceService.setQuery("from inode in class com.dotmarketing.beans.Permission where inode_id = ? and roleid = ? and " +
              "permission_type = ?");
          persistenceService.setParam(p.getInode());
          persistenceService.setParam(p.getRoleId());
          persistenceService.setParam(p.getType());
          Permission bitPermission = (Permission) persistenceService.load();
          if (bitPermission != null) {
            bitPermission.setPermission((bitPermission.getPermission() ^ p.getPermission()) & bitPermission.getPermission());
            if (bitPermission.getPermission() == 0)
              HibernateUtil.delete(bitPermission);
            else
              HibernateUtil.save(bitPermission);
          }
        }
View Full Code Here

      }
      for(Host host : allHosts) {
        if(!host.isSystemHost()) {

          if(filterOnlyIndividualPermissions(loadPermissions(host), host.getPermissionId()).size() > 0) {
            Permission inheritablePermission = filterInheritablePermission(allPermissions, permissionable
                .getPermissionId(), Host.class.getCanonicalName(), role.getId());
            int permission = 0;
            if (inheritablePermission != null) {
              permission = inheritablePermission.getPermission();
            }
            savePermission(new Permission(host.getPermissionId(), role.getId(), permission, true), host);
          }
          cascadePermissionUnder(host, role, permissionable, allPermissions);
        }
      }
    } else if(isHost || isFolder) {
View Full Code Here

TOP

Related Classes of com.dotmarketing.beans.Permission

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.