+ Reply to Thread
Results 1 to 5 of 5
  1. #1
    Senior Member Taaltos's Avatar
    Join Date
    Feb 2013
    Posts
    2,531

    For those wanting INSTANT fixed server.

    Here's a "simple" sample of code for building an OpenID Provider / Server.

    public class SampleServer
    {
    // instantiate a ServerManager object
    public ServerManager manager = new ServerManager();

    public SampleServer()
    {
    manager.setOPEndpointUrl("Http://my.openidprovider.com/server");
    }

    public String processRequest(HttpServletRequest httpReq,
    HttpServletResponse httpResp)
    throws Exception
    {
    // extract the parameters from the request
    ParameterList request = new ParameterList(httpReq.getParameterMap());

    String mode = request.hasParameter("openid.mode") ?
    request.getParameterValue("openid.mode") : null;

    Message response;
    String responseText;

    if ("associate".equals(mode))
    {
    // --- process an association request ---
    response = manager.associationResponse(request);
    responseText = response.keyValueFormEncoding();
    }
    else if ("checkid_setup".equals(mode)
    || "checkid_immediate".equals(mode))
    {
    // interact with the user and obtain data needed to continue
    List userData = userInteraction(request);

    String userSelectedId = (String) userData.get(0);
    String userSelectedClaimedId = (String) userData.get(1);
    Boolean authenticatedAndApproved = (Boolean) userData.get(2);

    // --- process an authentication request ---
    response = manager.authResponse(request,
    userSelectedId,
    userSelectedClaimedId,
    authenticatedAndApproved.booleanValue());

    if (response instanceof DirectError)
    return directResponse(httpResp, response.keyValueFormEncoding());
    else
    {
    // caller will need to decide which of the following to use:

    // option1: GET HTTP-redirect to the return_to URL
    return response.getDestinationUrl(true);

    // option2: HTML FORM Redirection
    //RequestDispatcher dispatcher =
    // getServletContext().getRequestDispatcher("formredi rection.jsp");
    //httpReq.setAttribute("prameterMap", response.getParameterMap());
    //httpReq.setAttribute("destinationUrl", response.getDestinationUrl(false));
    //dispatcher.forward(request, response);
    //return null;
    }
    }
    else if ("check_authentication".equals(mode))
    {
    // --- processing a verification request ---
    response = manager.verify(request);
    responseText = response.keyValueFormEncoding();
    }
    else
    {
    // --- error response ---
    response = DirectError.createDirectError("Unknown request");
    responseText = response.keyValueFormEncoding();
    }

    // return the result to the user
    return responseText;
    }

    private List userInteraction(ParameterList request) throws ServerException
    {
    throw new ServerException("User-interaction not implemented.");
    }

    private String directResponse(HttpServletResponse httpResp, String response)
    throws IOException
    {
    ServletOutputStream os = httpResp.getOutputStream();
    os.write(response.getBytes());
    os.close();

    return null;
    }
    }






    So yeah.

  2. #2
    Senior Member
    Join Date
    Mar 2013
    Posts
    155
    Yeah, that's what I was saying in another thread. With the amount of error checking that coding requires, mistakes are bound to happen. Let the dust settle before you get upset about it. 4-7 days from launch, however? Go ahead and complain until you're blue in the face. Their "grace period" has pretty much expired at that point.

  3. #3
    Senior Member MrTexas's Avatar
    Join Date
    Mar 2013
    Posts
    102
    cliff notes pls.

  4. #4
    Senior Member Taaltos's Avatar
    Join Date
    Feb 2013
    Posts
    2,531
    Quote Originally Posted by Philote View Post
    Yeah, that's what I was saying in another thread. With the amount of error checking that coding requires, mistakes are bound to happen. Let the dust settle before you get upset about it. 4-7 days from launch, however? Go ahead and complain until you're blue in the face. Their "grace period" has pretty much expired at that point.
    I agree with ya on the 4-7. Although, I'm will to give them a bit longer, considering the ******** I endured with SimCity.

  5. #5
    Senior Member Taaltos's Avatar
    Join Date
    Feb 2013
    Posts
    2,531
    Quote Originally Posted by MrTexas View Post
    cliff notes pls.
    Cliff Notes: That ****s a whole other language!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts