Examples of OurException


Examples of com.example.GWTOAuthLoginDemo.client.exception.OurException

    private String getStateFromSession() throws OurException
    {
        HttpSession session = getHttpSession();
        if (session == null)
        {
            throw new OurException(ClientUtils.SESSION_EXPIRED_MESSAGE);
        }
        /*
        ServersideSession sss = getServersideSession();
        if (sss != null)
            return sss.getState();
View Full Code Here

Examples of com.example.GWTOAuthLoginDemo.client.exception.OurException

    private String getSessionIdFromSession() throws OurException
    {
        HttpSession session = getHttpSession();
        if (session == null)
        {
            throw new OurException(ClientUtils.SESSION_EXPIRED_MESSAGE);
        }
        /*
        ServersideSession sss = getServersideSession();
        if (sss != null)
            return sss.getSessionId();
View Full Code Here

Examples of com.example.GWTOAuthLoginDemo.client.exception.OurException

    private Token getRequestTokenFromSession() throws OurException
    {
        HttpSession session = getHttpSession();
        if (session == null)
        {
            throw new OurException(ClientUtils.SESSION_EXPIRED_MESSAGE);
        }
        /*
        ServersideSession sss = getServersideSession();
        if (sss != null)
            return sss.getRequestToken();
View Full Code Here

Examples of com.example.GWTOAuthLoginDemo.client.exception.OurException

            {
                accessToken = service.getAccessToken(requestToken,verifier);
                if (accessToken == null)
                {
                    logger.error("Could not get Access Token for " + authProviderName);
                    throw new OurException("Could not get Access Token");
                }
            }
            catch (Exception e)
            {
                logger.info("Exception received gettign Access Token: " + e);
                throw new OurException("Exception received getting Access Token: " + e);
            }
            logger.info("Got the access token: " + accessToken);
            logger.info(" Token: " + accessToken.getToken());
            logger.info(" Secret: " + accessToken.getSecret());
            logger.info(" Raw: " + accessToken.getRawResponse());
        }
        else
        {
            /*
            ** Default provider.
            ** The info will probably come from database. Password will
            ** probably some kind of salted hash. We're just hard coding
            ** "test" and "secret" for the demo.
            */
            logger.info("Handing default loign..");
            String username = credential.getLoginName();
            String password = credential.getPassword();
            if (username == null)
            {
                throw new OurException("Default Username can not be empty");
            }
            if (password == null)
            {
                throw new OurException("Default Password not be empty");
            }
            if (username.equals(getDefaultUsername()) && password.equals(getDefaultPassword()))
            {
               
            }
            else
            {
                throw new OurException("Please use " + getDefaultUsername() + "  and " + getDefaultPassword() + " as Default Credential!");
            }
           
           
        }
       
        if (authProvider == ClientUtils.INSTAGRAM)
        {
            try
            {
                instragramToken = InstragramToken.parse(accessToken.getRawResponse());
            } catch (ParseException e)
            {
                throw new OurException("Could not parse " + authProviderName + " Json AccessToken");
            }
            logger.info("Getting Instragram Access Token");
            logger.info(" access token" + instragramToken.getAcessToken());
            logger.info(" userId: " + instragramToken.getUserId());
            logger.info(" full name: " + instragramToken.getFullName());
            logger.info(" username: " + instragramToken.getFullName());
            logger.info(" raw: " + instragramToken.getRawResponse());
           
            // replace userId and access token in protected resource url
            protectedResourceUrl = ClientUtils.getProctedResourceUrl(authProvider);
            logger.info("Instragram protected resource url: " + protectedResourceUrl);
            protectedResourceUrl = String.format(protectedResourceUrl, instragramToken.getUserId(),instragramToken.getAcessToken());
            logger.info("Instragram protected resource url: " + protectedResourceUrl);
        }
       
        if (authProvider == ClientUtils.GITHUB ||
            authProvider == ClientUtils.FOURSQUARE)
        {
            protectedResourceUrl = String.format(protectedResourceUrl,accessToken.getToken());
        }
       
       
        if (authProvider == ClientUtils.YAHOO)
        {
            //throw new OurException("Not implemented for yahoo yet!)");
            /* we need to replace <GUID> */
            yahooGuid = getQueryStringValue(accessToken.getRawResponse(),"xoauth_yahoo_guid");
            if (yahooGuid == null)
            {
                throw new OurException("Could not get Yahoo GUID from Query String");
            }
            // must save it to session. we'll use to get the user profile
            saveYahooGuidToSession(yahooGuid);
           
            protectedResourceUrl = ClientUtils.getProctedResourceUrl(authProvider);
            protectedResourceUrl = String.format(protectedResourceUrl,yahooGuid);
            logger.info("Yahoo protected resource url: " + protectedResourceUrl);
                   
        }
       
        // make session id
        String sessionId = makeRandomString();
       
        // must save session id to session
        saveSessionIdToSession(sessionId);
       
        // must save authProvider to session
        saveAuthProviderToSession(authProvider);
       
        SocialUser socialUser = null;
        if (authProvider != ClientUtils.DEFAULT)
        {
            // must save acess token to session
            saveAccessTokenToSession(accessToken);
           
            // must save the protected resource url to session
            saveProtectedResourceUrlToSession(protectedResourceUrl);
           
            // now request protected resource
            logger.info("Getting protected resource");
            logger.info("Protected resource url: " + protectedResourceUrl);
            try
            {
                OAuthRequest request = new OAuthRequest(Verb.GET,protectedResourceUrl);
                service.signRequest(accessToken,request);
               
                Response response = request.send();
                logger.info("Status code: " + response.getCode());
                logger.info("Body: " + response.getBody());
               
                String json = response.getBody();
                socialUser = getSocialUserFromJson(json,authProvider);
            }
            catch(Exception e)
            {
                logger.error("Could not retrieve protected resource: " + e);
                throw new OurException("Could not retrieve protected resource: " + e);
            }
        }
        else
        {
            socialUser = new SocialUser();
View Full Code Here

Examples of com.example.GWTOAuthLoginDemo.client.exception.OurException

    private Token getAccessTokenFromSession() throws OurException
    {
        HttpSession session = getHttpSession();
        if (session == null)
        {
            throw new OurException(ClientUtils.SESSION_EXPIRED_MESSAGE);
        }
        /*
        ServersideSession sss = getServersideSession();
        if (sss != null)
        {
View Full Code Here

Examples of com.example.GWTOAuthLoginDemo.client.exception.OurException

    private int getAuthProviderFromSession() throws OurException
    {
        HttpSession session = getHttpSession();
        if (session == null)
        {
            throw new OurException(ClientUtils.SESSION_EXPIRED_MESSAGE);
        }
        /*
        ServersideSession sss = getServersideSession();
        if (sss != null)
            return sss.getAuthProvider();
View Full Code Here

Examples of com.example.GWTOAuthLoginDemo.client.exception.OurException

                   
                    return socialUser;
                }
                catch (ParseException e)
                {
                  throw new OurException("Could not parse JSON data from " + authProviderName + ":" + e.getMessage());
                }
            }
               
            case ClientUtils.YAHOO:
            {
                /* --YAHOO--
                   http://developer.yahoo.com/social/rest_api_guide/extended-profile-resource.html#
                {
                     "profile": {
                       "uri": "http:\/\/social.yahooapis.com\/v1\/user\/ECUFIYO7BLY5FOV54XAPEQDC3Y\/profile",
                       "guid": "ECUFIYO7BLY5FOAPEQDC3Y",
                       "birthYear": 1969,
                       "created": "2010-01-23T13:07:10Z",
                       "displayAge": 89,
                       "gender": "M",
                       "image": {
                         "height": 192,
                         "imageUrl": "http:\/\/l.yimg.com\/a\/i\/identity2\/profile_192c.png",
                         "size": "192x192",
                         "width": 192
                       },
                       "location": "Philadelphia, Pennsylvania",
                       "memberSince": "2006-08-04T13:27:58Z",
                       "nickname": "jdoe",
                       "profileUrl": "http:\/\/profile.yahoo.com\/ECUFIYO7BLY5FOV54XAPEQDC3Y",
                       "searchable": false,
                       "updated": "2011-04-16T07:28:00Z",
                       "isConnected": false
                   }
               }
             */  
                try
                {
                    obj = jsonParser.parse(json);
                    JSONObject jsonObj = (JSONObject) obj;
                    // get profile object
                    JSONObject jsonObjPeople = (JSONObject) jsonObj.get("profile");
               
                    socialUser.setJson(json);
                   
                    socialUser.setNickname((String) jsonObjPeople.get("nickname"));
                    socialUser.setGender((String) jsonObjPeople.get("gender"));
                    socialUser.setFirstName((String) jsonObjPeople.get("givenName"));
                    socialUser.setLastName((String) jsonObjPeople.get("familyName"));
                   
                    return socialUser;
                }
                catch (ParseException e)
                {
                  throw new OurException("Could not parse JSON data from " + authProviderName + ":" + e.getMessage());
                }
            }
           
            case ClientUtils.GOOGLE:
            {
               /* --Google--
                {
                  "id": "116397076041912827850",
                  "name": "Muhammad Muquit",
                  "given_name": "Muhammad",
                  "family_name": "Muquit",
                  "link": "https://plus.google.com/116397076041912827850",
                  "gender": "male",
                  "locale": "en-US"
                }
               */
                try
                {
                    obj = jsonParser.parse(json);
                    JSONObject jsonObj = (JSONObject) obj;
               
                    socialUser.setJson(json);
               
                    socialUser.setName((String) jsonObj.get("name"));
                    socialUser.setFirstName((String) jsonObj.get("given_name"));
                    socialUser.setLastName((String) jsonObj.get("family_name"));
                    socialUser.setGender((String)jsonObj.get("gender"));
                   
                    return socialUser;
                }
                catch (ParseException e)
                {
                  throw new OurException("Could not parse JSON data from " + authProviderName + ":" + e.getMessage());
                }
            }
           
            case ClientUtils.LINKEDIN:
            {
                /* --Linkedin--
                {
                    "firstName": "Muhammad",
                    "headline": "Sr. Software Engineer at British Telecom",
                    "lastName": "Muquit",
                 }
                 */
                try
                {
                    obj = jsonParser.parse(json);
                    JSONObject jsonObj = (JSONObject) obj;
               
                    socialUser.setJson(json);
               
                    socialUser.setFirstName((String) jsonObj.get("firstName"));
                    socialUser.setLastName((String) jsonObj.get("lastName"));
                   
                    return socialUser;
                }
                catch (ParseException e)
                {
                  throw new OurException("Could not parse JSON data from " + authProviderName + ":" + e.getMessage());
                }
            }
           
            case ClientUtils.TWITTER:
            {
               /* --Twitter --
                {
                    "id":955924206,
                    "contributors_enabled":false,
                    "profile_use_background_image":true,
                    "time_zone":"Eastern Time (US & Canada)",
                    "following":false,
                    "friends_count":3,
                    "profile_text_color": "333333",
                    "geo_enabled":false,
                    "created_at":"Sun Nov 18 17:54:22 +0000 2012",
                    "utc_offset":-18000,
                    "follow_request_sent":false,
                    "name":"Muhammad Muquit",
                    "id_str":"955924206",
                    "default_profile_image":true,
                    "verified":false,
                    "profile_sidebar_border_color":"C0DEED",
                    "url":null,
                    "favourites_count":0,
                    ..
                    "lang":"en",
                    "profile_background_color":"C0DEED",
                    "screen_name":"mmqt2012",
                    ..
                  }
               */
               
                try
                {
                    obj = jsonParser.parse(json);
                    JSONObject jsonObj = (JSONObject) obj;
               
                    socialUser.setJson(json);
               
                    socialUser.setName((String) jsonObj.get("name"));
                    socialUser.setGender((String)jsonObj.get("gender"));
                   
                    return socialUser;
                }
                catch (ParseException e)
                {
                  throw new OurException("Could not parse JSON data from " + authProviderName + ":" + e.getMessage());
                }
            }
           
            case ClientUtils.INSTAGRAM:
            {
                /* -- Instragram --
                {
                    "data": {
                        "id": "1574083",
                        "username": "snoopdogg",
                        "full_name": "Snoop Dogg",
                        "profile_picture": "http://distillery.s3.amazonaws.com/profiles/profile_1574083_75sq_1295469061.jpg",
                        "bio": "This is my bio",
                        "website": "http://snoopdogg.com",
                        "counts": {
                            "media": 1320,
                            "follows": 420,
                            "followed_by": 3410
                        }
                }               
                */

                try
                {
                    logger.info("Instragram JSON: " + json);
                   obj = jsonParser.parse(json);
                    JSONObject jsonObj = (JSONObject) obj;
                    // get profile object
                    JSONObject jsonObjData = (JSONObject) jsonObj.get("data");
               
                    socialUser.setJson(json);
                    socialUser.setName((String) jsonObjData.get("username"));
                   
                    return socialUser;
                }
                catch (ParseException e)
                {
                  throw new OurException("Could not parse JSON data from " + authProviderName + ":" + e.getMessage());
                }
               
            }
           
            case ClientUtils.GITHUB:
            {
                /* -- github  --
                {
                    "plan":{
                       "private_repos":0,
                       "space":307200,
                       "name":"free",
                       "collaborators":0
                    },
                    "followers":0,
                    "type":"User",
                    "events_url":"https://api.github.com/users/oauthdemo2012/events{/privacy}",
                    "owned_private_repos":0,
                    "public_gists":0,
                    "avatar_url":"https://secure.gravatar.com/avatar/e0cb08c2b353cc1c3022dc65ebd060d1?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-user-420.png",
                    "received_events_url":"https://api.github.com/users/oauthdemo2012/received_events",
                    "private_gists":0,
                    "disk_usage":0,
                    "url":"https://api.github.com/users/oauthdemo2012",
                    "followers_url":"https://api.github.com/users/oauthdemo2012/followers",
                    "login":"oauthdemo2012",
                    "created_at":"2012-12-20T01:36:36Z",
                    "following_url":"https://api.github.com/users/oauthdemo2012/following",
                    "organizations_url":"https://api.github.com/users/oauthdemo2012/orgs",
                    "following":0,
                    "starred_url":"https://api.github.com/users/oauthdemo2012/starred{/owner}{/repo}",
                    "collaborators":0,
                    "public_repos":0,
                    "repos_url":"https://api.github.com/users/oauthdemo2012/repos",
                    "gists_url":"https://api.github.com/users/oauthdemo2012/gists{/gist_id}",
                    "id":3085592,
                    "total_private_repos":0,
                    "html_url":"https://github.com/oauthdemo2012",
                    "subscriptions_url":"https://api.github.com/users/oauthdemo2012/subscriptions",
                    "gravatar_id":"e0cb08c2b353cc1c3022dc65ebd060d1"
               }               
               */
                logger.info("github JSON: " + json);
                try
                {
                   obj = jsonParser.parse(json);
                    JSONObject jsonObj = (JSONObject) obj;
               
                    socialUser.setJson(json);
                    socialUser.setName((String) jsonObj.get("login"));
                   
                    return socialUser;
                }
                catch (ParseException e)
                {
                  throw new OurException("Could not parse JSON data from " + authProviderName + ":" + e.getMessage());
                }
            }
           
            case ClientUtils.FLICKR:
            {
                /* -- flickr --
                {
                    "user": {
                      "id": "91390211@N06",
                      "username": {
                        "_content": "oauthdemo2012"
                      }
                    },
                    "stat": "ok"
                }
                */
                logger.info("Flickr JSON: " + json);
                try
                {
                   obj = jsonParser.parse(json);
                   JSONObject jsonObj = (JSONObject) obj;
                   JSONObject jsonObjUser = (JSONObject) jsonObj.get("user");
                   JSONObject jsonObjUsername = (JSONObject) jsonObjUser.get("username");
                   socialUser.setName((String) jsonObjUsername.get("_content"));
                   socialUser.setJson(json);
                   
                  return socialUser;
                }
                catch (ParseException e)
                {
                  throw new OurException("Could not parse JSON data from " + authProviderName + ":" + e.getMessage());
                }
            }
           
            case ClientUtils.VIMEO:
            {
                /* --Vimeo starts --
                {
                    "generated_in": "0.0698",
                    "stat": "ok",
                    "person": {
                        "created_on": "2012-12-22 23:37:55",
                        "id": "15432968",
                        "is_contact": "0",
                        "is_plus": "0",
                        "is_pro": "0",
                        "is_staff": "0",
                        "is_subscribed_to": "0",
                        "username": "user15432968",
                        "display_name": "oauthdemo2012",
                        "location": "",
                        "url": [
                            ""
                        ],
                        .....
                    }
                }
                */
                logger.info("Vimeo JSON: " + json);
                try
                {
                   obj = jsonParser.parse(json);
                   JSONObject jsonObj = (JSONObject) obj;
                   JSONObject jsonObjPerson = (JSONObject) jsonObj.get("person");
                   String userName = (String) jsonObjPerson.get("username");
                   String displayName = (String) jsonObjPerson.get("display_name");
                  
                   if (displayName != null)
                   {
                       socialUser.setName(displayName);
                   }
                   else if (userName != null)
                   {
                       socialUser.setName(userName);
                   }
                   else
                   {
                       socialUser.setName("Unknown");
                   }
                   socialUser.setJson(json);
                   
                  return socialUser;
                }
                catch (ParseException e)
                {
                  throw new OurException("Could not parse JSON data from " + authProviderName + ":" + e.getMessage());
                }
            }
           
            case ClientUtils.WINDOWS_LIVE:
            {
                /* Windows Live --starts --
                {
                    "id" : "contact.c1678ab4000000000000000000000000",
                    "first_name" : "Roberto",
                    "last_name" : "Tamburello",
                    "name" : "Roberto Tamburello",
                    "gender" : "male",
                    "locale" : "en_US"
                }
                */
                logger.info("Windows Live JSON: " + json);
                try
                {
                   obj = jsonParser.parse(json);
                   JSONObject jsonObj = (JSONObject) obj;
                   JSONObject jsonErrorObj = (JSONObject) jsonObj.get("error");
                   if (jsonErrorObj != null)
                   {
                       /*
                       {
                           "error": {
                               "code": "request_token_too_many",
                               "message": "The request includes more than one access token. Only one access token is allowed."
                           }
                       }
                       */
                       String message = (String) jsonErrorObj.get("message");
                       throw new OurException("Error: " + message);
                   }
                   socialUser.setName((String) jsonObj.get("name"));
                   socialUser.setLastName((String) jsonObj.get("last_name"));
                   socialUser.setFirstName((String) jsonObj.get("first_name"));
                   socialUser.setJson(json);
                   
                  return socialUser;
                }
                catch (ParseException e)
                {
                  throw new OurException("Could not parse JSON data from " + authProviderName + ":" + e.getMessage());
                }
            }
           
            case ClientUtils.TUMBLR:
            {
                /* tumblr. --
                {
                    "meta": {
                      "status": 200,
                      "msg": "OK"
                    },
                    "response": {
                      "user": {
                        "name": "oauthdemo2012",
                        "likes": 0,
                        "following": 1,
                        "default_post_format": "html",
                        "blogs": [
                          {
                            "name": "oauthdemo2012",
                            "url": "http:\/\/oauthdemo2012.tumblr.com\/",
                            "followers": 0,
                            "primary": true,
                            "title": "Untitled",
                            "description": "",
                            "admin": true,
                            "updated": 0,
                            "posts": 0,
                            "messages": 0,
                            "queue": 0,
                            "drafts": 0,
                            "share_likes": true,
                            "ask": false,
                            "tweet": "N",
                            "facebook": "N",
                            "facebook_opengraph_enabled": "N",
                            "type": "public"
                          }
                        ]
                      }
                    }
                  }
                  */
                logger.info("tumblr JSON: " + json);
                try
                {
                   obj = jsonParser.parse(json);
                   JSONObject jsonObj = (JSONObject) obj;
                   JSONObject jsonObjResponse = (JSONObject) jsonObj.get("response");
                   JSONObject jsonObjUser = (JSONObject) jsonObjResponse.get("user");
                   String userName = (String) jsonObjUser.get("name");
                   socialUser.setName(userName);
                   socialUser.setJson(json);
                   
                  return socialUser;
                }
                catch (ParseException e)
                {
                  throw new OurException("Could not parse JSON data from " + authProviderName + ":" + e.getMessage());
                }
            }
           
            case ClientUtils.FOURSQUARE:
            {
               
               
                /* foursquare --        
                {
                    "meta": {
                        "code": 200,
                        "errorType": "deprecated",
                        "errorDetail": "Please provide an API version to avoid future errors.See http://bit.ly/vywCav"
                    },
                    "notifications": [
                        {
                            "type": "notificationTray",
                            "item": {
                                "unreadCount": 0
                            }
                        }
                    ],
                    "response": {
                        "user": {
                            "id": "43999331",
                            "firstName": "OAuth",
                            "lastName": "Demo",
                            "gender": "none",
                            "relationship": "self",
                            "photo": "https://foursquare.com/img/blank_boy.png",
                            "friends": {
                                "count": 0,
                                "groups": [
                                    {
                                        "type": "friends",
                                        "name": "Mutual friends",
                                        "count": 0,
                                        "items": []
                                    },
                                    {
                                        "type": "others",
                                        "name": "Other friends",
                                        "count": 0,
                                        "items": []
                                    }
                                ]
                            },
                            ......
                        }
                    }
                }
                */
                try
                {
                   obj = jsonParser.parse(json);
                   JSONObject jsonObj = (JSONObject) obj;
                   JSONObject jsonObjResponse = (JSONObject) jsonObj.get("response");
                   JSONObject jsonObjUser = (JSONObject) jsonObjResponse.get("user");
                   String firstName = (String) jsonObjUser.get("firstName");
                   String lastName = (String) jsonObjUser.get("lastName");
                   if (firstName != null && lastName != null)
                   {
                       socialUser.setName(firstName + " " + lastName);
                   }
                   else
                   {
                       socialUser.setName("UNKNOWN");
                   }
                   socialUser.setJson(json);
                   
                  return socialUser;
                }
                catch (ParseException e)
                {
                  throw new OurException("Could not parse JSON data from " + authProviderName + ":" + e.getMessage());
                }
            }
            default:
            {
                throw new OurException("Unknown Auth Provider: " + authProviderName);
            }
        }
       
      
        /*
 
View Full Code Here

Examples of com.example.GWTOAuthLoginDemo.client.exception.OurException

    private void verifyState(String state) throws OurException
    {
        String stateInSession = getStateFromSession();
        if (stateInSession == null)
        {
            throw new OurException("Could not find state in session");
        }
        if (!stateInSession.equals(state))
        {
            throw new OurException("State mismatch in session, expected: " + stateInSession + " Passed: " + state);
        }
    }
View Full Code Here

Examples of com.example.GWTOAuthLoginDemo.client.exception.OurException

    }

    private HttpSession validateSession(String sessionId) throws OurException
    {
        if (sessionId == null)
            throw new OurException("Session Id can not be empty");
        HttpSession session=getHttpSession();
        if (session == null)
        {
            throw new OurException(ClientUtils.SESSION_EXPIRED_MESSAGE);
        }
        /*
        ServersideSession ssSession=getServersideSession();
        if (ssSession == null)
        {
            throw new OurException(ClientUtils.SESSION_EXPIRED_MESSAGE);
        }
        if (sessionId.equals(ssSession.getSessionId()))
        {
            return session;
        }
        */
        String savedSessionId = getSessionIdFromSession();
        if (sessionId.equals(savedSessionId))
        {
            return session;
        }
        throw new OurException("Session Id mismatch: expected " + "'" + sessionId + "'" + " Found: " + "'" + savedSessionId + "'");
    }
View Full Code Here

Examples of com.example.GWTOAuthLoginDemo.client.exception.OurException

    {
        validateSession(sessionId);
        Token accessToken = getAccessTokenFromSession();
        if (accessToken == null)
        {
            throw new OurException("Could not find Access Token in HTTP Session");
        }
        return accessToken.getRawResponse();
    }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.