Search in sources :

Example 1 with Role

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

the class SecurityCommon method loadRoles.

/**
	 * See {@link PermissionControl#executeAddRole(String, int, String, RoleValueCollection)} for
	 * explanation about this method. The working way is the same.
	 * 
	 * @param rs The ResultSet containing the data to be fetched. This method does not
	 * free the resultset after it finished using it, so it's responsability of the 
	 * caller to do such task.
	 * @return A <code>RoleCollection</code> collection with the roles processed.
	 */
public static RoleCollection loadRoles(ResultSet rs) {
    RoleCollection rc = new RoleCollection();
    try {
        Role r = null;
        String lastName = null;
        while (rs.next()) {
            String currentName = rs.getString("name");
            if (!currentName.equals(lastName)) {
                if (r != null) {
                    rc.add(r);
                }
                r = new Role();
                r.setName(rs.getString("name"));
                lastName = currentName;
            }
            String roleValue = rs.getString("role_value");
            if (!rs.wasNull() && StringUtils.isNotBlank(roleValue)) {
                r.getValues().add(new RoleValue(roleValue));
            }
        }
        if (r != null) {
            rc.add(r);
        }
        return rc;
    } catch (SQLException e) {
        throw new DatabaseException(e);
    }
}
Also used : Role(net.jforum.security.Role) SQLException(java.sql.SQLException) RoleValue(net.jforum.security.RoleValue) RoleCollection(net.jforum.security.RoleCollection) DatabaseException(net.jforum.exceptions.DatabaseException)

Example 2 with Role

use of net.jforum.security.Role 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 3 with Role

use of net.jforum.security.Role 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 4 with Role

use of net.jforum.security.Role 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)4 RoleValue (net.jforum.security.RoleValue)3 RoleValueCollection (net.jforum.security.RoleValueCollection)3 SQLException (java.sql.SQLException)1 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 DatabaseException (net.jforum.exceptions.DatabaseException)1 PermissionControl (net.jforum.security.PermissionControl)1 RoleCollection (net.jforum.security.RoleCollection)1