Example usage for javax.servlet.http HttpServletResponse encodeRedirectUrl

List of usage examples for javax.servlet.http HttpServletResponse encodeRedirectUrl

Introduction

In this page you can find the example usage for javax.servlet.http HttpServletResponse encodeRedirectUrl.

Prototype

@Deprecated
public String encodeRedirectUrl(String url);

Source Link

Usage

From source file:org.etudes.mneme.tool.AssessmentInvalidView.java

/**
 * {@inheritDoc}//from w  w  w  .  j a  va  2  s .c  o  m
 */
public void get(HttpServletRequest req, HttpServletResponse res, Context context, String[] params)
        throws IOException {
    // sort code, aid
    if (params.length != 4) {
        throw new IllegalArgumentException();
    }

    String sortCode = params[2];
    String assessmentId = params[3];

    Assessment assessment = assessmentService.getAssessment(assessmentId);
    if (assessment == null) {
        // redirect to error
        res.sendRedirect(res.encodeRedirectURL(Web.returnUrl(req, "/error/" + Errors.invalid)));
        return;
    }

    // security check
    if (!assessmentService.allowEditAssessment(assessment)) {
        // redirect to error
        res.sendRedirect(res.encodeRedirectURL(Web.returnUrl(req, "/error/" + Errors.unauthorized)));
        return;
    }

    context.put("message", formatInvalidDisplay(assessment, this.messages));
    context.put("assessment", assessment);
    context.put("sortcode", sortCode);

    // render
    uiService.render(ui, context);
}

From source file:org.etudes.mneme.tool.ImportTqAssessmentView.java

/**
 * {@inheritDoc}/*from  w  w  w  . ja v a  2s. c o  m*/
 */
public void get(HttpServletRequest req, HttpServletResponse res, Context context, String[] params)
        throws IOException {
    // [2] pools sort, [3] source context
    if (params.length != 4) {
        throw new IllegalArgumentException();
    }
    String poolsSort = params[2];
    context.put("poolsSort", poolsSort);
    String sourceContext = params[3];

    if (!this.poolService.allowManagePools(toolManager.getCurrentPlacement().getContext())) {
        // redirect to error
        res.sendRedirect(res.encodeRedirectURL(Web.returnUrl(req, "/error/" + Errors.unauthorized)));
        return;
    }

    // the list of importable assessments for this site
    List<Ent> assessments = this.importService.getSamigoAssessments(sourceContext);
    context.put("assessments", assessments);

    // render
    uiService.render(ui, context);
}

From source file:org.broadleafcommerce.common.security.LocalRedirectStrategy.java

@Override
public void sendRedirect(HttpServletRequest request, HttpServletResponse response, String url)
        throws IOException {
    if (!url.startsWith("/")) {
        if (StringUtils.equals(request.getParameter("successUrl"), url)
                || StringUtils.equals(request.getParameter("failureUrl"), url)) {
            validateRedirectUrl(request.getContextPath(), url, request.getServerName(),
                    request.getServerPort());
        }/*from   w w w . j  a v  a  2s .  com*/
    }
    String redirectUrl = calculateRedirectUrl(request.getContextPath(), url);
    redirectUrl = response.encodeRedirectURL(redirectUrl);
    if (LOG.isDebugEnabled()) {
        LOG.debug("Redirecting to '" + url + "'");
    }

    response.sendRedirect(redirectUrl);
}

From source file:org.muse.mneme.tool.ImportAssignmentView.java

/**
 * {@inheritDoc}//  ww w .  j  av  a  2 s .  c  o  m
 */
public void get(HttpServletRequest req, HttpServletResponse res, Context context, String[] params)
        throws IOException {
    // [2] pools sort, [3] source context
    if (params.length != 4) {
        throw new IllegalArgumentException();
    }
    String poolsSort = params[2];
    context.put("poolsSort", poolsSort);
    String sourceContext = params[3];

    if (!this.poolService.allowManagePools(toolManager.getCurrentPlacement().getContext())) {
        // redirect to error
        res.sendRedirect(res.encodeRedirectURL(Web.returnUrl(req, "/error/" + Errors.unauthorized)));
        return;
    }

    // the list of importable assignments for this site
    List<Ent> assessments = this.importService.getAssignments(sourceContext);
    context.put("assignments", assessments);

    // render
    uiService.render(ui, context);
}

From source file:com.wso2telco.gsma.authenticators.saa.SmartPhoneAppAuthenticator.java

private void handleRedirect(HttpServletResponse response, AuthenticationContext context,
        boolean isFlowCompleted) throws AuthenticationFailedException {

    String loginPage = configurationService.getDataHolder().getMobileConnectConfig().getAuthEndpointUrl()
            + Constants.SAA_WAITING_JSP;
    context.setProperty(IS_FLOW_COMPLETED, isFlowCompleted);

    if (!isFlowCompleted) {
        String redirectUrl = response.encodeRedirectURL(loginPage + ("?" + context.getQueryParams()))
                + "&scope=" + (String) context.getProperty("scope") + "&redirect_uri="
                + context.getProperty("redirectURI") + "&authenticators=" + getName() + ":" + "LOCAL";

        log.info("Sent request to the SAA server successfully. Redirecting to [ " + redirectUrl + " ] ");

        try {//from   w  w w  . j  ava2s .co  m
            response.sendRedirect(redirectUrl);
        } catch (IOException e) {
            log.info(
                    "Error occurred while redirecting to waiting page. Passing control to the next authenticator");
        }
    } else {
        log.info("Passing control to the next authenticator");
    }
}

From source file:org.muse.mneme.tool.SectionInstructionView.java

/**
 * {@inheritDoc}//  w w w .ja va 2  s.  co m
 */
public void post(HttpServletRequest req, HttpServletResponse res, Context context, String[] params)
        throws IOException {
    // we need two parameters (submissionId, sectionId)
    if (params.length != 4) {
        throw new IllegalArgumentException();
    }

    // read form
    String destination = this.uiService.decode(req, context);

    // if other than the /submitted destination, just go there
    if (!destination.startsWith("/submitted") && (!destination.equals("SUBMIT"))) {
        res.sendRedirect(res.encodeRedirectURL(Web.returnUrl(req, destination)));
        return;
    }

    String submissionId = params[2];

    // this post is from the timer, and completes the submission
    TocView.submissionCompletePost(req, res, context, submissionId, this.uiService, this.submissionService);
}

From source file:org.muse.mneme.tool.PoolsView.java

/**
 * {@inheritDoc}/*from   w  w w . jav  a2s .co m*/
 */
public void get(HttpServletRequest req, HttpServletResponse res, Context context, String[] params)
        throws IOException {
    // sort, optional
    if ((params.length != 2) && (params.length != 3)) {
        throw new IllegalArgumentException();
    }

    // security
    if (!this.poolService.allowManagePools(toolManager.getCurrentPlacement().getContext())) {
        // redirect to error
        res.sendRedirect(res.encodeRedirectURL(Web.returnUrl(req, "/error/" + Errors.unauthorized)));
        return;
    }

    // sort parameter
    String sortCode = "0A";
    if (params.length > 2)
        sortCode = params[2];
    if ((sortCode == null) || (sortCode.length() != 2)) {
        throw new IllegalArgumentException();
    }
    context.put("sort_column", sortCode.charAt(0));
    context.put("sort_direction", sortCode.charAt(1));

    // 0 is title
    PoolService.FindPoolsSort sort = null;
    if ((sortCode.charAt(0) == '0') && (sortCode.charAt(1) == 'A')) {
        sort = PoolService.FindPoolsSort.title_a;
    } else if ((sortCode.charAt(0) == '0') && (sortCode.charAt(1) == 'D')) {
        sort = PoolService.FindPoolsSort.title_d;
    } else {
        throw new IllegalArgumentException();
    }

    // collect the pools to show
    List<Pool> pools = this.poolService.findPools(toolManager.getCurrentPlacement().getContext(), sort, null);
    context.put("pools", pools);

    // disable the tool navigation to this view
    context.put("disablePools", Boolean.TRUE);

    // pre-read question counts per pool
    this.questionService.preCountContextQuestions(toolManager.getCurrentPlacement().getContext(), null);

    // render
    uiService.render(ui, context);
}

From source file:org.etudes.mneme.tool.ConfirmGradesImportView.java

/**
 * {@inheritDoc}/*from  w w w. j  a  v  a  2s .co  m*/
 */
@SuppressWarnings("unchecked")
public void post(HttpServletRequest req, HttpServletResponse res, Context context, String[] params)
        throws IOException {
    // check for user permission to access the assessments for grading
    if (!this.submissionService.allowEvaluate(toolManager.getCurrentPlacement().getContext())) {
        // redirect to error
        res.sendRedirect(res.encodeRedirectURL(Web.returnUrl(req, "/error/" + Errors.unauthorized)));
        return;
    }

    // return destination - or the main assessments view if not specified
    String destination = null;
    if (params.length > 2) {
        int len = params.length - 2;
        destination = "/" + StringUtil.unsplit(params, 2, len, "/");
    } else {
        destination = "/assessments";
    }

    // get and clear the sets stored in the tool state
    ToolSession toolSession = m_sessionManager.getCurrentToolSession();
    List<GradeImportSet> importSets = (List<GradeImportSet>) toolSession.getAttribute(GradeImportSet.ATTR_NAME);
    toolSession.removeAttribute(GradeImportSet.ATTR_NAME);

    if (importSets == null) {
        // redirect to error
        res.sendRedirect(res.encodeRedirectURL(Web.returnUrl(req, "/error/" + Errors.invalid)));
        return;
    }

    context.put("targets", importSets);

    // read form
    String outcome = this.uiService.decode(req, context);

    if (outcome.equals("IMPORT")) {
        // process each set
        for (GradeImportSet set : importSets) {
            // if selected for import
            if (!set.getSelected())
                continue;

            // create if needed
            if (set.assessment == null) {
                Assessment assessment = null;
                try {
                    assessment = this.assessmentService
                            .newAssessment(toolManager.getCurrentPlacement().getContext());
                    assessment.setTitle(set.assessmentTitle);
                    assessment.setType(AssessmentType.offline);
                    if (set.points != null) {
                        assessment.setPoints(set.points);
                        assessment.setPublished(Boolean.TRUE);
                    }
                    this.assessmentService.saveAssessment(assessment);
                    set.assessment = assessment;
                } catch (AssessmentPermissionException e) {
                } catch (AssessmentPolicyException e) {
                }
            }

            if (set.assessment == null)
                continue;

            // ignore any not qualified for import
            if (set.assessment.getFormalCourseEval() || set.assessment.getType() == AssessmentType.survey
                    || !set.assessment.getHasPoints())
                continue;

            // get the assesssment's submissions
            List<Submission> subs = this.submissionService.findAssessmentSubmissions(set.assessment, null, true,
                    null, null, null, null);

            for (GradeImport r : set.rows) {
                if (r.userId == null)
                    continue;

                try {
                    User user = this.userDirectoryService.getUser(r.userId);

                    // find the submission
                    Submission forUser = null;
                    for (Submission submission : subs) {
                        if (submission.getUserId().equals(user.getId())) {
                            forUser = submission;
                            break;
                        }
                    }

                    if (forUser != null) {
                        try {
                            forUser.setTotalScore(r.score);

                            // save
                            try {
                                this.submissionService.evaluateSubmission(forUser);
                            } catch (AssessmentPermissionException e) {
                            }
                        } catch (NumberFormatException e) {
                        }
                    }
                } catch (UserNotDefinedException e) {
                }
            }
        }
    }

    else {
        destination = outcome;
    }

    res.sendRedirect(res.encodeRedirectURL(Web.returnUrl(req, destination)));
}

From source file:org.muse.mneme.tool.TocView.java

/**
 * {@inheritDoc}//from   ww w .  ja  v a 2s  . co m
 */
public void get(HttpServletRequest req, HttpServletResponse res, Context context, String[] params)
        throws IOException {
    // we need one parameter (sid)
    if (params.length != 3) {
        throw new IllegalArgumentException();
    }

    String submissionId = params[2];

    Submission submission = submissionService.getSubmission(submissionId);
    if (submission == null) {
        // redirect to error
        res.sendRedirect(res.encodeRedirectURL(Web.returnUrl(req, "/error/" + Errors.invalid)));
        return;
    }

    if (!submissionService.allowCompleteSubmission(submission)) {
        // redirect to error
        res.sendRedirect(res.encodeRedirectURL(Web.returnUrl(req, "/error/" + Errors.unauthorized)));
        return;
    }

    // linear is not allowed in here
    if (!submission.getAssessment().getRandomAccess()) {
        // redirect to error
        res.sendRedirect(
                res.encodeRedirectURL(Web.returnUrl(req, "/error/" + Errors.linear + "/" + submissionId)));
        return;
    }

    // collect information: the selected assessment (id the request)
    context.put("submission", submission);

    context.put("finalReview", Boolean.FALSE);

    // for the tool navigation
    if (this.assessmentService.allowManageAssessments(toolManager.getCurrentPlacement().getContext())) {
        context.put("maintainer", Boolean.TRUE);
    }

    // render
    uiService.render(ui, context);
}

From source file:org.etudes.mneme.tool.GuestListView.java

/**
 * {@inheritDoc}/*from   ww w.  j  av a 2  s  . c  o m*/
 */
public void get(HttpServletRequest req, HttpServletResponse res, Context context, String[] params)
        throws IOException {
    // 0 or 1 parameters
    if ((params.length != 2) && (params.length != 3)) {
        throw new IllegalArgumentException();
    }

    // check security
    if (!assessmentService.allowGuest(toolManager.getCurrentPlacement().getContext())) {
        // redirect to error
        res.sendRedirect(res.encodeRedirectURL(Web.returnUrl(req, "/error/" + Errors.unauthorized)));
        return;
    }

    // optional sort parameter
    String sortCode = null;
    if (params.length == 3) {
        sortCode = params[2];
    }

    // SORT: 0|1|2|3 A|D - 2 chars, column | direction
    if ((sortCode != null) && (sortCode.length() != 2)) {
        // redirect to error
        res.sendRedirect(res.encodeRedirectURL(Web.returnUrl(req, "/error/" + Errors.invalid)));
        return;
    }

    SubmissionService.GetUserContextSubmissionsSort sort = SubmissionService.GetUserContextSubmissionsSort.title_a;
    if (sortCode != null) {
        context.put("sort_column", sortCode.charAt(0));
        context.put("sort_direction", sortCode.charAt(1));

        // 0 is title
        if ((sortCode.charAt(0) == '0') && (sortCode.charAt(1) == 'A')) {
            sort = SubmissionService.GetUserContextSubmissionsSort.title_a;
        } else if ((sortCode.charAt(0) == '0') && (sortCode.charAt(1) == 'D')) {
            sort = SubmissionService.GetUserContextSubmissionsSort.title_d;
        }

        // 1 is status
        // TODO: remove status
        else if ((sortCode.charAt(0) == '1') && (sortCode.charAt(1) == 'A')) {
            sort = SubmissionService.GetUserContextSubmissionsSort.status_a;
        } else if ((sortCode.charAt(0) == '1') && (sortCode.charAt(1) == 'D')) {
            sort = SubmissionService.GetUserContextSubmissionsSort.status_d;
        }

        // 2 is due date
        else if ((sortCode.charAt(0) == '2') && (sortCode.charAt(1) == 'A')) {
            sort = SubmissionService.GetUserContextSubmissionsSort.dueDate_a;
        } else if ((sortCode.charAt(0) == '2') && (sortCode.charAt(1) == 'D')) {
            sort = SubmissionService.GetUserContextSubmissionsSort.dueDate_d;
        }

        // 3 is type
        else if ((sortCode.charAt(0) == '3') && (sortCode.charAt(1) == 'A')) {
            sort = SubmissionService.GetUserContextSubmissionsSort.type_a;
        } else if ((sortCode.charAt(0) == '3') && (sortCode.charAt(1) == 'D')) {
            sort = SubmissionService.GetUserContextSubmissionsSort.type_d;
        }

        else {
            // redirect to error
            res.sendRedirect(res.encodeRedirectURL(Web.returnUrl(req, "/error/" + Errors.invalid)));
            return;
        }
    }

    // default sort: title descending
    if (sortCode == null) {
        context.put("sort_column", '0');
        context.put("sort_direction", 'D');
        sort = SubmissionService.GetUserContextSubmissionsSort.title_d;
    }

    // collect information: submissions / assessments
    List<Submission> submissions = this.submissionService
            .getUserContextSubmissions(toolManager.getCurrentPlacement().getContext(), null, sort);
    context.put("submissions", submissions);

    // disable the tool navigation to this view
    context.put("disableDelivery", Boolean.TRUE);

    // for the tool navigation
    if (this.assessmentService.allowManageAssessments(toolManager.getCurrentPlacement().getContext())) {
        context.put("maintainer", Boolean.TRUE);
    }

    // render
    uiService.render(ui, context);
}