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;
}
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();
}
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);
}
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;
}
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());
}
Aggregations