Package cn.edu.zju.acm.onlinejudge.security

Examples of cn.edu.zju.acm.onlinejudge.security.RoleSecurity


        AuthorizationPersistence authorizationPersistence =
                PersistenceManager.getInstance().getAuthorizationPersistence();

        if (roleForm.getId() == null || roleForm.getId().trim().length() == 0) {
            long roleId = Utility.parseLong(context.getRequest().getParameter("roleId"));
            RoleSecurity role = authorizationPersistence.getRole(roleId);
            if (role == null) {
                return this.handleSuccess(mapping, context, "success");
            }

            // add contest names
            Map<Long, String> contestNames = new TreeMap<Long, String>();
            for (AbstractContest contest : ContestManager.getInstance().getAllContests()) {
                contestNames.put(contest.getId(), contest.getTitle());
            }
            for (AbstractContest contest : ContestManager.getInstance().getAllProblemsets()) {
                contestNames.put(contest.getId(), contest.getTitle());
            }
            for (AbstractContest contest : ContestManager.getInstance().getAllCourses()) {
                contestNames.put(contest.getId(), contest.getTitle());
            }
            context.setAttribute("ContestNames", contestNames);

            // TODO add forums
            Map<Long, String> forumNames = new TreeMap<Long, String>();
            forumNames.put(1L, "ZOJ Forum");
            context.setAttribute("ForumNames", forumNames);

            roleForm.populate(role);
            return this.handleSuccess(mapping, context, "failure");
        }

        RoleSecurity role = roleForm.toRole();
        authorizationPersistence.updateRole(role, context.getUserProfile().getId());

        if (role.getId() == 1) {
            ContextAdapter.resetDefaultUserSecurity();
        }
        return this.handleSuccess(mapping, context, "success");
    }
View Full Code Here


        }
        String description = context.getRequest().getParameter("description");
        if (description == null) {
            description = "";
        }
        RoleSecurity role = new RoleSecurity(-1, name, description);

        AuthorizationPersistence ap = PersistenceManager.getInstance().getAuthorizationPersistence();
        ap.createRole(role, context.getUserProfile().getId());

        return this.handleSuccess(mapping, context, "success");
View Full Code Here

        Connection conn = null;
        try {
            conn = Database.createConnection();
            PreparedStatement ps = null;
            ResultSet rs = null;
            RoleSecurity role;
            try {
                ps = conn.prepareStatement("SELECT role_id, name, description FROM role WHERE role_id=?");
                ps.setLong(1, id);
                rs = ps.executeQuery();
                if (!rs.next()) {
                    return null;
                }
                role = new RoleSecurity(rs.getLong(1), rs.getString(2), rs.getString(3));
            } finally {
                Database.dispose(ps);
            }
            try {
                // select the contest permissions
                ps =
                        conn
                            .prepareStatement("SELECT role_id, contest_id, permission_level_id FROM contest_permission WHERE role_id=?");
                ps.setLong(1, id);
                rs = ps.executeQuery();
                while (rs.next()) {
                    role.getContestPermission().addPermission(rs.getLong(2), PermissionLevel.findById(rs.getLong(3)));
                }
            } finally {
                Database.dispose(ps);
            }
            try {
                // select the forum permissions
                ps =
                        conn
                            .prepareStatement("SELECT role_id, forum_id, permission_level_id FROM forum_permission WHERE role_id=?");
                ps.setLong(1, id);
                rs = ps.executeQuery();
                while (rs.next()) {
                    role.getForumPermission().addPermission(rs.getLong(2), PermissionLevel.findById(rs.getLong(3)));
                }
            } finally {
                Database.dispose(ps);
            }
            return role;
View Full Code Here

                ps.setLong(1, contestId);
                ResultSet rs = ps.executeQuery();

                List<RoleSecurity> roles = new ArrayList<RoleSecurity>();
                while (rs.next()) {
                    RoleSecurity role = new RoleSecurity(rs.getLong(1), rs.getString(2), rs.getString(3));
                    roles.add(role);
                }
                return roles;
            } finally {
                Database.dispose(ps);
View Full Code Here

            try {
                // select the roles;
                ps = conn.prepareStatement("SELECT role_id, name, description FROM role");
                rs = ps.executeQuery();
                while (rs.next()) {
                    RoleSecurity role = new RoleSecurity(rs.getLong(1), rs.getString(2), rs.getString(3));
                    roles.add(role);
                    roleIds.put(role.getId(), role);
                }
            } finally {
                Database.dispose(ps);
            }
            try {
                // select the contests permissions
                ps = conn.prepareStatement("SELECT role_id, contest_id, permission_level_id FROM contest_permission");
                rs = ps.executeQuery();
                while (rs.next()) {
                    RoleSecurity role = roleIds.get(rs.getLong(1));
                    role.getContestPermission().addPermission(rs.getLong(2), PermissionLevel.findById(rs.getLong(3)));
                }
            } finally {
                Database.dispose(ps);
            }
            try {
                // select the forum permissions
                ps = conn.prepareStatement("SELECT role_id, forum_id, permission_level_id FROM forum_permission");
                rs = ps.executeQuery();
                while (rs.next()) {
                    RoleSecurity role = roleIds.get(rs.getLong(1));
                    role.getForumPermission().addPermission(rs.getLong(2), PermissionLevel.findById(rs.getLong(3)));
                }
            } finally {
                Database.dispose(ps);
            }
            return roles;
View Full Code Here

                            + "(SELECT role_id from user_role WHERE user_profile_id = ?)");
                ps.setLong(1, userProfileId);
                rs = ps.executeQuery();

                while (rs.next()) {
                    RoleSecurity role = new RoleSecurity(rs.getLong(1), rs.getString(2), rs.getString(3));
                    roles.add(role);
                    roleIds.put(role.getId(), role);
                }
            } finally {
                Database.dispose(ps);
            }

            try {
                // select the contests permissions
                ps =
                        conn
                            .prepareStatement("SELECT role_id, contest_id, permission_level_id FROM contest_permission "
                                + "WHERE role_id IN " + "(SELECT role_id from user_role WHERE user_profile_id = ?)");
                ps.setLong(1, userProfileId);
                rs = ps.executeQuery();

                while (rs.next()) {
                    RoleSecurity role = roleIds.get(rs.getLong(1));
                    role.getContestPermission().addPermission(rs.getLong(2), PermissionLevel.findById(rs.getLong(3)));
                }
            } finally {
                Database.dispose(ps);
            }

            try {
                // select the forum permissions
                ps =
                        conn.prepareStatement("SELECT role_id, forum_id, permission_level_id FROM forum_permission "
                            + "WHERE role_id IN " + "(SELECT role_id from user_role WHERE user_profile_id = ?)");
                ps.setLong(1, userProfileId);
                rs = ps.executeQuery();
                while (rs.next()) {
                    RoleSecurity role = roleIds.get(rs.getLong(1));
                    role.getForumPermission().addPermission(rs.getLong(2), PermissionLevel.findById(rs.getLong(3)));
                }
            } finally {
                Database.dispose(ps);
            }
View Full Code Here

        ActionForward forward = this.checkAdmin(mapping, context);
        if (forward != null) {
            return forward;
        }
        long roleId = Utility.parseLong(context.getRequest().getParameter("roleId"));
        RoleSecurity role = null;
        AuthorizationPersistence authorizationPersistence =
                PersistenceManager.getInstance().getAuthorizationPersistence();
        if (roleId >= 0) {
            role = authorizationPersistence.getRole(roleId);
        }
View Full Code Here

        }
        return errors;
    }

    public RoleSecurity toRole() {
        RoleSecurity role = new RoleSecurity(Utility.parseLong(this.id), this.name, this.description);
        if (this.selectedContestIds != null) {
            for (int i = 0; i < this.selectedContestIds.length; ++i) {
                role.getContestPermission()
                    .addPermission(Utility.parseLong(this.selectedContestIds[i]),
                                   PermissionLevel.findById(Utility.parseLong(this.contestPermissions[i])));
            }
        }
        if (this.selectedForumIds != null) {
            for (int i = 0; i < this.selectedForumIds.length; ++i) {
                role.getForumPermission()
                    .addPermission(Utility.parseLong(this.selectedForumIds[i]),
                                   PermissionLevel.findById(Utility.parseLong(this.forumPermissions[i])));
            }
        }
        return role;
View Full Code Here

TOP

Related Classes of cn.edu.zju.acm.onlinejudge.security.RoleSecurity

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.