Package org.openid4java.message

Examples of org.openid4java.message.Message


        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 void handleIncomingMessage(HttpServletRequest httpRequest, HttpServletResponse httpResponse) throws InvalidRequestException {
        ParameterList parameterList = new ParameterList(httpRequest.getParameterMap());

        String mode = parameterList.getParameterValue("openid.mode");

        Message associationResponse;

        if ("associate".equals(mode)) {
            associationResponse = openIdServerManager.get().associationResponse(parameterList);
            writeMessageToResponse(associationResponse, httpResponse);
        } else if ("checkid_setup".equals(mode) || "checkid_immediate".equals(mode)) {
View Full Code Here

        String claimedIdentifier = openIdProviderRequest.get().getClaimedIdentifier();
        if (claimedIdentifier.equals(AuthRequest.SELECT_ID)) {
            claimedIdentifier = opLocalIdentifier;
        }

        Message authResponse;

        if (response instanceof DirectError) {
            authResponse = openIdServerManager.get().authResponse(parameterList, opLocalIdentifier, claimedIdentifier, authenticationSuccesful, true);                    
            writeMessageToResponse(authResponse, response);
        } else {
            // We cannot sign the message before we add the extension
            authResponse = openIdServerManager.get().authResponse(parameterList, opLocalIdentifier, claimedIdentifier, authenticationSuccesful, false);
           
            if (openIdProviderRequest.get().getRequestedAttributes() != null) {
                try {
                    FetchResponse fetchResponse = FetchResponse.createFetchResponse(openIdProviderRequest.get().getFetchRequest(), attributeValues);
                    authResponse.addExtension(fetchResponse);
                } catch (MessageException e) {
                    throw new RuntimeException(e);
                }
            }
           
            try {
                openIdServerManager.get().sign((AuthSuccess)authResponse);
            } catch (ServerException e) {
                throw new RuntimeException(e);
            } catch (AssociationException e) {
                throw new RuntimeException(e);
            }

            // caller will need to decide which of the following to use:

            // option1: GET HTTP-redirect to the return_to URL
            String destinationUrl = authResponse.getDestinationUrl(true);
            responseHandler.sendHttpRedirectToUserAgent(destinationUrl, response);

            // option2: HTML FORM Redirection
            // RequestDispatcher dispatcher =
            // getServletContext().getRequestDispatcher("formredirection.jsp");
View Full Code Here

        Identifier id = new Identifier() {
            public String getIdentifier() {
                return "id";
            }
        };
        Message msg = mock(Message.class);

        when(mgr.verify(anyString(), any(ParameterList.class), any(DiscoveryInformation.class))).thenReturn(vr);
        when(vr.getVerifiedId()).thenReturn(id);
        when(vr.getAuthResponse()).thenReturn(msg);
View Full Code Here

    }

    @Test
    public void fetchAttributesReturnsExpectedValues() throws Exception {
        OpenID4JavaConsumer consumer = new OpenID4JavaConsumer(new NullAxFetchListFactory());
        Message msg = mock(Message.class);
        FetchResponse fr = mock(FetchResponse.class);
        when(msg.hasExtension(AxMessage.OPENID_NS_AX)).thenReturn(true);
        when(msg.getExtension(AxMessage.OPENID_NS_AX)).thenReturn(fr);
        when(fr.getAttributeValues("a")).thenReturn(Arrays.asList("x","y"));

        List<OpenIDAttribute> fetched = consumer.fetchAxAttributes(msg, attributes);

        assertEquals(1, fetched.size());
View Full Code Here

    }

    @Test(expected = OpenIDConsumerException.class)
    public void messageExceptionFetchingAttributesRaisesOpenIDException() throws Exception {
        OpenID4JavaConsumer consumer = new OpenID4JavaConsumer(new NullAxFetchListFactory());
        Message msg = mock(Message.class);
        FetchResponse fr = mock(FetchResponse.class);
        when(msg.hasExtension(AxMessage.OPENID_NS_AX)).thenReturn(true);
        when(msg.getExtension(AxMessage.OPENID_NS_AX)).thenThrow(new MessageException(""));
        when(fr.getAttributeValues("a")).thenReturn(Arrays.asList("x","y"));

        consumer.fetchAxAttributes(msg, attributes);
    }
View Full Code Here

   {
      ParameterList parameterList = new ParameterList(httpRequest.getParameterMap());

      String mode = parameterList.getParameterValue("openid.mode");

      Message associationResponse;

      if ("associate".equals(mode))
      {
         associationResponse = openIdServerManager.get().associationResponse(parameterList);
         writeMessageToResponse(associationResponse, httpResponse);
View Full Code Here

      if (claimedIdentifier.equals(AuthRequest.SELECT_ID))
      {
         claimedIdentifier = opLocalIdentifier;
      }

      Message authResponse = openIdServerManager.get().authResponse(parameterList, opLocalIdentifier, claimedIdentifier, authenticationSuccesful);

      if (response instanceof DirectError)
      {
         writeMessageToResponse(authResponse, response);
      }
      else
      {
         if (openIdProviderRequest.get().getRequestedAttributes() != null)
         {
            try
            {
               FetchResponse fetchResponse = FetchResponse.createFetchResponse(openIdProviderRequest.get().getFetchRequest(), attributeValues);
               authResponse.addExtension(fetchResponse);
            }
            catch (MessageException e)
            {
               throw new RuntimeException(e);
            }
         }

         // caller will need to decide which of the following to use:

         // option1: GET HTTP-redirect to the return_to URL
         String destinationUrl = authResponse.getDestinationUrl(true);
         responseHandler.sendHttpRedirectToUserAgent(destinationUrl, response);

         // option2: HTML FORM Redirection
         // RequestDispatcher dispatcher =
         // getServletContext().getRequestDispatcher("formredirection.jsp");
View Full Code Here

     * @throws MessageException
     */
    protected OMElement createOpenIdToken(OMElement rstrElem) throws IdentityProviderException {
        OMElement rdt = null;
        OpenIDInfoCardToken token = null;
        Message message = null;
        ParameterList params = null;
        String claimID = null;
        OpenIDInfoCardHeader header = null;

        rdt = IdentityProviderUtil.createOpenIdToken(rstrElem, ipData);
View Full Code Here

    return getExtension(HybridOauthResponse.class,
        HybridOauthMessage.OPENID_NS_OAUTH);
  }

  public Class<? extends AxMessage> getAxExtensionType() throws MessageException {
    Message resp = getAuthResponse();
    if (resp.hasExtension(AxMessage2.OPENID_NS_AX_FINAL)) {
      MessageExtension extension =
        resp.getExtension(AxMessage2.OPENID_NS_AX_FINAL);
      if (extension instanceof FetchResponse) {
        return FetchResponse.class;
      }
    }
    return null;
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.