예제 #1
0
  /**
   * * Load user's roles.
   *
   * @param userId The user's id
   * @param force If <code>true</code>, forces a reload. If <code>false</code>, the call will be
   *     ignored if the roles are already loaded.
   * @see SecurityRepository#load(int)
   * @see SecurityRepository#load(User)
   * @see SecurityRepository#load(User, boolean)
   * @return PermissionControl
   */
  public static PermissionControl load(int userId, boolean force) {
    if (force || cache.get(FQN, Integer.toString(userId)) == null) {
      UserDAO um = DataAccessDriver.getInstance().newUserDAO();

      return SecurityRepository.load(um.selectById(userId), force);
    }

    return SecurityRepository.get(userId);
  }
예제 #2
0
  /**
   * Gets the permssion schema of some specific user. If the roles of the user aren't loaded yet, a
   * call to {@link #load(int)} will be made.
   *
   * @param userId The user's id to get the permissions
   * @return The <code>PermissionControl</code> instance related to the user id passed as argument
   * @throws SecurityLoadException if case of erros while trying to load the roles
   */
  public static PermissionControl get(int userId) {
    PermissionControl pc = (PermissionControl) cache.get(FQN, Integer.toString(userId));

    if (pc == null) {
      try {
        pc = load(userId);
      } catch (Exception e) {
        throw new SecurityLoadException(e);
      }
    }

    return pc;
  }
예제 #3
0
  public static List getSmilies() {
    List list = (List) cache.get(FQN, ENTRIES);
    if (!contexted) {
      String forumLink = SystemGlobals.getValue(ConfigKeys.FORUM_LINK);

      for (Iterator iter = list.iterator(); iter.hasNext(); ) {
        Smilie s = (Smilie) iter.next();
        s.setUrl(s.getUrl().replaceAll("#CONTEXT#", forumLink).replaceAll("\\\\", ""));
      }

      cache.add(FQN, ENTRIES, list);
      contexted = true;
    }

    return list;
  }
예제 #4
0
  /**
   * Load user's roles.
   *
   * @param user The <code>User</code> to load
   * @param force If <code>true</code>, forces a reload. If <code>false</code>, the call will be
   *     ignored if the roles are already loaded.
   * @see SecurityRepository#load(int)
   * @see SecurityRepository#load(int, boolean)
   * @see SecurityRepository#load(User)
   * @return PermissionControl
   */
  public static PermissionControl load(User user, boolean force) {
    String userId = Integer.toString(user.getId());

    if (force || cache.get(FQN, userId) == null) {
      PermissionControl pc = new PermissionControl();

      // load roles
      GroupSecurityDAO dao = DataAccessDriver.getInstance().newGroupSecurityDAO();
      pc.setRoles(dao.loadRolesByUserGroups(user));

      cache.add(FQN, userId, pc);

      return pc;
    }

    return SecurityRepository.get(user.getId());
  }