Search in sources :

Example 1 with RoleValueCollection

use of net.jforum.security.RoleValueCollection 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 2 with RoleValueCollection

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

the class ForumAction method addRole.

private void addRole(PermissionControl pc, String roleName, int forumId, String[] groups) {
    Role role = new Role();
    role.setName(roleName);
    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(forumId));
        roleValues.add(rv);
        pc.addRoleValue(groupId, role, roleValues);
    }
}
Also used : Role(net.jforum.security.Role) RoleValue(net.jforum.security.RoleValue) RoleValueCollection(net.jforum.security.RoleValueCollection)

Example 3 with RoleValueCollection

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

the class PermissionProcessHelper method processData.

public void processData() {
    RequestContext request = JForumExecutionContext.getRequest();
    Enumeration e = request.getParameterNames();
    while (e.hasMoreElements()) {
        String paramName = (String) e.nextElement();
        if (paramName.startsWith("perm_")) {
            if (paramName.endsWith("$single")) {
                String paramValue = request.getParameter(paramName);
                if (paramValue.equals("deny")) {
                    continue;
                }
                paramName = paramName.substring(0, paramName.indexOf('$'));
                Role role = new Role();
                role.setName(paramName);
                this.pc.addRole(this.groupId, role);
            } else {
                String[] paramValues = request.getParameterValues(paramName);
                RoleValueCollection roleValues = new RoleValueCollection();
                if ("all".equals(paramValues[0])) {
                    this.addRoleValues(roleValues, this.getSplitedValues("all" + paramName));
                } else {
                    List allowList = new ArrayList(Arrays.asList(this.getSplitedValues("all" + paramName)));
                    allowList.removeAll(Arrays.asList(paramValues));
                    this.addRoleValues(roleValues, allowList.toArray());
                }
                Role role = new Role();
                role.setName(paramName);
                this.pc.addRole(this.groupId, role, roleValues);
            }
        }
    }
}
Also used : Role(net.jforum.security.Role) Enumeration(java.util.Enumeration) ArrayList(java.util.ArrayList) RoleValueCollection(net.jforum.security.RoleValueCollection) List(java.util.List) ArrayList(java.util.ArrayList) RequestContext(net.jforum.context.RequestContext)

Aggregations

Role (net.jforum.security.Role)3 RoleValueCollection (net.jforum.security.RoleValueCollection)3 RoleValue (net.jforum.security.RoleValue)2 ArrayList (java.util.ArrayList)1 Enumeration (java.util.Enumeration)1 List (java.util.List)1 RequestContext (net.jforum.context.RequestContext)1 GroupSecurityDAO (net.jforum.dao.GroupSecurityDAO)1 Category (net.jforum.entities.Category)1 PermissionControl (net.jforum.security.PermissionControl)1