Package org.openid4java.message

Examples of org.openid4java.message.Message


        } catch (AssociationException e) {
            throw new OpenIDConsumerException("Error verifying openid response", e);
        }

        // fetch the attributesToFetch of the response
        Message authSuccess = verification.getAuthResponse();
        List<OpenIDAttribute> attributes = new ArrayList<OpenIDAttribute>(this.attributesToFetch.size());

        if (authSuccess.hasExtension(AxMessage.OPENID_NS_AX)) {
            if (debug) {
                logger.debug("Extracting attributes retrieved by attribute exchange");
            }
            try {
                MessageExtension ext = authSuccess.getExtension(AxMessage.OPENID_NS_AX);
                if (ext instanceof FetchResponse) {
                    FetchResponse fetchResp = (FetchResponse) ext;
                    for (OpenIDAttribute attr : attributesToFetch) {
                        List<String> values = fetchResp.getAttributeValues(attr.getName());
                        if (!values.isEmpty()) {
View Full Code Here


      }

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

          Message responsem;
          String responseText;

          if ("associate".equals(mode))
          {
              // --- process an association request ---
              responsem = manager.associationResponse(requestp);
              responseText = responsem.keyValueFormEncoding();
          }
          else if ("checkid_setup".equals(mode)
                  || "checkid_immediate".equals(mode))
          {
              // interact with the user and obtain data needed to continue
              //List userData = userInteraction(requestp);
              String userSelectedId = null;
              String userSelectedClaimedId = null;
              Boolean authenticatedAndApproved = Boolean.FALSE;

              if ((session.getAttribute("authenticatedAndApproved") == null) ||
                      (((Boolean)session.getAttribute("authenticatedAndApproved")) == Boolean.FALSE) )
              {
                  session.setAttribute("parameterlist", requestp);
                  response.sendRedirect("provider_authorization.jsp");
              }
              else
              {
                  userSelectedId = (String) session.getAttribute("openid.claimed_id");
                  userSelectedClaimedId = (String) session.getAttribute("openid.identity");
                  authenticatedAndApproved = (Boolean) session.getAttribute("authenticatedAndApproved");
                  // Remove the parameterlist so this provider can accept requests from elsewhere
                  session.removeAttribute("parameterlist");
                  session.setAttribute("authenticatedAndApproved", Boolean.FALSE); // Makes you authorize each and every time
              }

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

              // caller will need to decide which of the following to use:
              // - GET HTTP-redirect to the return_to URL
              // - HTML FORM Redirection
              //responseText = response.wwwFormEncoding();
              if (responsem instanceof AuthSuccess)
              {
                  response.sendRedirect(((AuthSuccess) responsem).getDestinationUrl(true));
                  return "";
              }
              else
              {
                  responseText="<pre>"+responsem.keyValueFormEncoding()+"</pre>";
              }
          }
          else if ("check_authentication".equals(mode))
          {
              // --- processing a verification request ---
              responsem = manager.verify(requestp);
              responseText = responsem.keyValueFormEncoding();
          }
          else
          {
              // --- error response ---
              responsem = DirectError.createDirectError("Unknown request");
              responseText = responsem.keyValueFormEncoding();
          }
         
         
     
      return responseText != null ? responseText.trim() : null;
View Full Code Here

      }

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

          Message responsem;
          String responseText;

          if ("associate".equals(mode))
          {
              // --- process an association request ---
              responsem = manager.associationResponse(requestp);
              responseText = responsem.keyValueFormEncoding();
          }
          else if ("checkid_setup".equals(mode)
                  || "checkid_immediate".equals(mode))
          {
              // interact with the user and obtain data needed to continue
              //List userData = userInteraction(requestp);
              String userSelectedId = null;
              String userSelectedClaimedId = null;
              Boolean authenticatedAndApproved = Boolean.FALSE;

              if ((session.getAttribute("authenticatedAndApproved") == null) ||
                      (((Boolean)session.getAttribute("authenticatedAndApproved")) == Boolean.FALSE) )
              {
                  session.setAttribute("parameterlist", requestp);
                  response.sendRedirect("provider_authorization.jsp");
              }
              else
              {
                  userSelectedId = (String) session.getAttribute("openid.claimed_id");
                  userSelectedClaimedId = (String) session.getAttribute("openid.identity");
                  authenticatedAndApproved = (Boolean) session.getAttribute("authenticatedAndApproved");
                  // Remove the parameterlist so this provider can accept requests from elsewhere
                  session.removeAttribute("parameterlist");
                  session.setAttribute("authenticatedAndApproved", Boolean.FALSE); // Makes you authorize each and every time
              }

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

              // caller will need to decide which of the following to use:
              // - GET HTTP-redirect to the return_to URL
              // - HTML FORM Redirection
              //responseText = response.wwwFormEncoding();
              if (responsem instanceof AuthSuccess)
              {
                  response.sendRedirect(((AuthSuccess) responsem).getDestinationUrl(true));
                  return "";
              }
              else
              {
                  responseText="<pre>"+responsem.keyValueFormEncoding()+"</pre>";
              }
          }
          else if ("check_authentication".equals(mode))
          {
              // --- processing a verification request ---
              responsem = manager.verify(requestp);
              responseText = responsem.keyValueFormEncoding();
          }
          else
          {
              // --- error response ---
              responsem = DirectError.createDirectError("Unknown request");
              responseText = responsem.keyValueFormEncoding();
          }
         
         
     
      return responseText != null ? responseText.trim() : null;
View Full Code Here

    // 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 userSelectedClaimedId = (String) userData.get(0);
      Boolean authenticatedAndApproved = (Boolean) userData.get(1);
      String email = (String) userData.get(2);

      // --- process an authentication request ---
      AuthRequest authReq = AuthRequest.createAuthRequest(request, manager.getRealmVerifier());
      response = manager.authResponse(request, null, userSelectedClaimedId, authenticatedAndApproved, false); // Sign after we added extensions.

      if (response instanceof DirectError) {
        return directResponse(httpResp, response.keyValueFormEncoding());
      } else {
        if (authReq.hasExtension(AxMessage.OPENID_NS_AX)) {
          MessageExtension ext = authReq.getExtension(AxMessage.OPENID_NS_AX);
          if (ext instanceof FetchRequest) {
            FetchRequest fetchReq = (FetchRequest) ext;
            Map<?, ?> required = fetchReq.getAttributes(true);
            //Map optional = fetchReq.getAttributes(false);
            if (required.containsKey("email")) {
              Map<Object, Object> userDataExt = new HashMap<>();
              //userDataExt.put("email", userData.get(3));

              FetchResponse fetchResp = FetchResponse.createFetchResponse(fetchReq, userDataExt);
              // (alternatively) manually add attribute values
              fetchResp.addAttribute("email", "http://schema.openid.net/contact/email", email);
              response.addExtension(fetchResp);
            }
          } else {
            throw new UnsupportedOperationException("TODO");
          }
        }
        if (authReq.hasExtension(SRegMessage.OPENID_NS_SREG)) {
          MessageExtension ext = authReq.getExtension(SRegMessage.OPENID_NS_SREG);
          if (ext instanceof SRegRequest) {
            SRegRequest sregReq = (SRegRequest) ext;
            List<?> required = sregReq.getAttributes(true);
            //List optional = sregReq.getAttributes(false);
            if (required.contains("email")) {
              // data released by the user
              Map<Object, Object> userDataSReg = new HashMap<>();
              //userData.put("email", "user@example.com");

              SRegResponse sregResp = SRegResponse.createSRegResponse(sregReq, userDataSReg);
              // (alternatively) manually add attribute values
              sregResp.addAttribute("email", email);
              response.addExtension(sregResp);
            }
          } else {
            throw new UnsupportedOperationException("TODO");
          }
        }

        // Sign the auth success message.
        if (response instanceof AuthSuccess) {
          manager.sign((AuthSuccess) response);
        }

        // 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("formredirection.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;
  }
View Full Code Here

        ParameterList request = new ParameterList(req.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_immediate".equals(mode))
        {
          String userSelectedClaimedId = (String) request.getParameter("openid.claimed_id").getValue();
         
            String realm = (String) request.getParameter("openid.realm").getValue();
           
            if (!isTrustedRealm(realm, userSelectedClaimedId)) {
                response = DirectError.createDirectError("checkid_immediate is not supported");
                responseText = response.keyValueFormEncoding();
                directResponse(resp, responseText);
                return;
            }
         
            // --- process an authentication request ---
            AuthRequest authReq = null;
            try {
                authReq = AuthRequest.createAuthRequest(request, manager.getRealmVerifier());
            } catch (Exception ex) {
              throw new ServletException(ex);
            }

            String opLocalId = null;
            // if the user chose a different claimed_id than the one in request
            if (userSelectedClaimedId != null &&
                userSelectedClaimedId.equals(authReq.getClaimed()))
            {
                //opLocalId = lookupLocalId(userSelectedClaimedId);
            }
           
            response = manager.authResponse(request,
                    opLocalId,
                    userSelectedClaimedId,
                    true,
                    false); // Sign after we added extensions.

            if (response instanceof DirectError)
                responseText = response.keyValueFormEncoding();
            else
            {
                // Sign the auth success message.
                // This is required as AuthSuccess.buildSignedList has a `todo' tag now.
              try {
                    manager.sign((AuthSuccess) response);
              } catch (Exception ex) {
                throw new ServletException(ex);
              }
                responseText = response.keyValueFormEncoding();
            }
        }
        else
        {
          // unsupported mode
            // --- error response ---
            response = DirectError.createDirectError("Unknown request");
            responseText = response.keyValueFormEncoding();
        }

        directResponse(resp, responseText);
  }
View Full Code Here

   public OpenIDMessage processAuthenticationRequest(ParameterList requestParams,
         String userSelId,
         String userSelClaimed,
         boolean authenticatedAndApproved)
   {
      Message authMessage = serverManager.authResponse(requestParams,
            userSelId, userSelClaimed, authenticatedAndApproved);
     
      return new OpenIDMessage(authMessage);
   }
View Full Code Here

   public OpenIDMessage processAuthenticationRequest(ParameterList requestParams,
         String userSelId,
         String userSelClaimed,
         boolean authenticatedAndApproved)
   {
      Message authMessage = serverManager.authResponse(requestParams,
            userSelId, userSelClaimed, authenticatedAndApproved);
     
      return new OpenIDMessage(authMessage);
   }
View Full Code Here

TOP

Related Classes of org.openid4java.message.Message

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.