Package org.nemesis.forum

Examples of org.nemesis.forum.ForumPermissions


        con.close();
      } catch (Exception e) {
        log.error("",e);
      }
    }
    return new ForumPermissions(permissions);
  }
View Full Code Here


    Cache userPermCache = (Cache) factory.getCacheManager().get(DbCacheManager.USER_PERMS_CACHE, new Integer(id));

    //Simple case: if cache is turned on and the user is already cached,
    //we can simply return the cached permissions.
    if (userPermCache != null) {
      ForumPermissions permissions = (ForumPermissions) userPermCache.get(new Integer(userID));
      if (permissions != null) {
        return permissions;
      }
    }

    //Not so simple case: cache is not turned on or the user permissions
    //have not been cached yet.
    boolean isAnonymous = (userID == -1);
    boolean isUser = !isAnonymous;

    ForumPermissions finalPermissions = ForumPermissions.none();

    //Step 1 - Get permissions for the User. This includes anonymous
    //perms, "special user" perms, and the specific perms for the user.
    if (isUser) {
      ForumPermissions userPermissions = factory.getUserPermissions(userID, id);
      //Combine permissions
      finalPermissions = new ForumPermissions(finalPermissions, userPermissions);
    }
    //Add in anonymous perms.
    ForumPermissions anonyPermissions = null;
    if (userPermCache != null) {
      anonyPermissions = (ForumPermissions) userPermCache.get(new Integer(-1));
    }
    //Otherwise, do our own lookup.
    if (anonyPermissions == null) {
      anonyPermissions = factory.getUserPermissions(-1, id);
      //Add to cache so it will be there next time.
      if (userPermCache != null) {
        userPermCache.add(new Integer(-1), anonyPermissions);
      }
    }
    //Combine permissions
    finalPermissions = new ForumPermissions(finalPermissions, anonyPermissions);

    //If they are a valid user, figure out "any user" permissions.
    if (isUser) {
      ForumPermissions specialUserPermissions = null;
      //Check for cache
      if (userPermCache != null) {
        specialUserPermissions = (ForumPermissions) userPermCache.get(new Integer(0));
      }
      //Otherwise, do our own lookup.
      if (specialUserPermissions == null) {
        specialUserPermissions = factory.getUserPermissions(0, id);
        //Add to cache so it will be there next time.
        if (userPermCache != null) {
          userPermCache.add(new Integer(0), specialUserPermissions);
        }
      }
      //Combine permissions
      finalPermissions = new ForumPermissions(finalPermissions, specialUserPermissions);
    }

    //Step 2 -- get Permissions for all groups the user is in.
    int[] groups = ((DbProfileManager) factory.getProfileManager()).getUserGroups(userID);
    for (int i = 0; i < groups.length; i++) {
      ForumPermissions groupPermissions = factory.getGroupPermissions(groups[i], id);
      finalPermissions = new ForumPermissions(finalPermissions, groupPermissions);
    }

    //Finally, add user to cache so it will be there next time.
    if (isUser && userPermCache != null) {
      userPermCache.add(new Integer(userID), finalPermissions);
View Full Code Here

    saveProperties();
  }

  public ForumPermissions getPermissions(Authorization authorization) {
    if (authorization.getUserID() == id || id == -1 || id == 0) {
      return new ForumPermissions(false, false, false, true, false, false, false, false);
    } else {
      return ForumPermissions.none();
    }
  }
View Full Code Here

    }
  }

  public User getUser() {
    User user = message.getUser();
    ForumPermissions userPermissions = user.getPermissions(authorization);
    ForumPermissions newPermissions = new ForumPermissions(permissions, userPermissions);
    return new UserProxy(user, authorization, newPermissions);
  }
View Full Code Here

  public ForumPermissions getPermissions(Authorization authorization) {
    int userID = authorization.getUserID();
    try {
      User user = profileManager.getUser(userID);
      if (isAdministrator(user)) {
        return new ForumPermissions(false, false, false, false, true, false, false, false);
      }
    } catch (Exception e) {
    }

    return ForumPermissions.none();
View Full Code Here

    }
  }

  public Forum getForum(int forumID) throws ForumNotFoundException, UnauthorizedException {
    Forum forum = factory.getForum(forumID);
    ForumPermissions forumPermissions = forum.getPermissions(authorization);
    //Create a new permissions object with the combination of the
    //permissions of this object and tempPermissions.
   
    //:ICI: ************************************************** ilya une erreur
   
    ForumPermissions newPermissions = (/*new ForumPermissions(permissions,*/ forumPermissions);
    //Check and see if the user has READ permissions. If not, throw an
    //an UnauthorizedException.
    if (!(newPermissions.get(Constants.READ)
      || newPermissions.get(Constants.FORUM_ADMIN)
      || newPermissions.get(Constants.MODERATOR)
      || newPermissions.get(Constants.SYSTEM_ADMIN))) {
      throw new UnauthorizedException();
    }
    return new ForumProxy(forum, authorization, newPermissions);
  }
View Full Code Here

    return new ForumProxy(forum, authorization, newPermissions);
  }

  public Forum getForum(String name) throws ForumNotFoundException, UnauthorizedException {
    Forum forum = factory.getForum(name);
    ForumPermissions forumPermissions = forum.getPermissions(authorization);
    //Create a new permissions object with the combination of the
    //permissions of this object and tempPermissions.
    //:ICI: **************************************************
   
    ForumPermissions newPermissions = (/*new ForumPermissions(permissions,*/ forumPermissions);
    //Check and see if the user has READ permissions. If not, throw an
    //an UnauthorizedException.
    if (!(newPermissions.get(Constants.READ)
      || newPermissions.get(Constants.FORUM_ADMIN)
      || newPermissions.get(Constants.MODERATOR)
      || newPermissions.get(Constants.SYSTEM_ADMIN))) {
      throw new UnauthorizedException();
    }
    return new ForumProxy(forum, authorization, newPermissions);
  }
View Full Code Here

     * @param authToken the authentication token of the user
     * @return true if the user is a system administrator, false otherwise.
     */
  public static boolean isSystemAdmin(Authorization authToken) {
    ForumFactory forumFactory = ForumFactory.getInstance(authToken);
    ForumPermissions permissions = forumFactory.getPermissions(authToken);
    return permissions.get(Constants.SYSTEM_ADMIN);
  }
View Full Code Here

TOP

Related Classes of org.nemesis.forum.ForumPermissions

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.