コード例 #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()));
  }
コード例 #2
0
ファイル: SecurityRepository.java プロジェクト: pinke/trydone
  /**
   * * 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);
  }
コード例 #3
0
ファイル: SecurityRepository.java プロジェクト: pinke/trydone
  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));
  }
コード例 #4
0
ファイル: SecurityRepository.java プロジェクト: pinke/trydone
  /**
   * 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());
  }
コード例 #5
0
ファイル: SecurityRepository.java プロジェクト: pinke/trydone
 /**
  * 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);
 }
コード例 #6
0
ファイル: SecurityRepository.java プロジェクト: pinke/trydone
 /**
  * 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);
 }