Search in sources :

Example 1 with RoleCollection

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;
}
Also used : ResultSet(java.sql.ResultSet) RoleCollection(net.jforum.security.RoleCollection) PreparedStatement(java.sql.PreparedStatement) DatabaseException(net.jforum.exceptions.DatabaseException) DatabaseException(net.jforum.exceptions.DatabaseException) SQLException(java.sql.SQLException)

Example 2 with RoleCollection

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;
}
Also used : ResultSet(java.sql.ResultSet) RoleCollection(net.jforum.security.RoleCollection) PreparedStatement(java.sql.PreparedStatement) DatabaseException(net.jforum.exceptions.DatabaseException) DatabaseException(net.jforum.exceptions.DatabaseException) SQLException(java.sql.SQLException)

Example 3 with 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;
}
Also used : ArrayList(java.util.ArrayList) List(java.util.List) RoleCollection(net.jforum.security.RoleCollection)

Example 4 with RoleCollection

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

Aggregations

RoleCollection (net.jforum.security.RoleCollection)4 SQLException (java.sql.SQLException)3 DatabaseException (net.jforum.exceptions.DatabaseException)3 PreparedStatement (java.sql.PreparedStatement)2 ResultSet (java.sql.ResultSet)2 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Role (net.jforum.security.Role)1 RoleValue (net.jforum.security.RoleValue)1