use of net.jforum.security.RoleCollection in project jforum2 by rafaelsteil.
the class GenericGroupSecurityDAO method loadRoles.
protected RoleCollection loadRoles(int[] groupIds) {
String sql = SystemGlobals.getSql("PermissionControl.loadGroupRoles");
String groupIdAsString = SecurityCommon.groupIdAsString(groupIds);
if ("".equals(groupIdAsString)) {
// We suppose there is no "negative" group ids
sql = sql.replaceAll("#IN#", "-1");
} else {
sql = sql.replaceAll("#IN#", groupIdAsString);
}
RoleCollection roles = new RoleCollection();
PreparedStatement p = null;
ResultSet rs = null;
try {
p = JForumExecutionContext.getConnection().prepareStatement(sql);
rs = p.executeQuery();
roles = SecurityCommon.loadRoles(rs);
} catch (Exception e) {
throw new DatabaseException(e);
} finally {
DbUtils.close(rs, p);
}
return roles;
}
use of net.jforum.security.RoleCollection in project jforum2 by rafaelsteil.
the class MySQL323GroupSecurityDAO method loadRoles.
/**
* @see net.jforum.dao.generic.security.GenericGroupSecurityDAO#loadRoles(int[])
*/
protected RoleCollection loadRoles(int[] groupIds) {
String groupIdAsString = SecurityCommon.groupIdAsString(groupIds);
RoleCollection roleCollection = new RoleCollection();
PreparedStatement rolesP = null;
PreparedStatement roleValuesP = null;
ResultSet roles = null;
ResultSet roleValues = null;
try {
// Roles
String sql = this.sqlWithGroups("PermissionControl.getRoles", groupIdAsString);
rolesP = JForumExecutionContext.getConnection().prepareStatement(sql);
roles = rolesP.executeQuery();
// RoleValues
sql = this.sqlWithGroups("PermissionControl.getRoleValues", groupIdAsString);
roleValuesP = JForumExecutionContext.getConnection().prepareStatement(sql);
roleValues = roleValuesP.executeQuery();
MySQL323RoleResultSet mergedRs = new MySQL323RoleResultSet(0, 0, null, null);
mergedRs.merge(roles, roleValues);
roleCollection = SecurityCommon.loadRoles(mergedRs);
} catch (Exception e) {
throw new DatabaseException(e);
} finally {
DbUtils.close(roles, rolesP);
DbUtils.close(roleValues, roleValuesP);
}
return roleCollection;
}
use of net.jforum.security.RoleCollection in project jforum2 by rafaelsteil.
the class GenericGroupSecurityDAO method loadRolesByUserGroups.
/**
* @see net.jforum.dao.GroupSecurityDAO#loadRolesByUserGroups(net.jforum.entities.User)
*/
public RoleCollection loadRolesByUserGroups(User user) {
List groups = user.getGroupsList();
// When the user is associated to more than one group, we
// should check the merged roles
int[] groupIds = this.getSortedGroupIds(groups);
RoleCollection groupRoles = RolesRepository.getGroupRoles(groupIds);
// Not cached yet? then do it now
if (groupRoles == null) {
groupRoles = this.loadRoles(groupIds);
RolesRepository.addGroupRoles(groupIds, groupRoles);
}
return groupRoles;
}
use of net.jforum.security.RoleCollection 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);
}
}
Aggregations