Package com.dotmarketing.beans

Examples of com.dotmarketing.beans.Permission


    List<Permission> permissionablePermissions = loadPermissions(permissionable);

    if (isHost) {

      //Templates
      Permission inheritablePermission = filterInheritablePermission(allPermissions, permissionsPermissionable
          .getPermissionId(), Template.class.getCanonicalName(), role.getId());

      //Assigning inheritable permissions to the permissionable if needed
      List<Permission> permissionableTemplatePermissions = filterOnlyInheritablePermissions(permissionablePermissions, permissionable.getPermissionId(),
          Template.class.getCanonicalName());
      if(permissionableTemplatePermissions.size() > 0) {
        Permission permissionToUpdate = filterInheritablePermission(permissionablePermissions, permissionsPermissionable.getPermissionId(),
            Template.class.getCanonicalName(), role.getId());
        if(permissionToUpdate == null) {
          permissionToUpdate = new Permission(Template.class.getCanonicalName(), permissionable.getPermissionId(), role.getId(), 0, true);
        }
        if(inheritablePermission != null)
          permissionToUpdate.setPermission(inheritablePermission.getPermission());
        savePermission(permissionToUpdate, permissionable);
      }

      //Looking for children templates overriding inheritance to also apply the cascade changes
      dc.setSQL(selectChildrenTemplateWithIndividualPermissionsSQL);
      dc.addParam(host.getPermissionId());
      List<Map<String, String>> idsToUpdate = dc.loadResults();
      TemplateAPI templateAPI = APILocator.getTemplateAPI();
      int permission = 0;
      if (inheritablePermission != null) {
        permission = inheritablePermission.getPermission();
      }
      for (Map<String, String> idMap : idsToUpdate) {
        String id = idMap.get("id");
        Permissionable childPermissionable;
        try {
          childPermissionable = templateAPI.findWorkingTemplate(id, systemUser, false);
        } catch (DotSecurityException e) {
          Logger.error(PermissionBitFactoryImpl.class, e.getMessage(), e);
          throw new DotRuntimeException(e.getMessage(), e);
        }
        savePermission(new Permission(id, role.getId(), permission, true), childPermissionable);
      }

      //Containers
      inheritablePermission = filterInheritablePermission(allPermissions, permissionsPermissionable.getPermissionId(),
          Container.class.getCanonicalName(), role.getId());

      //Assigning inheritable permissions to the permissionable if needed
      List<Permission> permissionableContainerPermissions = filterOnlyInheritablePermissions(permissionablePermissions, permissionable.getPermissionId(),
          Container.class.getCanonicalName());
      if(permissionableContainerPermissions.size() > 0) {
        Permission permissionToUpdate = filterInheritablePermission(permissionablePermissions, permissionsPermissionable.getPermissionId(),
            Container.class.getCanonicalName(), role.getId());
        if(permissionToUpdate == null) {
          permissionToUpdate = new Permission(Container.class.getCanonicalName(), permissionable.getPermissionId(), role.getId(), 0, true);
        }
        if(inheritablePermission != null)
          permissionToUpdate.setPermission(inheritablePermission.getPermission());
        savePermission(permissionToUpdate, permissionable);
      }

      //Looking for children containers overriding inheritance to also apply the cascade changes
      dc.setSQL(selectChildrenContainerWithIndividualPermissionsSQL);
      dc.addParam(host.getPermissionId());
      idsToUpdate = dc.loadResults();
      ContainerAPI containerAPI = APILocator.getContainerAPI();
      permission = 0;
      if (inheritablePermission != null) {
        permission = inheritablePermission.getPermission();
      }
      for (Map<String, String> idMap : idsToUpdate) {
        String id = idMap.get("id");
        Permissionable childPermissionable;
        try {
          childPermissionable = containerAPI.getWorkingContainerById(id, systemUser, false);
        } catch (DotSecurityException e) {
          Logger.error(PermissionBitFactoryImpl.class, e.getMessage(), e);
          throw new DotRuntimeException(e.getMessage(), e);
        }
        savePermission(new Permission(id, role.getId(), permission, true), childPermissionable);
      }

    }

    //Folders
    Permission inheritablePermission = filterInheritablePermission(allPermissions,
        permissionsPermissionable.getPermissionId(), Folder.class.getCanonicalName(), role.getId());

    //Assigning inheritable permissions to the permissionable if needed
    List<Permission> permissionableFolderPermissions = filterOnlyInheritablePermissions(permissionablePermissions, permissionable.getPermissionId(),
        Folder.class.getCanonicalName());
    if(permissionableFolderPermissions.size() > 0) {
      Permission permissionToUpdate = filterInheritablePermission(permissionablePermissions, permissionsPermissionable.getPermissionId(),
          Folder.class.getCanonicalName(), role.getId());
      if(permissionToUpdate == null) {
        permissionToUpdate = new Permission(Folder.class.getCanonicalName(), permissionable.getPermissionId(), role.getId(), 0, true);
      }
      if(inheritablePermission != null)
        permissionToUpdate.setPermission(inheritablePermission.getPermission());
      savePermission(permissionToUpdate, permissionable);
    }

    // Selecting folders which are children and need individual permission
    // changes
    dc.setSQL(selectChildrenFolderWithDirectPermissionsSQL);
    dc.addParam(host.getPermissionId());
    dc.addParam(isHost ? "%" : folderPath + "%");
    dc.addParam(isHost ? " " : folderPath + "");
    List<Map<String, String>> idsToUpdate = dc.loadResults();
    FolderAPI folderAPI = APILocator.getFolderAPI();
    int permission = 0;
    if (inheritablePermission != null) {
      permission = inheritablePermission.getPermission();
    }
    for (Map<String, String> idMap : idsToUpdate) {
      String id = idMap.get("inode");
      Permissionable childPermissionable;
      try {
        childPermissionable = folderAPI.find(id, systemUser, false);
        savePermission(new Permission(id, role.getId(), permission, true), childPermissionable);
      } catch (DotSecurityException e) {
        Logger.error(this.getClass(), "Should not be getting a Permission Error with system user", e);
      }

    }

    //HTML pages

    inheritablePermission = filterInheritablePermission(allPermissions, permissionsPermissionable.getPermissionId(),
        HTMLPage.class.getCanonicalName(), role.getId());

    //Assigning inheritable permissions to the permissionable if needed
    List<Permission> permissionablePagesPermissions = filterOnlyInheritablePermissions(permissionablePermissions, permissionable.getPermissionId(),
        HTMLPage.class.getCanonicalName());
    if(permissionablePagesPermissions.size() > 0) {
      Permission permissionToUpdate = filterInheritablePermission(permissionablePermissions, permissionsPermissionable.getPermissionId(),
          HTMLPage.class.getCanonicalName(), role.getId());
      if(permissionToUpdate == null) {
        permissionToUpdate = new Permission(HTMLPage.class.getCanonicalName(), permissionable.getPermissionId(), role.getId(), 0, true);
      }
      if(inheritablePermission != null)
        permissionToUpdate.setPermission(inheritablePermission.getPermission());
      savePermission(permissionToUpdate, permissionable);
    }

    // Selecting html pages which are children and need individual
    // permission changes
    dc.setSQL(selectChildrenHTMLPageWithIndividualPermissionsSQL);
    dc.addParam(host.getPermissionId());
    dc.addParam(isHost ? "%" : folderPath + "%");
    idsToUpdate = dc.loadResults();
    HTMLPageAPI pageAPI = APILocator.getHTMLPageAPI();
    permission = 0;
    if (inheritablePermission != null) {
      permission = inheritablePermission.getPermission();
    }
    for (Map<String, String> idMap : idsToUpdate) {
      String id = idMap.get("id");
      Permissionable childPermissionable;
      try {
        childPermissionable = pageAPI.loadWorkingPageById(id, systemUser, false);
      } catch (DotSecurityException e) {
        Logger.error(PermissionBitFactoryImpl.class, e.getMessage(), e);
        throw new DotRuntimeException(e.getMessage(), e);
      }
      savePermission(new Permission(id, role.getId(), permission, true), childPermissionable);
    }

    // File

    inheritablePermission = filterInheritablePermission(allPermissions, permissionsPermissionable.getPermissionId(),
        File.class.getCanonicalName(), role.getId());

    //Assigning inheritable permissions to the permissionable if needed
    List<Permission> permissionableFilesPermissions = filterOnlyInheritablePermissions(permissionablePermissions, permissionable.getPermissionId(),
        File.class.getCanonicalName());
    if(permissionableFilesPermissions.size() > 0) {
      Permission permissionToUpdate = filterInheritablePermission(permissionablePermissions, permissionsPermissionable.getPermissionId(),
          File.class.getCanonicalName(), role.getId());
      if(permissionToUpdate == null) {
        permissionToUpdate = new Permission(File.class.getCanonicalName(), permissionable.getPermissionId(), role.getId(), 0, true);
      }
      if(inheritablePermission != null)
        permissionToUpdate.setPermission(inheritablePermission.getPermission());
      savePermission(permissionToUpdate, permissionable);
    }

    // Selecting files which are children and need individual permission
    // changes
    dc.setSQL(selectChildrenFileWithIndividualPermissionsSQL);
    dc.addParam(host.getPermissionId());
    dc.addParam(isHost ? "%" : folderPath + "%");
    idsToUpdate = dc.loadResults();
    FileAPI fileAPI = APILocator.getFileAPI();
    permission = 0;
    if (inheritablePermission != null) {
      permission = inheritablePermission.getPermission();
    }
    for (Map<String, String> idMap : idsToUpdate) {
      String id = idMap.get("id");
      Permissionable childPermissionable;
      try {
        childPermissionable = fileAPI.getWorkingFileById(id, systemUser, false);
      } catch (DotSecurityException e) {
        Logger.error(PermissionBitFactoryImpl.class, e.getMessage(), e);
        throw new DotRuntimeException(e.getMessage(), e);
      }
      savePermission(new Permission(id, role.getId(), permission, true), childPermissionable);
    }

    // Links

    inheritablePermission = filterInheritablePermission(allPermissions, permissionsPermissionable.getPermissionId(),
        Link.class.getCanonicalName(), role.getId());

    //Assigning inheritable permissions to the permissionable if needed
    List<Permission> permissionableLinksPermissions = filterOnlyInheritablePermissions(permissionablePermissions, permissionable.getPermissionId(),
        Link.class.getCanonicalName());
    if(permissionableLinksPermissions.size() > 0) {
      Permission permissionToUpdate = filterInheritablePermission(permissionablePermissions, permissionsPermissionable.getPermissionId(),
          Link.class.getCanonicalName(), role.getId());
      if(permissionToUpdate == null) {
        permissionToUpdate = new Permission(Link.class.getCanonicalName(), permissionable.getPermissionId(), role.getId(), 0, true);
      }
      if(inheritablePermission != null)
        permissionToUpdate.setPermission(inheritablePermission.getPermission());
      savePermission(permissionToUpdate, permissionable);
    }

    // Selecting links which are children and need individual permission
    // changes
    dc.setSQL(selectChildrenLinkWithIndividualPermissionsSQL);
    dc.addParam(host.getPermissionId());
    dc.addParam(isHost ? "%" : folderPath + "%");
    idsToUpdate = dc.loadResults();
    MenuLinkAPI linkAPI = APILocator.getMenuLinkAPI();
    permission = 0;
    if (inheritablePermission != null) {
      permission = inheritablePermission.getPermission();
    }
    for (Map<String, String> idMap : idsToUpdate) {
      String id = idMap.get("id");
      Permissionable childPermissionable;
      try {
        childPermissionable = linkAPI.findWorkingLinkById(id, systemUser, false);
      } catch (DotSecurityException e) {
        Logger.error(PermissionBitFactoryImpl.class, e.getMessage(), e);
        throw new DotRuntimeException(e.getMessage(), e);
      }
      savePermission(new Permission(id, role.getId(), permission, true), childPermissionable);
    }

    // Contentlets

    inheritablePermission = filterInheritablePermission(allPermissions, permissionsPermissionable.getPermissionId(),
        Contentlet.class.getCanonicalName(), role.getId());

    //Assigning inheritable permissions to the permissionable if needed
    List<Permission> permissionableContentPermissions = filterOnlyInheritablePermissions(permissionablePermissions, permissionable.getPermissionId(),
        Contentlet.class.getCanonicalName());
    if(permissionableContentPermissions.size() > 0) {
      Permission permissionToUpdate = filterInheritablePermission(permissionablePermissions, permissionsPermissionable.getPermissionId(),
          Contentlet.class.getCanonicalName(), role.getId());
      if(permissionToUpdate == null) {
        permissionToUpdate = new Permission(Contentlet.class.getCanonicalName(), permissionable.getPermissionId(), role.getId(), 0, true);
      }
      if(inheritablePermission != null)
        permissionToUpdate.setPermission(inheritablePermission.getPermission());
      savePermission(permissionToUpdate, permissionable);
    }

    // Selecting content which are children and need individual permission
    // changes
    dc.setSQL(selectChildrenContentWithIndividualPermissionsByPathSQL);
    dc.addParam(host.getPermissionId());
    dc.addParam(isHost ? "%" : folderPath + "%");
    idsToUpdate = dc.loadResults();
    ContentletAPI contentAPI = APILocator.getContentletAPI();
    permission = 0;
    if (inheritablePermission != null) {
      permission = inheritablePermission.getPermission();
    }
    for (Map<String, String> idMap : idsToUpdate) {
      String id = idMap.get("id");

      //Search contentlets by identifier (all languages) and set permissions
      String luceneQuery = "+identifier:"+id+" +working:true";
      try {
        for(Permissionable childPermissionable: contentAPI.search(luceneQuery,1,0,null,systemUser, false)) {
          savePermission(new Permission(id, role.getId(), permission, true), childPermissionable);
          break;
        }
      } catch (DotSecurityException e) {
        Logger.error(PermissionBitFactoryImpl.class, e.getMessage(), e);
        throw new DotRuntimeException(e.getMessage(), e);
      }
    }

    // Structures

    inheritablePermission = filterInheritablePermission(allPermissions, permissionsPermissionable.getPermissionId(),
        Structure.class.getCanonicalName(), role.getId());

    //Assigning inheritable permissions to the permissionable if needed
    List<Permission> permissionableStructurePermissions = filterOnlyInheritablePermissions(permissionablePermissions, permissionable.getPermissionId(),
        Structure.class.getCanonicalName());
    if(permissionableStructurePermissions.size() > 0) {
      Permission permissionToUpdate = filterInheritablePermission(permissionablePermissions, permissionsPermissionable.getPermissionId(),
          Structure.class.getCanonicalName(), role.getId());
      if(permissionToUpdate == null) {
        permissionToUpdate = new Permission(Structure.class.getCanonicalName(), permissionable.getPermissionId(), role.getId(), 0, true);
      }
      if(inheritablePermission != null)
        permissionToUpdate.setPermission(inheritablePermission.getPermission());
      savePermission(permissionToUpdate, permissionable);
    }


    // Selecting structures which are children and need individual permission
    // changes
    dc.setSQL(selectChildrenStructureWithIndividualPermissionsByPathSQL);
    dc.addParam(isHost ? "%" : folderPath + "%");
    dc.addParam(host.getPermissionId());
    dc.addParam(host.getPermissionId());
    idsToUpdate = dc.loadResults();
    permission = 0;
    if (inheritablePermission != null) {
      permission = inheritablePermission.getPermission();
    }

    for (Map<String, String> idMap : idsToUpdate) {
      String id = idMap.get("inode");
      Permissionable childPermissionable = StructureCache.getStructureByInode(id);
      savePermission(new Permission(id, role.getId(), permission, true), childPermissionable);
      //http://jira.dotmarketing.net/browse/DOTCMS-6090
      //If a structure we need to save permissions inheritable by children content
      savePermission(new Permission(Contentlet.class.getCanonicalName(), id, role.getId(), permission, true),childPermissionable);
    }

  }
View Full Code Here


  private ArrayList<Permission> _getSelectedPermissions(ActionRequest req, Contentlet con){
    ArrayList<Permission> pers = new ArrayList<Permission>();
    String[] readPermissions = req.getParameterValues("read");
    if (readPermissions != null) {
      for (int k = 0; k < readPermissions.length; k++) {
        pers.add(new Permission(con.getInode(), readPermissions[k], PermissionAPI.PERMISSION_READ));
      }
    }

    String[] writePermissions = req.getParameterValues("write");
    if (writePermissions != null) {
      for (int k = 0; k < writePermissions.length; k++) {
        pers.add(new Permission(con.getInode(), writePermissions[k], PermissionAPI.PERMISSION_WRITE));

      }
    }

    String[] publishPermissions = req.getParameterValues("publish");
    if (publishPermissions != null) {
      for (int k = 0; k < publishPermissions.length; k++) {
        pers.add(new Permission(con.getInode(), publishPermissions[k], PermissionAPI.PERMISSION_PUBLISH));
      }
    }
    return pers;
  }
View Full Code Here

      st.setOwner(systemUser.getUserId());
      st.setExpireDateVar("");
      st.setPublishDateVar("");
      StructureFactory.saveStructure(st);

      Permission p = new Permission();
      p.setInode(st.getPermissionId());
      p.setRoleId(roleAPI.loadCMSAnonymousRole().getId());
      p.setPermission(PermissionAPI.PERMISSION_READ);
      perAPI.save(p, st, systemUser, true);

      p = new Permission();
      p.setInode(st.getPermissionId());
      p.setRoleId(roleAPI.loadCMSAnonymousRole().getId());
      p.setPermission(PermissionAPI.PERMISSION_EDIT);
      perAPI.save(p, st, systemUser, true);

      p = new Permission();
      p.setInode(st.getPermissionId());
      p.setRoleId(roleAPI.loadCMSAnonymousRole().getId());
      p.setPermission(PermissionAPI.PERMISSION_PUBLISH);
      perAPI.save(p, st, systemUser, true)

      Field title = new Field("Title",Field.FieldType.TEXT,Field.DataType.TEXT,st,true,true,true,1,"", "", "", false, false, true);
      title.setVelocityVarName("title");
      FieldFactory.saveField(title);
View Full Code Here

        role.setEditLayouts(true);
        role.setDescription("testDesc1");
        role = roleAPI.save(role);

        List<Permission> newSetOfPermissions = new ArrayList<Permission>();
        newSetOfPermissions.add(new Permission(HTMLPage.class.getCanonicalName(), folderWithPerms.getPermissionId(), role.getId(),
            PermissionAPI.PERMISSION_READ, true));

        PermissionAPI permAPI = APILocator.getPermissionAPI();
        permAPI.assignPermissions(newSetOfPermissions, folderWithPerms, sysuser, false);

        APILocator.getHTMLPageAPI().movePage(page, folderWithPerms, sysuser, false);

        List<Permission> assetPermissions = permAPI.getPermissions(page, true);

        assertNotNull(assetPermissions);
        assertTrue(!assetPermissions.isEmpty());

        Permission pageReadPerm = assetPermissions.get(0);

        assertTrue(pageReadPerm.getType().equals(HTMLPage.class.getCanonicalName()) && pageReadPerm.getPermission()==1);

      } catch (Exception e) {
        try {
          HibernateUtil.rollbackTransaction();
        } catch (DotHibernateException e1) {
View Full Code Here

        testStructure.setType( "structure" );
        testStructure.setVelocityVarName( "structure2709" );

        StructureFactory.saveStructure( testStructure );

        Permission permissionRead = new Permission( testStructure.getInode(), APILocator.getRoleAPI().loadCMSAnonymousRole().getId(), PermissionAPI.PERMISSION_READ );
        Permission permissionEdit = new Permission( testStructure.getInode(), APILocator.getRoleAPI().loadCMSAnonymousRole().getId(), PermissionAPI.PERMISSION_EDIT );
        Permission permissionWrite = new Permission( testStructure.getInode(), APILocator.getRoleAPI().loadCMSAnonymousRole().getId(), PermissionAPI.PERMISSION_WRITE );

        APILocator.getPermissionAPI().save( permissionRead, testStructure, user, false );
        APILocator.getPermissionAPI().save( permissionEdit, testStructure, user, false );
        APILocator.getPermissionAPI().save( permissionWrite, testStructure, user, false );
View Full Code Here

      htmlPage = APILocator.getHTMLPageAPI().saveHTMLPage( htmlPage, template, testFolder, user, false );

      PermissionAPI permissionAPI = APILocator.getPermissionAPI();
      RoleAPI roleAPI = APILocator.getRoleAPI();

      Permission newPermission = new Permission( htmlPage.getPermissionId(), roleAPI.loadCMSAnonymousRole().getId(), PermissionAPI.PERMISSION_READ, true );
      permissionAPI.save( newPermission, htmlPage, user, false );

      //Make it working and live
      APILocator.getVersionableAPI().setWorking( htmlPage );
      APILocator.getVersionableAPI().setLive( htmlPage );

      // WIDGET


      widget = new Contentlet();
      widget.setReviewInterval("1m");
      widget.setStructureInode(simpleWidgetSt.getInode());
      widget.setHost(demoHost.getIdentifier());

      Field widgetTitle =  simpleWidgetSt.getFieldVar("widgetTitle");
      Field widgetCode = simpleWidgetSt.getFieldVar("code");


      ContentletAPI contentletAPI = APILocator.getContentletAPI();

      contentletAPI.setContentletProperty( widget, widgetTitle, "newsTestWidget" );
      contentletAPI.setContentletProperty( widget, widgetCode, "$URLMapContent.story" );

      widget = contentletAPI.checkin( widget, null, permissionAPI.getPermissions( simpleWidgetSt ), user, false );
      APILocator.getVersionableAPI().setLive(widget);

      // add the widget to the detail page
      MultiTreeFactory.saveMultiTree( new MultiTree( htmlPage.getIdentifier(), container.getIdentifier(), widget.getIdentifier() ) );

     
      // STRUCTURE
      testSt = new Structure();

      testSt.setDefaultStructure( false );
      testSt.setDescription( "News Test" );
      testSt.setFixed( false );
      testSt.setIDate( new Date() );
      testSt.setName( "NewsTest" +salt);
      testSt.setOwner( user.getUserId() );
      testSt.setStructureType( Structure.STRUCTURE_TYPE_CONTENT );
      testSt.setType( "structure" );
      testSt.setVelocityVarName( "NewsTest" +salt );
      testSt.setUrlMapPattern("/newstest"+salt+"/{urlNewsTitle}");
      testSt.setDetailPage( htmlPage.getIdentifier() );

      StructureFactory.saveStructure( testSt );

      //Creating and adding permissions
      Permission permissionRead = new Permission( testSt.getInode(), roleAPI.loadCMSAnonymousRole().getId(), PermissionAPI.PERMISSION_READ );
      Permission permissionEdit = new Permission( testSt.getInode(), roleAPI.loadCMSAnonymousRole().getId(), PermissionAPI.PERMISSION_EDIT );
      Permission permissionWrite = new Permission( testSt.getInode(), roleAPI.loadCMSAnonymousRole().getId(), PermissionAPI.PERMISSION_WRITE );

      permissionAPI.save( permissionRead, testSt, user, false );
      permissionAPI.save( permissionEdit, testSt, user, false );
      permissionAPI.save( permissionWrite, testSt, user, false );
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.