Package com.dyuproject.openid

Examples of com.dyuproject.openid.OpenIdUser


    public AuthenticationPlugin getAuthentication(final Principal principal,
            final Credentials creds) {
        return new AuthenticationPlugin() {
            public boolean authenticate(Credentials credentials)
                    throws RepositoryException {
                OpenIdUser user = authHandler.getOpenIdUser(credentials);
                if (user != null) {
                    return user.isAssociated();
                }
                throw new RepositoryException(
                    "Can't authenticate credentials of type: "
                        + credentials.getClass());
            }
View Full Code Here


            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
View Full Code Here

         * which could not be mapped to a valid repository user !!
         *
         * invalidate the curren OpenID user and set a failure reason
         */

        OpenIdUser user = null;
        try {
            user = getRelyingParty(request).discover(request);
        } catch (Exception e) {
            // don't care ...
        }

        dropCredentials(request, response);

        request.setAttribute(OpenIDConstants.OPENID_FAILURE_REASON,
            OpenIDFailure.REPOSITORY);

        if (user != null && user.getIdentity() != null) {
            request.setAttribute(OpenIDConstants.OPENID_IDENTITY,
                user.getIdentity());
        }
    }
View Full Code Here

            // If the ui supplies a LoginWithGoogle or LoginWithYahoo link/button,
            // this will speed up the openid process by skipping discovery.
            // The override is done by adding the OpenIdUser to the request attribute.
            if(loginWith.equals("google"))
            {
                OpenIdUser user = OpenIdUser.populate("https://www.google.com/accounts/o8/id",
                        YadisDiscovery.IDENTIFIER_SELECT,
                        "https://www.google.com/accounts/o8/ud");
                request.setAttribute(OpenIdUser.ATTR_NAME, user);
               
            }
            else if(loginWith.equals("yahoo"))
            {
                OpenIdUser user = OpenIdUser.populate("http://yahoo.com/",
                        YadisDiscovery.IDENTIFIER_SELECT,
                        "https://open.login.yahooapis.com/openid/op/auth");
                request.setAttribute(OpenIdUser.ATTR_NAME, user);
            }
        }
       
        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);
                   
                    // new user
                    request.getRequestDispatcher("/login.jsp").forward(request, response);
                }
                return;
            }
           
            if(user.isAuthenticated())
            {
                // user already authenticated
                request.getRequestDispatcher("/home.jsp").forward(request, response);
                return;
            }
           
            if(user.isAssociated() && RelyingParty.isAuthResponse(request))
            {
                // verify authentication
                if(_relyingParty.verifyAuth(user, request, response))
                {
                    // authenticated                   
View Full Code Here

            return;
        }
       
        try
        {
            OpenIdUser user = _relyingParty.discover(request);
            if(user!=null)
            {
                if(user.isAuthenticated() ||
                        (user.isAssociated() && RelyingParty.isAuthResponse(request) &&
                                _relyingParty.verifyAuth(user, request, response)))
                {
                    response.setContentType("text/json");
                    response.getWriter().write(JSON.toString(user));
                    return;
View Full Code Here

            // invalid cookie.
            return null;
        }
       
        Map map = (Map)_json.parse(new StringSource(B64Code.decode(u)));
        OpenIdUser user = new OpenIdUser();
        user.fromJSON(map);
        return user;
    }
View Full Code Here

            e.printStackTrace();
            return null;
        }
       
        Map map = (Map)_json.parse(new StringSource(value));
        OpenIdUser user = new OpenIdUser();
        user.fromJSON(map);
        return user;
    }
View Full Code Here

        if (loginWith != null) {
            // If the ui supplies a LoginWithGoogle or LoginWithYahoo link/button,
            // this will speed up the openid process by skipping discovery.
            // The override is done by adding the OpenIdUser to the request attribute.
            if (loginWith.equals("google")) {
                OpenIdUser user = OpenIdUser.populate("https://www.google.com/accounts/o8/id",
                        YadisDiscovery.IDENTIFIER_SELECT,
                        "https://www.google.com/accounts/o8/ud");
                request.setAttribute(OpenIdUser.ATTR_NAME, user);

            } else if (loginWith.equals("yahoo")) {
                OpenIdUser user = OpenIdUser.populate("http://yahoo.com/",
                        YadisDiscovery.IDENTIFIER_SELECT,
                        "https://open.login.yahooapis.com/openid/op/auth");
                request.setAttribute(OpenIdUser.ATTR_NAME, user);
            }
        }

        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 error pages, massage not passed to front end
                        // request.getRequestDispatcher("/home/error.html").forward(request, response);
                        response.sendRedirect(request.getContextPath() + "/home/error.html");
                    } else {
                        // new user
                        //request.getRequestDispatcher("/home/login.html").forward(request, response);
                        response.sendRedirect(request.getContextPath() + "/home/login.html");
                    }
                }
                return;
            }

            if (user.isAuthenticated()) {
                // user already authenticated
                // request.getRequestDispatcher("/home/home.jsp").forward(request, response);
                //added by suho
                // the original entry
                if (request.getSession().getAttribute(USER_NEED_TO_REGISTER) != null
                        && request.getSession().getAttribute(USER_NEED_TO_REGISTER).equals("true")) {
                    // for registering purposes
                    //  request.getRequestDispatcher("/home/registration.html").forward(request, response);
                    response.sendRedirect(request.getContextPath() + "/home/registration.html");
                } else if (request.getSession().getAttribute(USER_NEED_TO_REGISTER) != null
                        && request.getSession().getAttribute(USER_NEED_TO_REGISTER).equals("blocked")) {

                    // for registering purposes
                    //  request.getRequestDispatcher("/home/registration.html").forward(request, response);
                    response.sendRedirect(request.getContextPath() + "/logout");
                } else {
//                    if (request.getSession().getAttribute("accessList") != null) {
//                        AccessList accessList = (AccessList) request.getSession().getAttribute("accessList");
//                        if (accessList.getUserId().equals("UnRegisteredUser")) {
//                            response.sendRedirect(request.getContextPath() + "/logout");
//                            return;
//                        }
//                    }
                    response.sendRedirect(request.getContextPath() + "/admin/upload.html");
                }

                return;
            }

            if (user.isAssociated() && RelyingParty.isAuthResponse(request)) {
                // verify authentication
                if (_relyingParty.verifyAuth(user, request, response)) {
                    // authenticated                   
                    // redirect to home to remove the query params instead of doing:
                    // request.getRequestDispatcher("/home.jsp").forward(request, response);
View Full Code Here

    if (provider != null) {
      // If the ui supplies a number of buttons for default providers.
      // This will speed up the openid process by skipping discovery.
      // The override is done by adding the OpenIdUser to the request attribute.
      if (provider.equals("google")) {
        OpenIdUser user = OpenIdUser.populate("https://www.google.com/accounts/o8/id",
            YadisDiscovery.IDENTIFIER_SELECT,
        "https://www.google.com/accounts/o8/ud");
        request.setAttribute(OpenIdUser.ATTR_NAME, user);
      } else if (provider.equals("yahoo")) {
        OpenIdUser user = OpenIdUser.populate("http://yahoo.com/",
            YadisDiscovery.IDENTIFIER_SELECT,
        "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);
View Full Code Here

        return _relyingParty;
    }

    public OpenId verifyOpenIdResponse(HttpServletRequest request) {
        try {
            OpenIdUser user = _relyingParty.discover(request);
            if (user == null) {
                log.debug("Failed login");
                return null;
            }
            if (user.isAuthenticated()) {
                log.debug("user already authenticated");
                return new OpenId(user.getClaimedId());
            }
            if (user.isAssociated() && RelyingParty.isAuthResponse(request)) {
                log.debug("Verify");
                if (_relyingParty.verifyAuth(user, request, null)) {
                    log.debug("authenticated");
                    _relyingParty.invalidate(request, null); // clear
                    return new OpenId(user.getClaimedId());
                } else {
                    log.debug("failed verification");
                    return null;
                }
            }
View Full Code Here

TOP

Related Classes of com.dyuproject.openid.OpenIdUser

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.