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

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


                }
            } finally {
                Database.dispose(ps);
            }

            UserSecurity security = new UserSecurity(userProfileId, superAdmin);
            List<RoleSecurity> roles = new ArrayList<RoleSecurity>();
            Map<Long, RoleSecurity> roleIds = new HashMap<Long, RoleSecurity>();

            try {
                // select the roles;
                ps =
                        conn.prepareStatement("SELECT role_id, name, description FROM role " + "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 = 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);
            }

            for (RoleSecurity role : roles) {
                security.importRole(role);
            }

            return security;

        } catch (SQLException e) {
View Full Code Here


            return this.handleFailure(mapping, context, messages, "nopermission");
        }

        context.setAttribute("contest", contest);
        // check contest permission
        UserSecurity userSecurity = context.getUserSecurity();
        boolean hasPermisstion = false;
        if (level == PermissionLevel.ADMIN) {
            hasPermisstion = userSecurity.canAdminContest(contest.getId());
        } else if (level == PermissionLevel.PARTICIPATE) {
            hasPermisstion = userSecurity.canParticipateContest(contest.getId());
        } else if (level == PermissionLevel.VIEW) {
            hasPermisstion = userSecurity.canViewContest(contest.getId());
        } else if (level == PermissionLevel.PARTICIPATECANVIEWSOURCE) {
            hasPermisstion = userSecurity.canViewSource(contest.getId());
        }
        if (!hasPermisstion) {
            ActionMessages messages = new ActionMessages();
            messages.add("message", new ActionMessage("onlinejudge.showcontest.nopermission"));
            this.saveErrors(context.getRequest(), messages);
            if (isProblemset != null) {
                context.setAttribute("back", isProblemset ? "showProblemsets.do" : "showContests.do");
            }
            return this.handleFailure(mapping, context, messages, "nopermission");
        }

        // check start time
        if (checkStart && !userSecurity.canAdminContest(contest.getId())) {
            return this.checkContestStart(mapping, context, contest);
        }
        return null;
    }
View Full Code Here

        context.setAttribute("contest", contest);
        context.setAttribute("problem", problem);

        // check contest permission
        UserSecurity userSecurity = context.getUserSecurity();
        boolean hasPermisstion = false;
        if (level == PermissionLevel.ADMIN) {
            hasPermisstion = userSecurity.canAdminContest(contest.getId());
        } else if (level == PermissionLevel.PARTICIPATE) {
            hasPermisstion = userSecurity.canParticipateContest(contest.getId());
        } else if (level == PermissionLevel.PARTICIPATECANVIEWSOURCE) {
            hasPermisstion = userSecurity.canViewSource(contest.getId());
        } else if (level == PermissionLevel.VIEW) {
            hasPermisstion = userSecurity.canViewContest(contest.getId());
        }
        if (!hasPermisstion) {
            ActionMessages messages = new ActionMessages();
            messages.add("message", new ActionMessage("onlinejudge.showcontest.nopermission"));
            this.saveErrors(context.getRequest(), messages);
            if (isProblemset != null) {
                context.setAttribute("back", isProblemset ? "showProblemsets.do" : "showContests.do");
            }
            return this.handleFailure(mapping, context, messages, "nopermission");
        }

        // check start time
        if (userSecurity.canAdminContest(contest.getId())) {
            return null;
        } else {
            return this.checkContestStart(mapping, context, contest);
        }
View Full Code Here

        }
        return null;
    }

    protected ActionForward checkAdmin(ActionMapping mapping, ContextAdapter context) throws Exception {
        UserSecurity security = context.getUserSecurity();
        if (security == null || !security.isSuperAdmin()) {
            return this.handleSuccess(mapping, context, "nopermission");
        }
        return null;
    }
View Full Code Here

        context.getRequest().setAttribute("Countries",
                                          PersistenceManager.getInstance().getUserPersistence().getAllCountries());

        // get UserSecurity
        UserSecurity security = authorizationPersistence.getUserSecurity(profile.getId());

        context.setUserProfile(profile);
        context.setUserSecurity(security);
        context.setUserPreference(perference);
View Full Code Here

    protected List<AbstractContest> getAllCourses() throws PersistenceException {
        return this.getCheckedContests(ContestManager.getInstance().getAllCourses());
    }

    protected List<AbstractContest> getCheckedContests(List<AbstractContest> contests) throws PersistenceException {
        UserSecurity userSecurity = this.getUserSecurity();

        List<AbstractContest> ret = new ArrayList<AbstractContest>();
        for (AbstractContest contest : contests) {
            if (userSecurity.canViewContest(contest.getId())) {
                ret.add(contest);
            }
        }
        return ret;
    }
View Full Code Here

    public UserSecurity getDefaultUserSecurity() throws PersistenceException {
        if (ContextAdapter.defaultUserSecurity == null) {
            synchronized (this) {
                if (ContextAdapter.defaultUserSecurity == null) {
                    ContextAdapter.defaultUserSecurity = new UserSecurity(0);
                    ContextAdapter.defaultUserSecurity.importRole(PersistenceManager.getInstance()
                                                                                    .getAuthorizationPersistence()
                                                                                    .getRole(1));
                }
            }
View Full Code Here

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

        // get UserSecurity
        UserSecurity security = authorizationPersistence.getUserSecurity(profile.getId());

        // get UserPreference
        UserPreference perference = userPersistence.getUserPreference(profile.getId());

        context.setUserProfile(profile);
        context.setUserSecurity(security);
        if(context.getAllCourses().size()!=0) {
          security.setHasCourses(true);
        } else {
          security.setHasCourses(false);
        }
        context.setUserPreference(perference);

        return errors;
View Full Code Here

                    if (profile != null && profile.isActive()) {

                        AuthorizationPersistence authorizationPersistence =
                                PersistenceManager.getInstance().getAuthorizationPersistence();
                        // get UserSecurity
                        UserSecurity security = authorizationPersistence.getUserSecurity(profile.getId());
                        // get UserPreference
                        UserPreference perference = userPersistence.getUserPreference(profile.getId());
                        r.getSession().setAttribute(ContextAdapter.USER_PROFILE_SESSION_KEY, profile);
                        r.getSession().setAttribute(ContextAdapter.SECURITY_SESSION_KEY, security);
                        r.getSession().setAttribute(ContextAdapter.PREFERENCE_SESSION_KEY, perference);
View Full Code Here

TOP

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

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.