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