Open ID 端点转发不起作用

发布于 2024-11-18 09:09:29 字数 2473 浏览 1 评论 0原文

我是 Open Id 开发的新手。我从互联网上下载了 openid4java 示例应用程序,并尝试在我的应用程序中实现相同的功能。到目前为止,我已经编写了在发现后点击打开 id 端点的代码。它一直工作到发现。但是之后当尝试到达终点 URI 时,我收到 404 错误,因为它还附加了我的项目 URL 路径。 例如:

/Openid/http://www.myopenid.com/server。(这里Openid是我的项目名称)。

这是我的 servlet :

package com.openid.registration;

import java.io.IOException;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.openid4java.discovery.DiscoveryInformation;
import org.openid4java.message.AuthRequest;

public class OpenIdRegistrationServlet extends HttpServlet
{
private static final long serialVersionUID = 1L;
private String returnToUrl;
RequestDispatcher rd = null;

protected void processRequest(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException 
{
    HttpSession session=request.getSession(false);
    String OpenID=request.getParameter("openid");
    System.out.println("Open ID entered by the user"+OpenID);
    // Delegate to Open ID code
    DiscoveryInformation discoveryInformation = RegistrationService.performDiscoveryOnUserSuppliedIdentifier(OpenID);
    // Store the disovery results in session.
    System.out.println("OPEnd Point"+discoveryInformation.getOPEndpoint());
    session.setAttribute("discoveryInformation", discoveryInformation);
     // Create the AuthRequest
    returnToUrl=RegistrationService.getReturnToUrl();
    AuthRequest authRequest = RegistrationService.createOpenIdAuthRequest(discoveryInformation, returnToUrl);
    rd = request.getRequestDispatcher(authRequest.getDestinationUrl(true));
    System.out.println("Destination URL:"+authRequest.getDestinationUrl(true));
    rd.forward(request, response);

}
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    processRequest(request,response);
    // TODO Auto-generated method stub
}

/**
 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
 */
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    processRequest(request,response);
    // TODO Auto-generated method stub
}

}

我已经在 tomcat 5 中部署了我的应用程序。有没有办法从 URL 中删除我的项目名称,或者我需要从 apache web 服务器重定向?任何帮助表示赞赏

I am new to Open Id development.I have downloaded openid4java sample application from the internet and trying to implement the same in mine.Till now i have written the code to hit to open id end point after discover.its working till discovering.But after that when trying to hit the end point URI I am getting 404 error because its appending my project URL path also.
Ex:

/Openid/http:/www.myopenid.com/server.(here Openid is my project name).

This is my servlet :

package com.openid.registration;

import java.io.IOException;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.openid4java.discovery.DiscoveryInformation;
import org.openid4java.message.AuthRequest;

public class OpenIdRegistrationServlet extends HttpServlet
{
private static final long serialVersionUID = 1L;
private String returnToUrl;
RequestDispatcher rd = null;

protected void processRequest(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException 
{
    HttpSession session=request.getSession(false);
    String OpenID=request.getParameter("openid");
    System.out.println("Open ID entered by the user"+OpenID);
    // Delegate to Open ID code
    DiscoveryInformation discoveryInformation = RegistrationService.performDiscoveryOnUserSuppliedIdentifier(OpenID);
    // Store the disovery results in session.
    System.out.println("OPEnd Point"+discoveryInformation.getOPEndpoint());
    session.setAttribute("discoveryInformation", discoveryInformation);
     // Create the AuthRequest
    returnToUrl=RegistrationService.getReturnToUrl();
    AuthRequest authRequest = RegistrationService.createOpenIdAuthRequest(discoveryInformation, returnToUrl);
    rd = request.getRequestDispatcher(authRequest.getDestinationUrl(true));
    System.out.println("Destination URL:"+authRequest.getDestinationUrl(true));
    rd.forward(request, response);

}
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    processRequest(request,response);
    // TODO Auto-generated method stub
}

/**
 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
 */
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    processRequest(request,response);
    // TODO Auto-generated method stub
}

}

I have deployed my application in tomcat 5.Is there any way to remove my project name from the URL or do i need to redirect from apache webserver ? Any help is appreciated

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

对岸观火 2024-11-25 09:09:29

这是我的错误。我已将forward(请求,响应)更改为sendRedirect(authRequest.getDestinationUrl(true))。它开始正常工作。

Its my mistake.I have changed forward(request, response) to sendRedirect(authRequest.getDestinationUrl(true)).Its started working fine.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文