Search in sources :

Example 1 with GroupSecurityDAO

use of net.jforum.dao.GroupSecurityDAO in project jforum2 by rafaelsteil.

the class GenericGroupDAO method delete.

/**
	 * @see net.jforum.dao.GroupDAO#delete(int)
	 */
public void delete(int groupId) {
    PreparedStatement p = null;
    try {
        p = JForumExecutionContext.getConnection().prepareStatement(SystemGlobals.getSql("GroupModel.delete"));
        p.setInt(1, groupId);
        p.executeUpdate();
        GroupSecurityDAO securityDao = DataAccessDriver.getInstance().newGroupSecurityDAO();
        securityDao.deleteAllRoles(groupId);
    } catch (SQLException e) {
        throw new DatabaseException(e);
    } finally {
        DbUtils.close(p);
    }
}
Also used : SQLException(java.sql.SQLException) PreparedStatement(java.sql.PreparedStatement) DatabaseException(net.jforum.exceptions.DatabaseException) GroupSecurityDAO(net.jforum.dao.GroupSecurityDAO)

Example 2 with GroupSecurityDAO

use of net.jforum.dao.GroupSecurityDAO in project jforum2 by rafaelsteil.

the class GroupAction method permissionsSave.

public void permissionsSave() {
    int id = this.request.getIntParameter("id");
    GroupSecurityDAO gmodel = DataAccessDriver.getInstance().newGroupSecurityDAO();
    PermissionControl pc = new PermissionControl();
    pc.setSecurityModel(gmodel);
    new PermissionProcessHelper(pc, id).processData();
    SecurityRepository.clean();
    RolesRepository.clear();
    ForumRepository.clearModeratorList();
    this.list();
}
Also used : XMLPermissionControl(net.jforum.security.XMLPermissionControl) PermissionControl(net.jforum.security.PermissionControl) GroupSecurityDAO(net.jforum.dao.GroupSecurityDAO)

Example 3 with GroupSecurityDAO

use of net.jforum.dao.GroupSecurityDAO in project jforum2 by rafaelsteil.

the class SecurityRepository method load.

/**
	 * Load user's roles.
	 * 
	 * @param user The <code>User</code> to load
	 * @param force If <code>true</code>, forces a reload. If <code>false</code>, the call
	 * will be ignored if the roles are already loaded.
	 * 
	 * @see SecurityRepository#load(int)
	 * @see SecurityRepository#load(int, boolean)
	 * @see SecurityRepository#load(User)
     * @return PermissionControl
	 */
public static PermissionControl load(User user, boolean force) {
    String userId = Integer.toString(user.getId());
    if (force || cache.get(FQN, userId) == null) {
        PermissionControl pc = new PermissionControl();
        // load roles
        GroupSecurityDAO dao = DataAccessDriver.getInstance().newGroupSecurityDAO();
        pc.setRoles(dao.loadRolesByUserGroups(user));
        cache.add(FQN, userId, pc);
        return pc;
    }
    return SecurityRepository.get(user.getId());
}
Also used : PermissionControl(net.jforum.security.PermissionControl) GroupSecurityDAO(net.jforum.dao.GroupSecurityDAO)

Example 4 with GroupSecurityDAO

use of net.jforum.dao.GroupSecurityDAO in project jforum2 by rafaelsteil.

the class GenericForumDAO method delete.

/**
	 * @see net.jforum.dao.ForumDAO#delete(int)
	 */
public void delete(int forumId) {
    PreparedStatement p = null;
    try {
        p = JForumExecutionContext.getConnection().prepareStatement(SystemGlobals.getSql("ForumModel.delete"));
        p.setInt(1, forumId);
        p.executeUpdate();
        GroupSecurityDAO groupSecurity = DataAccessDriver.getInstance().newGroupSecurityDAO();
        groupSecurity.deleteForumRoles(forumId);
    } catch (SQLException e) {
        throw new DatabaseException(e);
    } finally {
        DbUtils.close(p);
    }
}
Also used : SQLException(java.sql.SQLException) PreparedStatement(java.sql.PreparedStatement) DatabaseException(net.jforum.exceptions.DatabaseException) GroupSecurityDAO(net.jforum.dao.GroupSecurityDAO)

Example 5 with GroupSecurityDAO

use of net.jforum.dao.GroupSecurityDAO 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)

Aggregations

GroupSecurityDAO (net.jforum.dao.GroupSecurityDAO)6 PermissionControl (net.jforum.security.PermissionControl)4 PreparedStatement (java.sql.PreparedStatement)2 SQLException (java.sql.SQLException)2 DatabaseException (net.jforum.exceptions.DatabaseException)2 Category (net.jforum.entities.Category)1 Forum (net.jforum.entities.Forum)1 Role (net.jforum.security.Role)1 RoleValue (net.jforum.security.RoleValue)1 RoleValueCollection (net.jforum.security.RoleValueCollection)1 XMLPermissionControl (net.jforum.security.XMLPermissionControl)1