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.wso2.carbon.identity.sample.extension.auth.SampleFingerprintAuthenticator.java

@Override
protected void initiateAuthenticationRequest(HttpServletRequest request, HttpServletResponse response,
        AuthenticationContext context) throws AuthenticationFailedException {

    String loginPage = IdentityUtil.getServerURL("sample-auth", true, true) + "/fpt.jsp";
    String queryParams = FrameworkUtils.getQueryStringWithFrameworkContextId(context.getQueryParams(),
            context.getCallerSessionKey(), context.getContextIdentifier());
    try {//w w  w.j a va  2 s . c  om
        String retryParam = "";

        if (context.isRetrying()) {
            retryParam = "&authFailure=true&authFailureMsg=login.fail.message";
        }
        String callbackUrl = IdentityUtil.getServerURL(FrameworkConstants.COMMONAUTH, true, true);
        callbackUrl = callbackUrl + "?sessionDataKey=" + context.getContextIdentifier() + "&authenticatorName="
                + getName();
        String encodedUrl = URLEncoder.encode(callbackUrl, StandardCharsets.UTF_8.name());
        response.sendRedirect(response.encodeRedirectURL(loginPage + ("?" + queryParams)) + "&callbackUrl="
                + encodedUrl + "&authenticators=SampleFingerprintAuthenticator:" + "LOCAL" + retryParam);
    } catch (IOException e) {
        throw new AuthenticationFailedException(
                "Authentication failed for the Sample Fingerprint Authenticator.", e);
    }
}

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

/**
 * {@inheritDoc}//from   w ww . j  a v a2 s  .c om
 */
public void post(HttpServletRequest req, HttpServletResponse res, Context context, String[] params)
        throws IOException {
    // sid then return
    if (params.length < 3) {
        throw new IllegalArgumentException();
    }

    String returnDestination = null;
    if (params.length > 3) {
        returnDestination = "/" + StringUtil.unsplit(params, 3, params.length - 3, "/");
    }

    // if not specified, go to the main list view
    else {
        returnDestination = "/list";
    }

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

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

    String submissionId = params[2];

    // this post is from the timer, or the "submit" button, and completes the submission
    submissionCompletePost(req, res, context, submissionId, this.uiService, this.submissionService,
            returnDestination);
}

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

/**
 * {@inheritDoc}/*from   w  w  w  . j a  v a  2  s  . c  o m*/
 */
public void post(HttpServletRequest req, HttpServletResponse res, Context context, String[] params)
        throws IOException {
    // [2] assessment id, [3] part id
    // [4] sort "0A", [5] page, [6] type filter [7] pool filter [8] survey filter
    // return address in the rest
    if (params.length < 9)
        throw new IllegalArgumentException();

    String assessmentId = params[2];
    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;
    }

    String partId = params[3];
    Part part = assessment.getParts().getPart(partId);
    if (part == null) {
        // redirect to error
        res.sendRedirect(res.encodeRedirectURL(Web.returnUrl(req, "/error/" + Errors.invalid)));
        return;
    }

    Values values = this.uiService.newValues();
    context.put("questionids", values);

    // for the selected "for" part
    Value value = this.uiService.newValue();
    context.put("partId", value);

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

    // get the new part id
    String newPartId = value.getValue();
    if (!part.getId().equals(newPartId)) {
        // create a new part?
        if ("0".equals(newPartId)) {
            try {
                Part created = assessment.getParts().addPart();
                this.assessmentService.saveAssessment(assessment);
                newPartId = created.getId();
            } catch (AssessmentPermissionException e) {
                // redirect to error
                res.sendRedirect(res.encodeRedirectURL(Web.returnUrl(req, "/error/" + Errors.unauthorized)));
                return;
            } catch (AssessmentPolicyException e) {
                // redirect to error
                res.sendRedirect(res.encodeRedirectURL(Web.returnUrl(req, "/error/" + Errors.policy)));
                return;
            }
        }

        Part newPart = assessment.getParts().getPart(newPartId);
        if (newPart != null) {
            part = newPart;

            // adjust the destination to use this part, if the destination is back to me
            String[] destParts = StringUtil.split(destination, "/");
            if (destParts[1].equals("select_add_mpart_question")) {
                destParts[3] = part.getId();
                destination = StringUtil.unsplit(destParts, 0, destParts.length, "/");
            }
        }
    }

    for (String id : values.getValues()) {
        Question question = this.questionService.getQuestion(id);
        if (question != null) {
            part.addPickDetail(question);
        }
    }

    // commit the save
    try {
        this.assessmentService.saveAssessment(assessment);
    } catch (AssessmentPermissionException e) {
        // redirect to error
        res.sendRedirect(res.encodeRedirectURL(Web.returnUrl(req, "/error/" + Errors.unauthorized)));
        return;
    } catch (AssessmentPolicyException e) {
        // redirect to error
        res.sendRedirect(res.encodeRedirectURL(Web.returnUrl(req, "/error/" + Errors.policy)));
        return;
    }

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

From source file:org.wso2.carbon.identity.sample.extension.auth.DemoFaceIdAuthenticator.java

@Override
protected void initiateAuthenticationRequest(HttpServletRequest request, HttpServletResponse response,
        AuthenticationContext context) throws AuthenticationFailedException {

    String loginPage = IdentityUtil.getServerURL("sample-auth", true, true) + "/retina.jsp";

    String queryParams = FrameworkUtils.getQueryStringWithFrameworkContextId(context.getQueryParams(),
            context.getCallerSessionKey(), context.getContextIdentifier());
    try {/*from   w ww .  j ava2s. c  om*/
        String retryParam = "";
        if (context.isRetrying()) {
            retryParam = "&authFailure=true&authFailureMsg=login.fail.message";
        }
        String callbackUrl = IdentityUtil.getServerURL(FrameworkConstants.COMMONAUTH, true, true);
        callbackUrl = callbackUrl + "?sessionDataKey=" + context.getContextIdentifier() + "&authenticatorName="
                + getName();
        String encodedUrl = URLEncoder.encode(callbackUrl, StandardCharsets.UTF_8.name());

        response.sendRedirect(response.encodeRedirectURL(loginPage + ("?" + queryParams)) + "&callbackUrl="
                + encodedUrl + "&authenticators=DemoFaceIdAuthenticator:" + "LOCAL" + retryParam);
    } catch (IOException e) {
        throw new AuthenticationFailedException("Authentication failed for the demo FaceID authenticator.", e);
    }
}

From source file:org.wso2.carbon.identity.sample.extension.auth.SampleRetinaAuthenticator.java

@Override
protected void initiateAuthenticationRequest(HttpServletRequest request, HttpServletResponse response,
        AuthenticationContext context) throws AuthenticationFailedException {

    String loginPage = IdentityUtil.getServerURL("sample-auth", true, true) + "/retina.jsp";

    String queryParams = FrameworkUtils.getQueryStringWithFrameworkContextId(context.getQueryParams(),
            context.getCallerSessionKey(), context.getContextIdentifier());
    try {//  w w w  .  ja  v a 2s  .com
        String retryParam = "";
        if (context.isRetrying()) {
            retryParam = "&authFailure=true&authFailureMsg=login.fail.message";
        }
        String callbackUrl = IdentityUtil.getServerURL(FrameworkConstants.COMMONAUTH, true, true);
        callbackUrl = callbackUrl + "?sessionDataKey=" + context.getContextIdentifier() + "&authenticatorName="
                + getName();
        String encodedUrl = URLEncoder.encode(callbackUrl, StandardCharsets.UTF_8.name());

        response.sendRedirect(response.encodeRedirectURL(loginPage + ("?" + queryParams)) + "&callbackUrl="
                + encodedUrl + "&authenticators=SampleRetinaAuthenticator:" + "LOCAL" + retryParam);
    } catch (IOException e) {
        throw new AuthenticationFailedException("Authentication failed for the sample Retina authenticator.",
                e);
    }
}

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

/**
 * {@inheritDoc}/*from  ww  w.j av a2 s.  c  om*/
 */
public void post(HttpServletRequest req, HttpServletResponse res, Context context, String[] params)
        throws IOException {
    // we need two parameters (submissionId, sectionId) then return
    if (params.length < 4) {
        throw new IllegalArgumentException();
    }

    String returnDestination = null;
    if (params.length > 4) {
        returnDestination = "/" + StringUtil.unsplit(params, 4, params.length - 4, "/");
    }

    // if not specified, go to the main list view
    else {
        returnDestination = "/list";
    }

    // 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"))
            && (!destination.equals("AUTO"))) {
        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,
            returnDestination);
}

From source file:org.wso2.carbon.identity.sample.extension.auth.DemoHardwareKeyAuthenticator.java

@Override
protected void initiateAuthenticationRequest(HttpServletRequest request, HttpServletResponse response,
        AuthenticationContext context) throws AuthenticationFailedException {

    String loginPage = IdentityUtil.getServerURL("sample-auth", true, true) + "/hwk.jsp";

    String queryParams = FrameworkUtils.getQueryStringWithFrameworkContextId(context.getQueryParams(),
            context.getCallerSessionKey(), context.getContextIdentifier());
    try {/*from www  .ja va  2  s.  c  om*/
        String retryParam = "";

        if (context.isRetrying()) {
            retryParam = "&authFailure=true&authFailureMsg=login.fail.message";
        }
        String callbackUrl = IdentityUtil.getServerURL(FrameworkConstants.COMMONAUTH, true, true);
        callbackUrl = callbackUrl + "?sessionDataKey=" + context.getContextIdentifier() + "&authenticatorName="
                + getName();
        String encodedUrl = URLEncoder.encode(callbackUrl, StandardCharsets.UTF_8.name());
        response.sendRedirect(response.encodeRedirectURL(loginPage + ("?" + queryParams)) + "&callbackUrl="
                + encodedUrl + "&authenticators=DemoHardwareKeyAuthenticator:" + "LOCAL" + retryParam);
    } catch (IOException e) {
        throw new AuthenticationFailedException(
                "Authentication failed for the Demo Hardware-key Authenticator.", e);
    }
}

From source file:org.wso2.carbon.identity.sample.extension.auth.SampleHardwareKeyAuthenticator.java

@Override
protected void initiateAuthenticationRequest(HttpServletRequest request, HttpServletResponse response,
        AuthenticationContext context) throws AuthenticationFailedException {

    String loginPage = IdentityUtil.getServerURL("sample-auth", true, true) + "/hwk.jsp";

    String queryParams = FrameworkUtils.getQueryStringWithFrameworkContextId(context.getQueryParams(),
            context.getCallerSessionKey(), context.getContextIdentifier());
    try {//from w  w w  . j a  v  a 2s  . c  om
        String retryParam = "";

        if (context.isRetrying()) {
            retryParam = "&authFailure=true&authFailureMsg=login.fail.message";
        }
        String callbackUrl = IdentityUtil.getServerURL(FrameworkConstants.COMMONAUTH, true, true);
        callbackUrl = callbackUrl + "?sessionDataKey=" + context.getContextIdentifier() + "&authenticatorName="
                + getName();
        String encodedUrl = URLEncoder.encode(callbackUrl, StandardCharsets.UTF_8.name());
        response.sendRedirect(response.encodeRedirectURL(loginPage + ("?" + queryParams)) + "&callbackUrl="
                + encodedUrl + "&authenticators=SampleHardwareKeyAuthenticator:" + "LOCAL" + retryParam);
    } catch (IOException e) {
        throw new AuthenticationFailedException(
                "Authentication failed for the Sample Hardware-key Authenticator.", e);
    }
}

From source file:fll.web.admin.ChangePassword.java

@Override
protected void processRequest(final HttpServletRequest request, final HttpServletResponse response,
        final ServletContext application, final HttpSession session) throws IOException, ServletException {
    final DataSource datasource = ApplicationAttributes.getDataSource(application);
    Connection connection = null;
    try {//from   w  w  w . j  ava  2s. co  m
        connection = datasource.getConnection();

        final Collection<String> loginKeys = CookieUtils.findLoginKey(request);
        final String user = Queries.checkValidLogin(connection, loginKeys);

        final String passwordHash = Queries.getHashedPassword(connection, user);
        final String oldPassword = request.getParameter("old_password");
        final String hashedOldPass = DigestUtils.md5Hex(oldPassword);
        if (!ComparisonUtils.safeEquals(passwordHash, hashedOldPass)) {
            session.setAttribute(SessionAttributes.MESSAGE, "<p class='error'>Old password is incorrect</p>");
            response.sendRedirect(response.encodeRedirectURL("changePassword.jsp"));
            return;
        }

        final String newPassword = request.getParameter("pass");
        final String newPasswordCheck = request.getParameter("pass_check");
        if (!ComparisonUtils.safeEquals(newPassword, newPasswordCheck)) {
            session.setAttribute(SessionAttributes.MESSAGE, "<p class='error'>New passwords don't match</p>");
            response.sendRedirect(response.encodeRedirectURL("changePassword.jsp"));
            return;
        }

        final String newPasswordHash = DigestUtils.md5Hex(newPassword);

        // invalidate all login keys now that the password has changed
        Queries.changePassword(connection, user, newPasswordHash);
        Queries.removeValidLoginByUser(connection, user);

        session.setAttribute(SessionAttributes.MESSAGE,
                "<p id='success'>Password changed for '" + user + "', you will now need to login again.</p>");
        response.sendRedirect(response.encodeRedirectURL("changePassword.jsp"));

    } catch (final SQLException e) {
        throw new RuntimeException(e);
    } finally {
        SQLFunctions.close(connection);
    }

}

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

/**
 * {@inheritDoc}/*w ww.ja  v a 2s . c o m*/
 */
public void get(HttpServletRequest req, HttpServletResponse res, Context context, String[] params)
        throws IOException {
    // we need two parameters (submissionId, partId) then return
    if (params.length < 4) {
        throw new IllegalArgumentException();
    }

    String submissionId = params[2];
    String partId = params[3];

    String destination = null;
    if (params.length > 4) {
        destination = "/" + StringUtil.unsplit(params, 4, params.length - 4, "/");
    }

    // if not specified, go to the main list view
    else {
        destination = "/list";
    }
    context.put("return", destination);

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

    // make sure by-question is valid for this assessment
    if (submission.getAssessment().getQuestionGrouping() != QuestionGrouping.question) {
        // 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;
    }

    // collect the part
    Part part = submission.getAssessment().getParts().getPart(partId);
    if (part == null) {
        // redirect to error
        res.sendRedirect(res.encodeRedirectURL(Web.returnUrl(req, "/error/" + Errors.invalid)));
        return;
    }

    context.put("submission", submission);
    context.put("part", part);

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

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