Package org.openid4java.message

Examples of org.openid4java.message.AuthRequest


        }

        DiscoveryInformation information = consumerManager.associate(discoveries);
        req.getSession().setAttribute(DISCOVERY_INFO_KEY, information);

        AuthRequest authReq;

        try {
            authReq = consumerManager.authenticate(information, returnToUrl, realm);

            logger.debug("Looking up attribute fetch list for identifier: " + identityUrl);

            List<OpenIDAttribute> attributesToFetch = attributesToFetchFactory.createAttributeList(identityUrl);

            if (!attributesToFetch.isEmpty()) {
                req.getSession().setAttribute(ATTRIBUTE_LIST_KEY, attributesToFetch);
                FetchRequest fetchRequest = FetchRequest.createFetchRequest();
                for (OpenIDAttribute attr : attributesToFetch) {
                    if (logger.isDebugEnabled()) {
                        logger.debug("Adding attribute " + attr.getType() + " to fetch request");
                    }
                    fetchRequest.addAttribute(attr.getName(), attr.getType(), attr.isRequired(), attr.getCount());
                }
                authReq.addExtension(fetchRequest);
            }
        } catch (MessageException e) {
            throw new OpenIDConsumerException("Error processing ConsumerManager authentication", e);
        } catch (ConsumerException e) {
            throw new OpenIDConsumerException("Error processing ConsumerManager authentication", e);
        }

        return authReq.getDestinationUrl(true);
    }
View Full Code Here


    public ConstructedRequest constructRequest(String providerId, String responseUrl) throws OpenIdException {
        String discoveryId = getDiscoveryId(providerId);

        DiscoveryInformation discoveryInfo = getDiscoveryInfo(discoveryId, providerId);

        AuthRequest request = createRequest(discoveryInfo, responseUrl);

        addExtensions(request, discoveryInfo, providerId, discoveryId);

        return createConstructedRequest(request, discoveryInfo, providerId, discoveryId);
    }
View Full Code Here

         openIdRequest.setDiscoveryInformation(discovered);

         String openIdServiceUrl = relyingPartyBean.getServiceURL(OpenIdService.OPEN_ID_SERVICE);
         String realm = relyingPartyBean.getRealm();
         String returnTo = openIdServiceUrl + "?dialogueId=" + dialogue.get().getId();
         AuthRequest authReq = openIdConsumerManager.authenticate(discovered, returnTo, realm);

         if (attributes != null && attributes.size() > 0)
         {
            FetchRequest fetch = FetchRequest.createFetchRequest();
            for (OpenIdRequestedAttribute attribute : attributes)
            {
               fetch.addAttribute(attribute.getAlias(), attribute.getTypeUri(), attribute.isRequired());
            }
            // attach the extension to the authentication request
            authReq.addExtension(fetch);
         }

         String url = authReq.getDestinationUrl(true);

         responseHandler.sendHttpRedirectToUserAgent(url, response);
      }
      catch (OpenIDException e)
      {
View Full Code Here

         openIdProviderRequest.get().setClaimedIdentifier(claimedIdentifier);

         MessageExtension ext = null;
         try
         {
            AuthRequest authReq = AuthRequest.createAuthRequest(parameterList, openIdServerManager.get().getRealmVerifier());
            if (authReq.hasExtension(AxMessage.OPENID_NS_AX))
            {
               ext = authReq.getExtension(AxMessage.OPENID_NS_AX);
            }
         }
         catch (MessageException e)
         {
            throw new RuntimeException(e);
View Full Code Here

                // fullReturnTo += "?" + SignIn.keyNextURL + "=" +
                //     URLEncoder.encode(nextURL, "utf-8");
            } catch(Exception ex) {
                System.err.println("parameter next cannot be url encoded.");
            }
            AuthRequest authReq = manager.authenticate(discovered, fullReturnTo);

            session.setAttribute(OPENID_CLAIMED_ID_SESSION, openid);

            /* add those extensions you want to test */
            if( bypassSRE == false )
                authReq.addExtension(sreg);
            if( bypassAX == false )
                authReq.addExtension(fetch);

            logger.info("Redirects to URL:" + authReq.getDestinationUrl(true));
            response.sendRedirect(authReq.getDestinationUrl(true));
        } catch (Exception e) {
            logger.severe(e.toString());
            succ = false;
        }

View Full Code Here

        }
        return ret;
    }
   
    public static AuthRequest createOpenIdAuthRequest(final DiscoveryInformation discoveryInformation, final String returnToUrl, final String endpoint) {
        AuthRequest ret = null;
        //
        try {
            // Create the AuthRequest object
            ret = getConsumerManager().authenticate(discoveryInformation, returnToUrl);
           
            final FetchRequest fetch = FetchRequest.createFetchRequest();
            if (endpoint.startsWith(GOOGLE_ENDPOINT)) {
                fetch.addAttribute("email", "http://axschema.org/contact/email", true);
                fetch.addAttribute("FirstName", "http://axschema.org/namePerson/first", true);
                fetch.addAttribute("LastName", "http://axschema.org/namePerson/last", true);
            } else if (endpoint.startsWith(YAHOO_ENDPOINT)) {
                fetch.addAttribute("email", "http://axschema.org/contact/email", true);
                fetch.addAttribute("Fullname", "http://axschema.org/namePerson", true);
            }
            ret.addExtension(fetch);
        } catch (Exception e) {
            final String message = "Exception occurred while building "
                    + "AuthRequest object!";
            throw new RuntimeException(message, e);
        }
View Full Code Here

    protected void doPost(final HttpServletRequest request, final HttpServletResponse response)
            throws ServletException, IOException {
        final String url = request.getParameter("openid");
        final DiscoveryInformation discoveryInformation = performDiscoveryOnUserSuppliedIdentifier(url);
        final InetAddress myLocalHost = InetAddress.getLocalHost();
        final AuthRequest authRequest = createOpenIdAuthRequest(discoveryInformation, "http://" + myLocalHost.getHostAddress() + ":8080/Software_Engineering_C/openid", url);
        response.sendRedirect(authRequest.getDestinationUrl(true));
    }
View Full Code Here

            AuthRequestHelper helper = consumerHelper.getAuthRequestHelper(openId,
                    request.getReturnUrl());
            addAttributes(helper, request);

            HttpSession session = request.getRequest().getSession();
            AuthRequest authReq = helper.generateRequest();

            UiMessageRequest uiExtension = new UiMessageRequest();
            uiExtension.setIconRequest(true);
            authReq.addExtension(uiExtension);

            session.setAttribute(IdentityConstants.OpenId.DISC, helper.getDiscoveryInformation());

            if (request.getRealm() != null && request.getRealm().trim().length() != 0) {
                authReq.setRealm(request.getRealm());
            }

            for (String type : request.getRequestTypes()) {
                authReq.addExtension(OpenIDExtensionFactory.getInstance().getExtension(type)
                        .getMessageExtension(request));
            }

            // Redirect to the OpenID provider server for authentication.
            String value = authReq.getDestinationUrl(true);
            return value;
        } catch (Exception e) {
            log.error(e.getMessage(), e);
            // Present error to the user
            throw new IdentityException(e.getMessage(), e);
View Full Code Here

  public AuthRequest generateRequest() throws DiscoveryException,
      MessageException, ConsumerException {
    DiscoveryInformation discovered = getDiscoveryInformation();

    // this a standard OpenID request
    AuthRequest authReq =
      consumerManager.authenticate(discovered, returnToUrl, null);
    if (axFetchRequest != null) {
      authReq.addExtension(axFetchRequest);
    }

    if (hybridOauthRequest != null) {
      authReq.addExtension(hybridOauthRequest);
    }

    if (uiRequest != null) {
      authReq.addExtension(uiRequest);
    }

    log.info(authReq);
    return authReq;
  }
View Full Code Here

    if (YES_STRING.equals(req.getParameter("lastName"))) {
      helper.requestAxAttribute(Step2.AxSchema.LAST_NAME, true);
    }

    HttpSession session = req.getSession();
    AuthRequest authReq = null;
    try {
      authReq = helper.generateRequest();
      authReq.setRealm(realm);
      session.setAttribute("discovered", helper.getDiscoveryInformation());
    } catch (DiscoveryException e) {
      throw new ServletException(e);
    } catch (MessageException e) {
      throw new ServletException(e);
    } catch (ConsumerException e) {
      throw new ServletException(e);
    }
    if (YES_STRING.equals(req.getParameter("usePost"))) {
      // using POST
      req.setAttribute("message", authReq);
      RequestDispatcher d =
        req.getRequestDispatcher("/WEB-INF/formredirection.jsp");
      d.forward(req, resp);
    } else {
      // using GET
      resp.sendRedirect(authReq.getDestinationUrl(true));
    }
  }
View Full Code Here

TOP

Related Classes of org.openid4java.message.AuthRequest

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.