Package org.openid4java.message.ax

Examples of org.openid4java.message.ax.FetchResponse


   * @throws MessageException
   */
  private void receiveAttributeExchange(HttpServletRequest httpReq,
      AuthSuccess authSuccess) throws MessageException {
    if (authSuccess.hasExtension(AxMessage.OPENID_NS_AX)) {
      FetchResponse fetchResp = (FetchResponse) authSuccess
          .getExtension(AxMessage.OPENID_NS_AX);

      // List emails = fetchResp.getAttributeValues("email");
      // String email = (String) emails.get(0);

      List aliases = fetchResp.getAttributeAliases();
      Map attributes = new LinkedHashMap();
      for (Iterator iter = aliases.iterator(); iter.hasNext();) {
        String alias = (String) iter.next();
        List values = fetchResp.getAttributeValues(alias);
        if (values.size() > 0) {
          String[] arr = new String[values.size()];
          values.toArray(arr);
          attributes.put(alias, StringUtils.join(arr));
        }
View Full Code Here


            identifier = verified.getIdentifier();
        }

        AuthSuccess authSuccess = (AuthSuccess) authResponse;

        FetchResponse fetchResp = null;

        Map<String,String> attributes = new LinkedHashMap<String,String>();

        MessageExtension ext;
        if ( authSuccess.hasExtension(AxMessage.OPENID_NS_AX) &&
             (ext = authSuccess.getExtension(AxMessage.OPENID_NS_AX)) instanceof FetchResponse)
        {
            fetchResp = (FetchResponse) ext;

            // extract the rest of the optional attributes
            List aliases = fetchResp.getAttributeAliases();
            Map types = fetchResp.getAttributeTypes();
            String alias;
            List values;
            for (Object a : aliases)
            {
                alias = (String) a;
                values = fetchResp.getAttributeValues(alias);
                attributes.put(_attributes.get(types.get(alias)),
                    values.size() > 0 ? (String) values.get(0) : null);
            }
        }
View Full Code Here

    }
  }


  private String extractEmailAddress(AuthSuccess authSuccess) throws MessageException {
    FetchResponse fetchResp = (FetchResponse) authSuccess.getExtension(AxMessage.OPENID_NS_AX);
    return getAttributeValue(
      fetchResp,
      "email",
      "",
      String.class);
View Full Code Here

      "",
      String.class);
  }

  private String extractFirstName(AuthSuccess authSuccess) throws MessageException {
    FetchResponse fetchResp = (FetchResponse) authSuccess.getExtension(AxMessage.OPENID_NS_AX);
    return getAttributeValue(
      fetchResp,
      "firstname",
      "",
      String.class);
View Full Code Here

      "",
      String.class);
  }

  private String extractLastName(AuthSuccess authSuccess) throws MessageException {
    FetchResponse fetchResp = (FetchResponse) authSuccess.getExtension(AxMessage.OPENID_NS_AX);
    return getAttributeValue(
      fetchResp,
      "lastname",
      "",
      String.class);
View Full Code Here

            // 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);
                }
            }
View Full Code Here

            if (identifier != null) {
                AuthSuccess authSuccess = (AuthSuccess) verification.getAuthResponse();

                Map<String, List<String>> attributeValues = null;
                if (authSuccess.hasExtension(AxMessage.OPENID_NS_AX)) {
                    FetchResponse fetchResp = (FetchResponse) authSuccess.getExtension(AxMessage.OPENID_NS_AX);
                    @SuppressWarnings("unchecked")
                    Map<String, List<String>> attrValues = fetchResp.getAttributes();
                    attributeValues = attrValues;
                }

                OpenIdPrincipal principal = createPrincipal(identifier.getIdentifier(),
                        discovered.getOPEndpoint(), attributeValues);
View Full Code Here

                AuthSuccess authSuccess =
                    (AuthSuccess) verification.getAuthResponse();
               
                System.out.println("*** EXT: " + authSuccess.getExtensions());
                if (authSuccess.hasExtension(AxMessage.OPENID_NS_AX)) {
                    FetchResponse fetchResp = (FetchResponse) authSuccess
                        .getExtension(AxMessage.OPENID_NS_AX);
                   
                    List emails = fetchResp.getAttributeValues("email");
                    String email = (String) emails.get(0);
                    System.out.println("XXX email is " + email);
                }
               
                return verified.getIdentifier();
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());
        assertEquals(2, fetched.get(0).getValues().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

TOP

Related Classes of org.openid4java.message.ax.FetchResponse

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.