Search in sources :

Example 6 with PermissionControl

use of net.jforum.security.PermissionControl in project jforum2 by rafaelsteil.

the class Category method getForums.

/**
 * Gets all forums from this category.
 *
 * @return The forums available to the user who make the call
 * @see #getForums()
 * @param userId int
 */
public Collection getForums(int userId) {
    PermissionControl pc = SecurityRepository.get(userId);
    List forums = new ArrayList();
    for (Iterator iter = this.forums.iterator(); iter.hasNext(); ) {
        Forum f = (Forum) iter.next();
        if (pc.canAccess(SecurityConstants.PERM_FORUM, Integer.toString(f.getId()))) {
            forums.add(f);
        }
    }
    return forums;
}
Also used : PermissionControl(net.jforum.security.PermissionControl) ArrayList(java.util.ArrayList) Iterator(java.util.Iterator) ArrayList(java.util.ArrayList) List(java.util.List)

Example 7 with PermissionControl

use of net.jforum.security.PermissionControl in project jforum2 by rafaelsteil.

the class CategoryAction method insertSave.

// A new one
public void insertSave() {
    Category c = new Category();
    c.setName(this.request.getParameter("category_name"));
    c.setModerated("1".equals(this.request.getParameter("moderated")));
    int categoryId = this.cm.addNew(c);
    c.setId(categoryId);
    ForumRepository.addCategory(c);
    String[] groups = this.request.getParameterValues("groups");
    if (groups != null) {
        GroupSecurityDAO gmodel = DataAccessDriver.getInstance().newGroupSecurityDAO();
        PermissionControl pc = new PermissionControl();
        pc.setSecurityModel(gmodel);
        Role role = new Role();
        role.setName(SecurityConstants.PERM_CATEGORY);
        for (int i = 0; i < groups.length; i++) {
            int groupId = Integer.parseInt(groups[i]);
            RoleValueCollection roleValues = new RoleValueCollection();
            RoleValue rv = new RoleValue();
            rv.setValue(Integer.toString(categoryId));
            roleValues.add(rv);
            pc.addRoleValue(groupId, role, roleValues);
        }
        SecurityRepository.clean();
        RolesRepository.clear();
    }
    this.list();
}
Also used : Role(net.jforum.security.Role) Category(net.jforum.entities.Category) PermissionControl(net.jforum.security.PermissionControl) RoleValue(net.jforum.security.RoleValue) RoleValueCollection(net.jforum.security.RoleValueCollection) GroupSecurityDAO(net.jforum.dao.GroupSecurityDAO)

Example 8 with PermissionControl

use of net.jforum.security.PermissionControl in project jforum2 by rafaelsteil.

the class GroupAction method permissions.

// Permissions
public void permissions() {
    int id = this.request.getIntParameter("group_id");
    PermissionControl pc = new PermissionControl();
    pc.setRoles(DataAccessDriver.getInstance().newGroupSecurityDAO().loadRoles(id));
    String xmlconfig = SystemGlobals.getValue(ConfigKeys.CONFIG_DIR) + "/permissions.xml";
    List sections = new XMLPermissionControl(pc).loadConfigurations(xmlconfig);
    GroupDAO gm = DataAccessDriver.getInstance().newGroupDAO();
    this.context.put("sections", sections);
    this.context.put("group", gm.selectById(id));
    this.setTemplateName(TemplateKeys.GROUP_PERMISSIONS);
}
Also used : XMLPermissionControl(net.jforum.security.XMLPermissionControl) PermissionControl(net.jforum.security.PermissionControl) ArrayList(java.util.ArrayList) List(java.util.List) GroupDAO(net.jforum.dao.GroupDAO) XMLPermissionControl(net.jforum.security.XMLPermissionControl)

Example 9 with PermissionControl

use of net.jforum.security.PermissionControl in project jforum2 by rafaelsteil.

the class ForumRepository method getAllCategories.

/**
 * Gets all categories from the cache.
 *
 * @param userId int
 * @return <code>List</code> with the categories. Each entry is a <code>Category</code> object.
 */
public static List getAllCategories(int userId) {
    PermissionControl pc = SecurityRepository.get(userId);
    List l = new ArrayList();
    Set categoriesSet = (Set) cache.get(FQN, CATEGORIES_SET);
    if (categoriesSet == null) {
        synchronized (ForumRepository.instance) {
            if (categoriesSet == null) {
                logger.warn("Categories set returned null from the cache. Trying to reload");
                try {
                    ForumRepository.instance.loadCategories(DataAccessDriver.getInstance().newCategoryDAO());
                    ForumRepository.instance.loadForums(DataAccessDriver.getInstance().newForumDAO());
                } catch (Exception e) {
                    throw new CategoryNotFoundException("Failed to get the category", e);
                }
                categoriesSet = (Set) cache.get(FQN, CATEGORIES_SET);
                if (categoriesSet == null) {
                    throw new CategoryNotFoundException("Could not find all categories. There must be a problem with the cache");
                }
            }
        }
    }
    for (Iterator iter = categoriesSet.iterator(); iter.hasNext(); ) {
        Category c = getCategory(pc, ((Category) iter.next()).getId());
        if (c != null) {
            l.add(c);
        }
    }
    return l;
}
Also used : TreeSet(java.util.TreeSet) Set(java.util.Set) Category(net.jforum.entities.Category) PermissionControl(net.jforum.security.PermissionControl) ArrayList(java.util.ArrayList) CategoryNotFoundException(net.jforum.exceptions.CategoryNotFoundException) Iterator(java.util.Iterator) ArrayList(java.util.ArrayList) List(java.util.List) DatabaseException(net.jforum.exceptions.DatabaseException) CategoryNotFoundException(net.jforum.exceptions.CategoryNotFoundException)

Example 10 with PermissionControl

use of net.jforum.security.PermissionControl in project jforum2 by rafaelsteil.

the class SecurityRepository method load.

/**
 * 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());
}
Also used : PermissionControl(net.jforum.security.PermissionControl) GroupSecurityDAO(net.jforum.dao.GroupSecurityDAO)

Aggregations

PermissionControl (net.jforum.security.PermissionControl)11 List (java.util.List)4 GroupSecurityDAO (net.jforum.dao.GroupSecurityDAO)4 ArrayList (java.util.ArrayList)3 Iterator (java.util.Iterator)3 Forum (net.jforum.entities.Forum)3 UserSession (net.jforum.entities.UserSession)3 PollDAO (net.jforum.dao.PollDAO)2 PostDAO (net.jforum.dao.PostDAO)2 TopicDAO (net.jforum.dao.TopicDAO)2 Category (net.jforum.entities.Category)2 Poll (net.jforum.entities.Poll)2 Topic (net.jforum.entities.Topic)2 XMLPermissionControl (net.jforum.security.XMLPermissionControl)2 AttachmentCommon (net.jforum.view.forum.common.AttachmentCommon)2 SimpleHash (freemarker.template.SimpleHash)1 SimpleDateFormat (java.text.SimpleDateFormat)1 Date (java.util.Date)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1