Package org.openid4java.discovery

Examples of org.openid4java.discovery.DiscoveryInformation


            discoveries = consumerManager.discover(identityUrl);
        } catch (DiscoveryException e) {
            throw new OpenIDConsumerException("Error during discovery", e);
        }

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

        AuthRequest authReq;

        try {
View Full Code Here


        // extract the parameters from the authentication response
        // (which comes in as a HTTP request from the OpenID provider)
        ParameterList openidResp = new ParameterList(request.getParameterMap());

        // retrieve the previously stored discovery information
        DiscoveryInformation discovered = (DiscoveryInformation) request.getSession().getAttribute(DISCOVERY_INFO_KEY);

        if (discovered == null) {
            throw new OpenIDConsumerException("DiscoveryInformation is not available. Possible causes are lost session or replay attack");
        }

        List<OpenIDAttribute> attributesToFetch = (List<OpenIDAttribute>) request.getSession().getAttribute(ATTRIBUTE_LIST_KEY);

        request.getSession().removeAttribute(DISCOVERY_INFO_KEY);
        request.getSession().removeAttribute(ATTRIBUTE_LIST_KEY);

        // extract the receiving URL from the HTTP request
        StringBuffer receivingURL = request.getRequestURL();
        String queryString = request.getQueryString();

        if (StringUtils.hasLength(queryString)) {
            receivingURL.append("?").append(request.getQueryString());
        }

        // verify the response
        VerificationResult verification;

        try {
            verification = consumerManager.verify(receivingURL.toString(), openidResp, discovered);
        } catch (MessageException e) {
            throw new OpenIDConsumerException("Error verifying openid response", e);
        } catch (DiscoveryException e) {
            throw new OpenIDConsumerException("Error verifying openid response", e);
        } catch (AssociationException e) {
            throw new OpenIDConsumerException("Error verifying openid response", e);
        }

        // examine the verification result and extract the verified identifier
        Identifier verified = verification.getVerifiedId();

        if (verified == null) {
            Identifier id = discovered.getClaimedIdentifier();
            return new OpenIDAuthenticationToken(OpenIDAuthenticationStatus.FAILURE,
                    id == null ? "Unknown" : id.getIdentifier(),
                    "Verification status message: [" + verification.getStatusMsg() + "]",
                    Collections.<OpenIDAttribute>emptyList());
        }
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);
View Full Code Here

         // extract the parameters from the authentication response
         // (which comes in as a HTTP request from the OpenID provider)
         ParameterList parameterList = new ParameterList(httpRequest.getParameterMap());

         // retrieve the previously stored discovery information
         DiscoveryInformation discovered = openIdRequest.getDiscoveryInformation();
         if (discovered == null)
         {
            throw new IllegalStateException("No discovery information found in OpenID request");
         }        

         // extract the receiving URL from the HTTP request
         StringBuffer receivingURL = httpRequest.getRequestURL();
         String queryString = httpRequest.getQueryString();
         if (queryString != null && queryString.length() > 0)
            receivingURL.append("?").append(httpRequest.getQueryString());

         // verify the response; ConsumerManager needs to be the same
         // (static) instance used to place the authentication request
         VerificationResult verification = openIdConsumerManager.verify(
               receivingURL.toString(), parameterList, discovered);

         // examine the verification result and extract the verified identifier
         Identifier identifier = verification.getVerifiedId();

         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);

            openIdRelyingPartySpi.get().loginSucceeded(principal,
                  responseHandler.createResponseHolder(httpResponse));
         }
         else
View Full Code Here

      try
      {
         @SuppressWarnings("unchecked")
         List<DiscoveryInformation> discoveries = openIdConsumerManager.discover(openId);

         DiscoveryInformation discovered = openIdConsumerManager.associate(discoveries);

         openIdRequest.setDiscoveryInformation(discovered);

         String openIdServiceUrl = relyingPartyBean.getServiceURL(OpenIdService.OPEN_ID_SERVICE);
         String realm = relyingPartyBean.getRealm();
View Full Code Here

            /* Do the actual work */
            logger.info("Starting OpenID provider discovery.");
            List discoveries = manager.discover(openid);
            logger.info("Discovered OpenID provider");
            DiscoveryInformation discovered = manager.associate(discoveries);
            logger.info("Associate a URL.");
            HttpSession session = request.getSession(true);
            session.setAttribute("discovered", discovered);
            openidVersion = discovered.getVersion();
            logger.info("OpenId version " + openidVersion);

            String nextURL      = request.getParameter(SignIn.keyNextURL);
            String fullReturnTo = returnTo;
            try {
View Full Code Here

    public void parseAuthResponse(HttpServletRequest request, HttpServletResponse response){
        try {
            HttpSession session = request.getSession();
            ParameterList openidResp = new ParameterList(request.getParameterMap());
           
            DiscoveryInformation discovered = (DiscoveryInformation)session.getAttribute("discovered");
            session.removeAttribute("discovered");

            StringBuffer receivingURL = request.getRequestURL();
            String queryString = request.getQueryString();
            if( queryString != null && queryString.length() > 0 )
View Full Code Here

        }
        return consumerManager;
    }
   
    public static DiscoveryInformation performDiscoveryOnUserSuppliedIdentifier(final String userSuppliedIdentifier) {
        DiscoveryInformation ret = null;
        consumerManager = getConsumerManager();
        try {
            // Perform discover on the User-Supplied Identifier
            final List<DiscoveryInformation> discoveries =
                    consumerManager.discover(userSuppliedIdentifier);
View Full Code Here

        try {
            // extract the parameters from the authentication response
            // (which comes in as a HTTP request from the OpenID provider)
            final ParameterList response = new ParameterList(request.getParameterMap());
            // retrieve the previously stored discovery information
            final DiscoveryInformation discovered = (DiscoveryInformation) request.getSession().getAttribute("openid-disc");

            // extract the receiving URL from the HTTP request
            final StringBuffer receivingURL = request.getRequestURL();
            final String queryString = request.getQueryString();
            if (queryString != null && queryString.length() > 0) {
View Full Code Here

     */
    @Override
    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

TOP

Related Classes of org.openid4java.discovery.DiscoveryInformation

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.