Package com.dyuproject.openid

Examples of com.dyuproject.openid.RelyingParty


     */
    public AuthenticationInfo extractCredentials(HttpServletRequest request,
            HttpServletResponse response) {

        try {
            final RelyingParty relyingParty = getRelyingParty(request);

            // this may throw a ClassCastException after an update of the
            // bundle if the HTTP Session object still holds on to an
            // OpenIdUser instance created by the old bundle.
            final OpenIdUser user = discover(relyingParty, request);

            // no OpenID user in the request, check whether this is an
            // OpenID response at all
            if (user == null) {

                if (RelyingParty.isAuthResponse(request)) {

                    log.debug("OpenID authentication timeout");
                    response.sendRedirect(request.getRequestURI());
                    return AuthenticationInfo.DOING_AUTH;

                } else if (RelyingParty.isAuthCancel(request)) {

                    log.info("OpenID authentication cancelled by user");
                    return handleAuthFailure(OpenIDFailure.AUTHENTICATION,
                        request);
                }

                // check whether the request has an OpenID identifier
                // request parameter not leading to a valid OpenID
                // transaction; fail authentication in this case
                final String identifier = request.getParameter(identifierParam);
                if (identifier != null) {
                    log.info("OpenID authentication failed (probably failed to discover OpenID Provider)");
                    return handleAuthFailure(OpenIDFailure.DISCOVERY, request);
                }

            } else if (user.isAuthenticated()) {

                // user already authenticated
                return getAuthInfoFromUser(user);

            } else if (user.isAssociated()) {

                if (RelyingParty.isAuthResponse(request)) {

                    if (relyingParty.verifyAuth(user, request, response)) {
                        // authenticated
                        response.sendRedirect(getReturnToResource(request));
                        return AuthenticationInfo.DOING_AUTH;
                    }

                    // failed verification
                    return handleAuthFailure(OpenIDFailure.VERIFICATION,
                        request);

                }

                // Assume a cancel or some other non-successful response
                // from provider failed verification
                relyingParty.invalidate(request, response);

                return handleAuthFailure(OpenIDFailure.AUTHENTICATION, request);

            } else {

                // associate and authenticate user

                // prepare the url for the return_to parameter
                final String url = getBaseUrl(request);

                // set the realm/trustroot from configuration or the root url
                final String trustRoot = (realm == null) ? url : realm;

                // append the resource URL to the returnTo address
                final String returnTo = url + getReturnToPath(request);

                if (relyingParty.associateAndAuthenticate(user, request,
                    response, trustRoot, trustRoot, returnTo)) {
                    // user is associated and then redirected to his openid
                    // provider for authentication
                    return AuthenticationInfo.DOING_AUTH;
                }
View Full Code Here


        }


        // requestAuthentication is only called after a failedauthentication
        // so it makes sense to remove any existing login
        final RelyingParty relyingParty = getRelyingParty(request);
        relyingParty.invalidate(request, response);

        HashMap<String, String> params = new HashMap<String, String>();
        params.put(Authenticator.LOGIN_RESOURCE,
            getLoginResource(request, null));
View Full Code Here

        "https://open.login.yahooapis.com/openid/op/auth");
        request.setAttribute(OpenIdUser.ATTR_NAME, user);
      }
    }

    RelyingParty relyingParty = RelyingParty.getInstance();

    String errorMsg = OpenIdServletFilter.DEFAULT_ERROR_MSG;
    try {
      OpenIdUser user = relyingParty.discover(request);
      if (user == null) {
        if (RelyingParty.isAuthResponse(request)) {
          // authentication timeout
          response.sendRedirect(request.getRequestURI());
        } else {
          // set error msg if the openid_identifier is not resolved.
          if (request.getParameter(relyingParty.getIdentifierParameter()) != null) {
            request.setAttribute(OpenIdServletFilter.ERROR_MSG_ATTR, errorMsg);
          }

          // TODO: Simply close the window? Alert?
          request.getRequestDispatcher(CLOSE_POPUP_URI).forward(request, response);
        }
        return;
      }

      if (user.isAuthenticated()) {
        // user already authenticated
        request.getRequestDispatcher(CLOSE_POPUP_URI).forward(request, response);
        return;
      }

      if (user.isAssociated() && RelyingParty.isAuthResponse(request)) {
        // verify authentication
        if (relyingParty.verifyAuth(user, request, response)) {
          // authenticated
          userDAO.get().setSessionUser(user);

          // redirect to home to remove the query params instead of doing:
          request.getRequestDispatcher(CLOSE_POPUP_URI).forward(request, response);
        } else {
          // failed verification

          // TODO: Simply close the window? Alert?
          request.getRequestDispatcher(CLOSE_POPUP_URI).forward(request, response);
        }
        return;
      }

      // associate and authenticate user
      StringBuffer url = request.getRequestURL();
      String trustRoot = url.substring(0, url.indexOf("/", 9));
      String realm = url.substring(0, url.lastIndexOf("/"));
      String returnTo = url.toString();
      if (relyingParty.associateAndAuthenticate(user, request, response, trustRoot, realm,
          returnTo)) {
        return;
      }
    } catch (UnknownHostException uhe) {
      System.err.println("not found");
View Full Code Here

TOP

Related Classes of com.dyuproject.openid.RelyingParty

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.