Package com.dotmarketing.business

Examples of com.dotmarketing.business.RoleAPI


            throw new DotSecurityException("not authorized");
        }

    Map<String, Boolean> userPerms = new HashMap<String,Boolean>();
    if(UtilMethods.isSet(userId)){
      RoleAPI roleAPI = APILocator.getRoleAPI();
      List<com.dotmarketing.business.Role> roles = roleAPI.loadRolesForUser(userId, false);
      for(com.dotmarketing.business.Role r : roles) {
        List<Permission> perms = APILocator.getPermissionAPI().getPermissionsByRole(r, false);
        for (Permission p : perms) {
          String permType = p.getType();
          permType = permType.equals(Folder.class.getCanonicalName())?"folderModifiable":
View Full Code Here


    ActivityLogger.logInfo(getClass(), "Modifying User Roles", "User Beign Modified:" + userId + "; "+ "Modificator User:" + currentUser.getUserId() + "; Date:" + date );
    AdminLogger.log(getClass(), "Modifying User Roles", "User Beign Modified:" + userId + "; "+ "Modificator User:" + currentUser.getUserId() + "; Date:" + date );

    WebContext ctx = WebContextFactory.get();
    RoleAPI roleAPI = APILocator.getRoleAPI();
    UserWebAPI uWebAPI = WebAPILocator.getUserWebAPI();
    HttpServletRequest request = ctx.getHttpServletRequest();
    UserAPI uAPI = APILocator.getUserAPI();

    List<com.dotmarketing.business.Role> userRoles = roleAPI.loadRolesForUser(userId);

    User user = uAPI.loadUserById(userId,uWebAPI.getLoggedInUser(request),false);

    //Remove all roles not assigned
    for(com.dotmarketing.business.Role r : userRoles) {
      if(!roleIds.contains(r.getId())) {
        if(r.isEditUsers()) {
          try {
            roleAPI.removeRoleFromUser(r, user);
          } catch(DotDataException | DotStateException e) {
            ActivityLogger.logInfo(getClass(), "Error Removing User Role", "User Beign Modified:" + userId + "; "+ "Modificator User:" + currentUser.getUserId() + "; RoleID: " + r.getId() + "; Date:" + date );
            AdminLogger.log(getClass(), "Error Removing User Role", "User Beign Modified:" + userId + "; "+ "Modificator User:" + currentUser.getUserId() + "; RoleID: " + r.getId() + "; Date:" + date );
            throw e;
          }
        }
      }
    }

    for(com.dotmarketing.business.Role r : roleAPI.loadRolesForUser(userId)) {
      if(roleIds.contains(r.getId())) {
        roleIds.remove(r.getId());
      }
    }

    //Adding missing roles
    for(String roleId : roleIds) {
      com.dotmarketing.business.Role r = roleAPI.loadRoleById(roleId);
      if(r.isEditUsers()) {
        try {
          roleAPI.addRoleToUser(r, user);
        } catch(DotDataException e) {
          ActivityLogger.logInfo(getClass(), "Error Adding User Role", "User Beign Modified:" + userId + "; "+ "Modificator User:" + currentUser.getUserId() + "; RoleID: " + r.getId() + "; Date:" + date );
          AdminLogger.log(getClass(), "Error Adding User Role", "User Beign Modified:" + userId + "; "+ "Modificator User:" + currentUser.getUserId() + "; RoleID: " + r.getId() + "; Date:" + date );
          throw e;
        } catch(DotStateException e) {
View Full Code Here

        if(loggedInUser==null || APILocator.getLayoutAPI().loadLayoutsForUser(loggedInUser).isEmpty()) {
            SecurityLogger.logInfo(UserAjax.class, "unauthorized attempt to call getRoleById by user "+loggedInUser!=null?loggedInUser.getUserId():"[not logged in]");
            throw new DotSecurityException("not authorized");
        }

    RoleAPI api = APILocator.getRoleAPI();
    Role role;
    try {
      role = com.dotmarketing.business.APILocator.getRoleAPI().loadRoleById(roleId);
    } catch (DotDataException e) {
      Logger.error(this, e.getMessage(), e);
View Full Code Here

  @Test
  public void issue5197() throws DotDataException, IOException, DotSecurityException{
    HttpServletRequest req=ServletTestRunner.localRequest.get();
    User systemUser = APILocator.getUserAPI().getSystemUser();
    PermissionAPI perAPI = APILocator.getPermissionAPI();
    RoleAPI roleAPI = APILocator.getRoleAPI();
    Host host = APILocator.getHostAPI().findDefaultHost(systemUser, true);

    User adminUser = APILocator.getUserAPI().loadByUserByEmail("admin@dotcms.com", systemUser, false);
    Role role = roleAPI.getUserRole(adminUser);
    /*
     * Create workflow scheme
     */
    String schemeName = "issue5197-"+UtilMethods.dateToHTMLDate(new Date(), "MM-dd-yyyy-HHmmss");
    String baseURL = "http://"+req.getServerName()+":"+req.getServerPort()+"/DotAjaxDirector/com.dotmarketing.portlets.workflows.business.TestableWfSchemeAjax?cmd=save&schemeId=&schemeName="+schemeName;
    URL testUrl = new URL(baseURL);
    IOUtils.toString(testUrl.openStream(),"UTF-8");
    WorkflowAPI wapi = APILocator.getWorkflowAPI();
    WorkflowScheme ws = wapi.findSchemeByName(schemeName);
    Assert.assertTrue(UtilMethods.isSet(ws));

    /*
     * Create scheme step1
     */
    baseURL = "http://"+req.getServerName()+":"+req.getServerPort()+"/DotAjaxDirector/com.dotmarketing.portlets.workflows.business.TestableWfStepAjax?cmd=add&stepName=Edit&schemeId=" +  ws.getId();
    testUrl = new URL(baseURL);
    IOUtils.toString(testUrl.openStream(),"UTF-8");
    List<WorkflowStep> steps = wapi.findSteps(ws);
    Assert.assertTrue(steps.size()==1);
    WorkflowStep step1 = steps.get(0);

    /*
     * Create scheme step2
     */
    baseURL = "http://"+req.getServerName()+":"+req.getServerPort()+"/DotAjaxDirector/com.dotmarketing.portlets.workflows.business.TestableWfStepAjax?cmd=add&stepName=Publish&schemeId=" +  ws.getId();
    testUrl = new URL(baseURL);
    IOUtils.toString(testUrl.openStream(),"UTF-8");
    steps = wapi.findSteps(ws);
    Assert.assertTrue(steps.size()==2);
    WorkflowStep step2 = steps.get(1);

    /*
     * Add action to scheme step1
     */
    baseURL = "http://"+req.getServerName()+":"+req.getServerPort()+"/DotAjaxDirector/com.dotmarketing.portlets.workflows.business.TestableWfActionAjax?cmd=save&stepId="+step1.getId()+"&schemeId="+UtilMethods.webifyString(ws.getId())+"&actionName=Edit&whoCanUse=";
    baseURL+=role.getId()+",&actionIconSelect=workflowIcon&actionAssignable=true&actionCommentable=true&actionRequiresCheckout=false&actionRoleHierarchyForAssign=false";
    baseURL+="&actionAssignToSelect="+role.getId()+"&actionNextStep="+step2.getId()+"&actionCondition=";
    testUrl = new URL(baseURL);
    IOUtils.toString(testUrl.openStream(),"UTF-8");
    List<WorkflowAction> actions1= wapi.findActions(step1, systemUser);
    Assert.assertTrue(actions1.size()==1);
    WorkflowAction action1 = actions1.get(0);

    /*
     * Add action to scheme step2
     */
    baseURL = "http://"+req.getServerName()+":"+req.getServerPort()+"/DotAjaxDirector/com.dotmarketing.portlets.workflows.business.TestableWfActionAjax?cmd=save&stepId="+step2.getId()+"&schemeId="+UtilMethods.webifyString(ws.getId())+"&actionName=Publish&whoCanUse=";
    baseURL+=role.getId()+",&actionIconSelect=workflowIcon&actionAssignable=true&actionCommentable=true&actionRequiresCheckout=false&actionRoleHierarchyForAssign=false";
    baseURL+="&actionAssignToSelect="+role.getId()+"&actionNextStep="+step2.getId()+"&actionCondition=";

    testUrl = new URL(baseURL);
    IOUtils.toString(testUrl.openStream(),"UTF-8");
    List<WorkflowAction> actions2= wapi.findActions(step2, systemUser);
    Assert.assertTrue(actions2.size()==1);
    WorkflowAction action2 = actions2.get(0);

    /*
     * Create structure and add workflow scheme
     */
    Structure st = StructureCache.getStructureByVelocityVarName("Issue5197Structure");
    if(!UtilMethods.isSet(st) || !UtilMethods.isSet(st.getInode())){
      st = new Structure();
      st.setHost(host.getIdentifier());
      st.setDescription("Testing issue 5197");
      st.setName("Issue5197Structure");
      st.setVelocityVarName("Issue5197Structure");
      st.setStructureType(Structure.STRUCTURE_TYPE_CONTENT);
      st.setFixed(false);
      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");
View Full Code Here

        // folder with some perms, where the page gets moved to
        folderWithPerms=APILocator.getFolderAPI().createFolders(
            "/test_junit/test_"+UUIDGenerator.generateUuid().replaceAll("-", "_"), host, sysuser, false);

        // create new roles
        RoleAPI roleAPI = APILocator.getRoleAPI();

        role = new Role();
        role.setName("testRole1");
        role.setRoleKey("testKey1");
        role.setEditUsers(true);
        role.setEditPermissions(true);
        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));
View Full Code Here

        ResourceResponse responseResource = new ResourceResponse( initData.getParamsMap() );

    Map<String, String> paramsMap = initData.getParamsMap();
    String roleId = paramsMap.get("id");

    RoleAPI roleAPI = APILocator.getRoleAPI();
   
    CacheControl cc = new CacheControl();
        cc.setNoCache( true );

    if(!UtilMethods.isSet(roleId) || roleId.equals("root")) {  // Loads Root Roles
      JSONArray jsonRoles = new JSONArray();
      JSONObject jsonRoleObject = new JSONObject();
      jsonRoleObject.put("id", "root");
      jsonRoleObject.put("name", "Roles");
      jsonRoleObject.put("top", "true");
     
      List<Role> rootRoles = roleAPI.findRootRoles();
      JSONArray jsonChildren = new JSONArray();

      for(Role r : rootRoles) {
        JSONObject jsonRoleChildObject = new JSONObject();
        jsonRoleChildObject.put("id", r.getId());
        jsonRoleChildObject.put("$ref", r.getId());
        jsonRoleChildObject.put("name", UtilMethods.javaScriptify(r.getName()));
        jsonRoleChildObject.put("locked", r.isLocked());
        jsonRoleChildObject.put("children", true);
       
        jsonChildren.add(jsonRoleChildObject);
      }
      //In order to add a JsonArray to a JsonObject
      //we need to specify that is an object (API bug)
      jsonRoleObject.put("children", (Object)jsonChildren);
      jsonRoles.add(jsonRoleObject);
     
      return responseResource.response(jsonRoles.toString(), cc);
     
    } else // Loads Children Roles of given Role ID
      Role role = roleAPI.loadRoleById(roleId);
     
      JSONObject jsonRoleObject = new JSONObject();
      jsonRoleObject.put("id", role.getId());
      jsonRoleObject.put("name", UtilMethods.javaScriptify(role.getName()));
      jsonRoleObject.put("locked", role.isLocked());

      JSONArray jsonChildren = new JSONArray();
     
      List<String> children = role.getRoleChildren();
      if(children != null) {
        for(String childId : children) {
          Role r = roleAPI.loadRoleById(childId);

          JSONObject jsonRoleChildObject = new JSONObject();
          jsonRoleChildObject.put("id", r.getId());
          jsonRoleChildObject.put("$ref", r.getId());
          jsonRoleChildObject.put("name", UtilMethods.javaScriptify(r.getName()));
View Full Code Here

      jsonRoleObject.put("name", "Root Role");

            return responseResource.response(jsonRoleObject.toString());
    }

    RoleAPI roleAPI = APILocator.getRoleAPI();
    Role role = roleAPI.loadRoleById(roleId);

    JSONObject jsonRoleObject = new JSONObject();
    jsonRoleObject.put("DBFQN", UtilMethods.javaScriptify(role.getDBFQN()));
    jsonRoleObject.put("FQN", UtilMethods.javaScriptify(role.getFQN()));
    jsonRoleObject.put("children", (Object)new JSONArray());
View Full Code Here

    if(!UtilMethods.isSet(name)) {
            responseResource.response( "" );//FIXME: Should return a proper error....
        }

    RoleAPI roleAPI = APILocator.getRoleAPI();
    Role userRole = roleAPI.loadRoleByKey(RoleAPI.USERS_ROOT_ROLE_KEY);
    List<Role> roles = roleAPI.findRolesByNameFilter(name, -1, -1);

    LinkedHashMap<String, Object> resultTree = new LinkedHashMap<String, Object>();

    for (Role r : roles) {
View Full Code Here

  @SuppressWarnings("unchecked")
  private JSONArray buildFilteredJsonTree(LinkedHashMap<String, Object> map) throws DotDataException, JSONException {
    JSONArray jsonChildren = new JSONArray();
   
    RoleAPI roleAPI = APILocator.getRoleAPI();

    if(map != null) {
      for (String key : map.keySet()) {
        Role r = roleAPI.loadRoleById(key);
       
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("id", r.getId().replace('-', '_'));
        jsonObject.put("name", UtilMethods.javaScriptify(r.getName()));
        jsonObject.put("locked", r.isLocked());
View Full Code Here

      htmlPage.setWebStartDate( "" );

      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.business.RoleAPI

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.