Package cn.edu.zju.acm.onlinejudge.persistence

Examples of cn.edu.zju.acm.onlinejudge.persistence.AuthorizationPersistence


        if (forward != null) {
            return forward;
        }

        RoleForm roleForm = (RoleForm) form;
        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


        ActionForward forward = this.checkAdmin(mapping, context);
        if (forward != null) {
            return forward;
        }

        AuthorizationPersistence authorizationPersistence =
                PersistenceManager.getInstance().getAuthorizationPersistence();
        List<RoleSecurity> roles = authorizationPersistence.getAllRoles();
        context.setAttribute("Roles", roles);

        return this.handleSuccess(mapping, context, "success");

    }
View Full Code Here

        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

        if (forward != null) {
            return forward;
        }

        long roleId = Utility.parseLong(context.getRequest().getParameter("roleId"));
        AuthorizationPersistence ap = PersistenceManager.getInstance().getAuthorizationPersistence();
        ap.deleteRole(roleId, context.getUserProfile().getId());

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

        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);
        }
        if (role == null) {
            return this.handleSuccess(mapping, context, "failure");
        }
        context.setAttribute("importMessage", "");
        context.setAttribute("role", role);
        String users = context.getRequest().getParameter("users");
        if (users == null || users.trim().length() == 0) {
            return this.handleSuccess(mapping, context, "success");
        }
        List<String> userList = new ArrayList<String>();
        BufferedReader reader = new BufferedReader(new StringReader(users));
        for (;;) {
            String line = reader.readLine();
            if (line == null) {
                break;
            }
            if (line.trim().length() > 0) {
                userList.add(line.trim());
            }
        }

        String operation = context.getRequest().getParameter("operation");
        if ("remove".equalsIgnoreCase(operation)) {
            // TODO NOT SAFE HERE, Sql injection is possible.
            Map<String, Boolean> result = authorizationPersistence.removeRoleUsers(userList, roleId);
            String message = this.generateResult(userList, result, true);
            context.setAttribute("importMessage", message);
        } else if ("add".equalsIgnoreCase(operation)) {
            // TODO NOT SAFE HERE, Sql injection is possible.
            Map<String, Boolean> result = authorizationPersistence.addRoleUsers(userList, roleId);
            String message = this.generateResult(userList, result, false);
            context.setAttribute("importMessage", message);
        }

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

        // create user perference
        UserPreference perference = profileForm.toUserPreference();
        perference.setId(profile.getId());
        userPersistence.createUserPreference(perference, 0);

        AuthorizationPersistence authorizationPersistence =
                PersistenceManager.getInstance().getAuthorizationPersistence();
        authorizationPersistence.addUserRole(profile.getId(), 2);

        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

        if (!profile.isActive()) {
            errors.add("password", new ActionMessage("LoginForm.password.deactivated"));
            return errors;
        }

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

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

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

        context.setUserProfile(profile);
View Full Code Here

                    UserPersistence userPersistence = PersistenceManager.getInstance().getUserPersistence();
                    UserProfile profile = userPersistence.login(handle, password);

                    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.persistence.AuthorizationPersistence

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.