Exemplo n.º 1
0
  /**
   * Setup common variables used by almost all templates.
   *
   * @param context SimpleHash The context to use
   * @param jforumContext JForumContext
   */
  public void prepareTemplateContext(SimpleHash context, ForumContext jforumContext) {
    RequestContext request = JForumExecutionContext.getRequest();

    context.put("karmaEnabled", SecurityRepository.canAccess(SecurityConstants.PERM_KARMA_ENABLED));
    context.put("dateTimeFormat", SystemGlobals.getValue(ConfigKeys.DATE_TIME_FORMAT));
    context.put("autoLoginEnabled", SystemGlobals.getBoolValue(ConfigKeys.AUTO_LOGIN_ENABLED));
    context.put(
        "sso", ConfigKeys.TYPE_SSO.equals(SystemGlobals.getValue(ConfigKeys.AUTHENTICATION_TYPE)));
    context.put("contextPath", request.getContextPath());
    context.put("serverName", request.getServerName());
    context.put("templateName", SystemGlobals.getValue(ConfigKeys.TEMPLATE_DIR));
    context.put("extension", SystemGlobals.getValue(ConfigKeys.SERVLET_EXTENSION));
    context.put("serverPort", Integer.toString(request.getServerPort()));
    context.put("I18n", I18n.getInstance());
    context.put("version", SystemGlobals.getValue(ConfigKeys.VERSION));
    context.put("forumTitle", SystemGlobals.getValue(ConfigKeys.FORUM_PAGE_TITLE));
    context.put("pageTitle", SystemGlobals.getValue(ConfigKeys.FORUM_PAGE_TITLE));
    context.put("metaKeywords", SystemGlobals.getValue(ConfigKeys.FORUM_PAGE_METATAG_KEYWORDS));
    context.put(
        "metaDescription", SystemGlobals.getValue(ConfigKeys.FORUM_PAGE_METATAG_DESCRIPTION));
    context.put("forumLink", SystemGlobals.getValue(ConfigKeys.FORUM_LINK));
    context.put("homepageLink", SystemGlobals.getValue(ConfigKeys.HOMEPAGE_LINK));
    context.put("encoding", SystemGlobals.getValue(ConfigKeys.ENCODING));
    context.put(
        "bookmarksEnabled", SecurityRepository.canAccess(SecurityConstants.PERM_BOOKMARKS_ENABLED));
    context.put(
        "canAccessModerationLog",
        SecurityRepository.canAccess(SecurityConstants.PERM_MODERATION_LOG));
    context.put("JForumContext", jforumContext);
    context.put("timestamp", new Long(System.currentTimeMillis()));
  }
Exemplo n.º 2
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.º 3
0
  public static boolean canAccess(int userId, String roleName, String value) {
    PermissionControl pc = SecurityRepository.get(userId);

    if (pc == null) {
      throw new SecurityLoadException(
          "Failed to load security roles for userId "
              + userId
              + " (null PermissionControl returned). "
              + "roleName="
              + roleName
              + ", roleValue="
              + value);
    }

    return (value != null ? pc.canAccess(roleName, value) : pc.canAccess(roleName));
  }
Exemplo n.º 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());
  }
Exemplo n.º 5
0
 /**
  * Load user's roles.
  *
  * @param user The <code>User</code> to load.
  * @see SecurityRepository#load(int)
  * @see SecurityRepository#load(int, boolean),
  * @see SecurityRepository#load(User, boolean)
  * @return PermissionControl
  */
 public static PermissionControl load(User user) {
   return SecurityRepository.load(user, false);
 }
Exemplo n.º 6
0
 /**
  * Load user's roles.
  *
  * @param userId The users's id
  * @see SecurityRepository#load(int, boolean)
  * @see SecurityRepository#load(User)
  * @see SecurityRepository#load(User, boolean)
  * @return PermissionControl
  */
 public static PermissionControl load(int userId) {
   return SecurityRepository.load(userId, false);
 }