Package evolaris.framework.sys.business

Examples of evolaris.framework.sys.business.PermissionManager


      throw new BugException(e1.getMessage());
    }
    BlogManager blogMgr = new BlogManager(locale, session);
    List<Article> articles = blogMgr.getArticlesByLabel(labelParam);   
    List<DisplayableArticle> entries = new ArrayList<DisplayableArticle>();
    PermissionManager permissionMgr = new PermissionManager(locale, session);
    Map<Long, Set<Long>> blogPermissions = new HashMap<Long, Set<Long>>()// cache permissions, as computing them is expensive
    for (Article a : articles) {
      // only add articles, the user is allowed to see
      Set<Long> permissions = blogPermissions.get(a.getBlog().getId());
      if (permissions == null) {
        permissions = permissionMgr.getPermissions(a.getBlog(), webUser);
        // if group specified, only allow articles of blogs of that group!
        if (group != null && a.getBlog().getGroup() != group) {
          permissions = new HashSet<Long>();
        }
        blogPermissions.put(a.getBlog().getId(), permissions);
View Full Code Here


   * Get permissions for specified blog for specified user.
   * @param blog
   * @return
   */
  protected Set<Long> getPermissions(Blog blog, User user) {
    PermissionManager permissionMgr = new PermissionManager(locale, session);
    return permissionMgr.getPermissions(blog, user);
  }
View Full Code Here

    Group group = mgblGroup();
    Blog blog = new Blog();
    blog.setName(name);
    blog.setGroup(group);
    blog.setCode("blogcode"+(new Date().getTime()));
    PermissionManager permissionManager = new PermissionManager(locale, session);
    blog.setAccessControlledClass(permissionManager.getAccessControlledClass("BLOG"));
    blog.setCreatedAt(new Date());
    session.save(blog);
   
    // create permissions according to parameters
   
    for (Role readRole : readRoles) {
      permissionManager.setRolePermission(blog, readRole, PermissionManager.READ_PERMISSION);
    }
    for (Role writeRole : writeRoles) {
      permissionManager.setRolePermission(blog, writeRole, PermissionManager.WRITE_PERMISSION);
    }
    for (Role commentRole : commentRoles) {
      permissionManager.setRolePermission(blog, commentRole, PermissionManager.ADD_COMMENT_PERMISSION);
    }
    return blog;
  }
View Full Code Here

  }

  protected void setUp() throws Exception {
    super.setUp();
    session = HibernateSessions.startTransaction(this.getClass());
    mgr = new PermissionManager(Locale.getDefault(), session);
   
    UserManager umgr = new UserManager(Locale.getDefault(), session);
    UserSetManager usmgr = new UserSetManager(Locale.getDefault(), session);;
    adminUser = umgr.getUserDetails("rbra");
View Full Code Here

    String idParam = req.getParameter("id");
    String nameParam = req.getParameter("name");
    String formActionPath = req.getParameter("formActionPath");
    req.setAttribute("formActionPath", formActionPath);

    PermissionManager permissionMgr = new PermissionManager(locale, session);
   
    List<String> permissionValues = new ArrayList<String>();
   
    AccessControlledEntry entry = permissionMgr.getAccessControlledEntry(Long.parseLong(idParam));
    if (entry == null) {
      throw new InputException(getResources(req).getMessage(locale, "um.AccessControlledEntryNotFound", idParam));
    }
    LOGGER.debug("preparing editing of permissions for AccessControlledEntry #`"+entry.getId()+"`");
    req.setAttribute("entry", entry);
    req.setAttribute("name", nameParam);
   
    LOGGER.debug("about to fetch list of permissions for AccessControlledClass `"+entry.getAccessControlledClass().getName()+"`...");
    List<Permission> permissions = permissionMgr.getPermissions(entry.getAccessControlledClass().getName());
    LOGGER.debug("successfully fetched list of permissions.");
    LOGGER.debug("about to prepare for display...");

    List<KeyValueContainer> displayablePermissions = new ArrayList<KeyValueContainer>();
    for (Permission p : permissions) {
      try {
        String s = this.getResources(req).getMessage(locale,"um.AccessPermission_"+p.getValue());
         displayablePermissions.add(new KeyValueContainer(p.getId(), s));
         LOGGER.debug("added displayable permission `"+s+"`");
      } catch (Exception e) {
        String msg = getResources(req).getMessage(locale,"um.missingAccessPermissionName", p.getValue());
        throw new ConfigurationException(msg);
      }
    }
    req.setAttribute("permissions", displayablePermissions);

    LOGGER.debug("about to fetch anonymous permissions...");
    /* anonymous permissions */
    Set<Long> anonymousPermissions = permissionMgr.getAnonymousPermissions(entry);   
    for (Permission p : permissions) {
      if (anonymousPermissions.contains(p.getId())) {
        permissionValues.add("anonymous_"+p.getId());
      }
    }
    LOGGER.debug("successfully fetched anonymous permissions.");

    LOGGER.debug("about to fetch role permissions...");
    /* role permissions */
    UserManager userMgr = new UserManager(locale,session);
    Role[] roles = null;
    if (req.isUserInRole(UserManagerBase.ADMINISTRATOR)) {
      roles = userMgr.getRoles();
    } else  if (req.isUserInRole(UserManagerBase.GROUP_ADMINISTRATOR)) {
      roles = webUser.getRoles().toArray(new Role[0])// only show the own roles
    } else {
      LOGGER.error("insufficient rights - user must be GROUP_ADMINISTRATOR or ADMINISTRATOR to edit permissions.");
      throw new InputException(getResources(req).getMessage(locale, "um.insufficientRights"));
    }   
    req.setAttribute("roles", roles);
    for (Role r : roles) {
      Set<Long> rolePermissions = permissionMgr.getRolePermissions(entry, r);   
      for (Permission p : permissions) {
        if (rolePermissions.contains(p.getId())) {
          permissionValues.add("role_"+r.getId()+"_"+p.getId());
        }       
      }
    }
    LOGGER.debug("successfully fetched role permissions.");
   
    LOGGER.debug("about to fetch userset permissions...");
    /* userset permissions */
    UserSet[] userSets = entry.getGroup().getUserSets().toArray(new UserSet[0]);
    req.setAttribute("usersets", userSets);   
    for (UserSet s : userSets) {
      Set<Long> userSetPermissions = permissionMgr.getUserSetPermissions(entry, s);   
      for (Permission p : permissions) {
        if (userSetPermissions.contains(p.getId())) {
          permissionValues.add("userset_"+s.getId()+"_"+p.getId());
        }
      }
    }
    LOGGER.debug("sucessfully fetched userset permissions.");
   
    LOGGER.debug("about to fetch user permissions.");
    /* user permissions */
    User[] users = userMgr.getUsers(entry.getGroup(), false)// get all users with a username
    if (users != null && users.length > 100) {     
      req.setAttribute("tooManyUsers", getLocalizedMessage("application", "um.tooManyUsersForPermissions", 100));
    } else {
      req.setAttribute("users", users);
      for (User u : users) {
        Set<Long> userPermissions = permissionMgr.getUserPermissions(entry, u);   
        for (Permission p : permissions) {
          if (userPermissions.contains(p.getId())) {
            permissionValues.add("user_"+u.getId()+"_"+p.getId());
          }       
        }
View Full Code Here

  public ActionForward modify(ActionMapping mapping, ActionForm form, HttpServletRequest req, HttpServletResponse resp) {
    if (! (req.isUserInRole(UserManagerBase.ADMINISTRATOR) || req.isUserInRole(UserManagerBase.GROUP_ADMINISTRATOR))) {
      throw new InputException(getResources(req).getMessage(locale, "um.insufficientRights"));
    }
    PermissionForm permissionForm = (PermissionForm)form;
    PermissionManager permissionMgr = new PermissionManager(locale, session);

    AccessControlledEntry entry = permissionMgr.getAccessControlledEntry(permissionForm.getId());
    if (entry == null) {
      throw new InputException(getResources(req).getMessage(locale, "um.AccessControlledEntryNotFound", permissionForm.getId()));
    }
   
    Set<Long> anonymousPermissions = new HashSet<Long>();
    Map<Long, Set<Long>> rolePermissions = new HashMap<Long, Set<Long>>();
    Map<Long, Set<Long>> userSetPermissions = new HashMap<Long, Set<Long>>();
    Map<Long, Set<Long>> userPermissions = new HashMap<Long, Set<Long>>();
    for (String p : permissionForm.getPermission()) {
      String[] parts = p.split("_");
      if ("anonymous".equals(parts[0])) {
        anonymousPermissions.add(Long.parseLong(parts[1]));
      } else if ("role".equals(parts[0])) {
        Long roleId = Long.parseLong(parts[1]);
        if (!rolePermissions.containsKey(roleId)) {
          rolePermissions.put(roleId, new HashSet<Long>());
        }
        Long permission = Long.parseLong(parts[2]);
        if (permission > 0) {
          rolePermissions.get(roleId).add(permission);
        }
      } else if ("userset".equals(parts[0])) {
        Long userSetId = Long.parseLong(parts[1]);
        if (!userSetPermissions.containsKey(userSetId)) {
          userSetPermissions.put(userSetId, new HashSet<Long>());
        }
        Long permission = Long.parseLong(parts[2]);
        if (permission > 0) {
          userSetPermissions.get(userSetId).add(permission);
        }
      } else if ("user".equals(parts[0])) {
        Long userId = Long.parseLong(parts[1]);
        if (!userPermissions.containsKey(userId)) {
          userPermissions.put(userId, new HashSet<Long>());
        }
        Long permission = Long.parseLong(parts[2]);
        if (permission > 0) {
          userPermissions.get(userId).add(permission);
        }
      }
    }
       
    UserManager userMgr = new UserManager(locale, session);
    UserSetManager userSetMgr = new UserSetManager(locale, session);
   
    permissionMgr.setAnonymousPermissions(entry, anonymousPermissions.toArray(new Long[0]));
    for (Iterator<Map.Entry<Long, Set<Long>>> iter = rolePermissions.entrySet().iterator(); iter.hasNext();) {
      Map.Entry<Long, Set<Long>> element = iter.next();
      Role role = userMgr.getRole(element.getKey());
      permissionMgr.setRolePermissions(entry, role, element.getValue().toArray(new Long[0]));
    }
    for (Iterator<Map.Entry<Long, Set<Long>>> iter = userSetPermissions.entrySet().iterator(); iter.hasNext();) {
      Map.Entry<Long, Set<Long>> element = iter.next();
      UserSet userSet = userSetMgr.getUserSet(element.getKey());
      permissionMgr.setUserSetPermissions(entry, userSet, element.getValue().toArray(new Long[0]));
    }
    for (Iterator<Map.Entry<Long, Set<Long>>> iter = userPermissions.entrySet().iterator(); iter.hasNext();) {
      Map.Entry<Long, Set<Long>> element = iter.next();
      User user = userMgr.getUserDetails(element.getKey());
      permissionMgr.setUserPermissions(entry, user, element.getValue().toArray(new Long[0]));
    }
   
    return mapping.findForward("modified");
  }
View Full Code Here

   * Get permissions for specified blog for specified user.
   * @param blog
   * @return
   */
  protected Set<Long> getPermissions(Blog blog, User user) {
    PermissionManager permissionMgr = new PermissionManager(locale, session);
    return permissionMgr.getPermissions(blog, user);
  }
View Full Code Here

   * Get permissions for specified blog for specified user.
   * @param blog
   * @return
   */
  protected Set<Long> getPermissions(Blog blog, User user) {
    PermissionManager permissionMgr = new PermissionManager(locale, session);
    Group originalGroup = blog.getGroup();
    if (originalGroup.getClientProject().getName().equals("mgbl")) {
      blog.setGroup(user.getGroup())// outflank getRolesPermissions()
    }
    Set<Long> permissions = new HashSet<Long>();
    permissions.addAll(permissionMgr.getAnonymousPermissions(blog));
    permissions.addAll(permissionMgr.getRolesPermissions(blog, user));     
    blog.setGroup(originalGroup);
    return permissions;
  }
View Full Code Here

   * Get permissions for specified blog for specified user.
   * @param blog
   * @return
   */
  protected Set<Long> getPermissions(Blog blog, User user) {
    PermissionManager permissionMgr = new PermissionManager(locale, session);
    Group originalGroup = blog.getGroup();
    if (originalGroup.getClientProject().getName().equals("mgbl")) {
      blog.setGroup(user.getGroup())// outflank getRolesPermissions()
    }
    Set<Long> permissions = new HashSet<Long>();
    permissions.addAll(permissionMgr.getAnonymousPermissions(blog));
    permissions.addAll(permissionMgr.getRolesPermissions(blog, user));     
    blog.setGroup(originalGroup);
    return permissions;
 
View Full Code Here

    Criteria crit  = session.createCriteria(Blog.class);
    if (group != null) {
      crit.add(Restrictions.eq("group", group));
    }
    List<Blog> all = (List<Blog>)crit.list();
    PermissionManager permissionMgr = new PermissionManager(locale, session);
    for (Blog b : all) {
      if (permissionMgr.getPermissions(b, user).contains(PermissionManager.READ_PERMISSION)) {
        result.add(b);
      }
    }
    return result;
  }
View Full Code Here

TOP

Related Classes of evolaris.framework.sys.business.PermissionManager

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.