Exemplo n.º 1
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;
  }
Exemplo n.º 2
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());
  }
Exemplo n.º 3
0
 public static void loadSmilies() {
   try {
     cache.add(FQN, ENTRIES, DataAccessDriver.getInstance().newSmilieDAO().selectAll());
     contexted = false;
   } catch (Exception e) {
     throw new SmiliesLoadException("Error while loading smilies: " + e);
   }
 }
Exemplo n.º 4
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);
  }
Exemplo n.º 5
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;
  }
Exemplo n.º 6
0
 /** Clear all cached security entries. */
 public static synchronized void clean() {
   cache.remove(FQN);
 }
Exemplo n.º 7
0
 /**
  * Remove the cached roles from a specific user.
  *
  * @param userId The id of the user to remove from the cache
  */
 public static synchronized void remove(int userId) {
   cache.remove(FQN, Integer.toString(userId));
 }
Exemplo n.º 8
0
 /**
  * Adds a new permission control schema to the cache
  *
  * @param userId The user's id to associate with the schema
  * @param pc The <code>PermissionControl</code> instance to add
  */
 public static synchronized void add(int userId, PermissionControl pc) {
   cache.add(FQN, Integer.toString(userId), pc);
 }