Package org.brickred.socialauth

Examples of org.brickred.socialauth.Profile


    isVerify = true;
    return getProfile();
  }

  private Profile getProfile() throws Exception {
    Profile profile = new Profile();

    String profileUrl = String
        .format(PROFILE_URL, accessToken.getAttribute("user_nsid"),
            config.get_consumerKey());

    LOG.info("Obtaining user profile. Profile URL : " + profileUrl);
    Response serviceResponse = null;
    try {
      serviceResponse = authenticationStrategy.executeFeed(profileUrl);
    } catch (Exception e) {
      throw new SocialAuthException(
          "Failed to retrieve the user profile from  " + profileUrl,
          e);
    }
    if (serviceResponse.getStatus() != 200) {
      throw new SocialAuthException(
          "Failed to retrieve the user profile from  " + profileUrl
              + ". Status :" + serviceResponse.getStatus());
    }

    Element root;
    try {
      root = XMLParseUtil.loadXmlResource(serviceResponse
          .getInputStream());
    } catch (Exception e) {
      throw new ServerDataException(
          "Failed to parse the profile from response." + profileUrl,
          e);
    }

    if (root != null) {
      NodeList pList = root.getElementsByTagName("person");
      if (pList != null && pList.getLength() > 0) {
        Element p = (Element) pList.item(0);
        if (p != null) {
          profile.setFullName(XMLParseUtil.getElementData(p,
              "realname"));
          profile.setDisplayName(XMLParseUtil.getElementData(p,
              "username"));
          profile.setCountry(XMLParseUtil.getElementData(p,
              "location"));
          String id = p.getAttribute("id");
          String iconfarm = p.getAttribute("iconfarm");
          String iconserver = p.getAttribute("iconserver");
          String buddyurl = "http://farm" + iconfarm
              + ".staticflickr.com/" + iconserver
              + "/buddyicons/" + id + ".jpg";
          profile.setValidatedId(id);
          if (iconserver.equalsIgnoreCase("0")) {
            profile.setProfileImageURL("http://www.flickr.com/images/buddyicon.gif");
          } else {
            profile.setProfileImageURL(buddyurl);
          }
          userProfile = profile;
        }
      }
    }
View Full Code Here


   * @param requestParams
   *            request parameters map
   * @return User Profile
   */
  public static Profile getUserInfo(final Map<String, String> requestParams) {
    Profile p = new Profile();
    p.setEmail(requestParams.get("openid.ext1.value.email"));
    p.setFirstName(requestParams.get("openid.ext1.value.firstname"));
    p.setLastName(requestParams.get("openid.ext1.value.lastname"));
    p.setCountry(requestParams.get("openid.ext1.value.country"));
    p.setLanguage(requestParams.get("openid.ext1.value.language"));
    p.setValidatedId(requestParams.get("openid.identity"));
    return p;
  }
View Full Code Here

      manager = (SocialAuthManager) userSession.get("socialAuthManager");
    }

    if (manager != null) {
      List<Contact> contactsList = new ArrayList<Contact>();
      Profile profile = null;
      try {
        Map<String, String> paramsMap = SocialAuthUtil
            .getRequestParametersMap(request);
        AuthProvider provider = manager.connect(paramsMap);
        profile = provider.getUserProfile();
View Full Code Here

          + PROFILE_URL, e);
    }
    try {
      LOG.debug("User Profile : " + presp);
      JSONObject resp = new JSONObject(presp);
      Profile p = new Profile();
      p.setValidatedId(resp.getString("id"));
      if (resp.has("name")) {
        p.setFullName(resp.getString("name"));
      }
      if (resp.has("first_name")) {
        p.setFirstName(resp.getString("first_name"));
      }
      if (resp.has("last_name")) {
        p.setLastName(resp.getString("last_name"));
      }
      if (resp.has("email")) {
        p.setEmail(resp.getString("email"));
      }
      if (resp.has("location")) {
        p.setLocation(resp.getJSONObject("location").getString("name"));
      }
      if (resp.has("birthday")) {
        String bstr = resp.getString("birthday");
        String[] arr = bstr.split("/");
        BirthDate bd = new BirthDate();
        if (arr.length > 0) {
          bd.setMonth(Integer.parseInt(arr[0]));
        }
        if (arr.length > 1) {
          bd.setDay(Integer.parseInt(arr[1]));
        }
        if (arr.length > 2) {
          bd.setYear(Integer.parseInt(arr[2]));
        }
        p.setDob(bd);
      }
      if (resp.has("gender")) {
        p.setGender(resp.getString("gender"));
      }
      p.setProfileImageURL(String.format(PROFILE_IMAGE_URL,
          resp.getString("id")));
      String locale = resp.getString("locale");
      if (locale != null) {
        String a[] = locale.split("_");
        p.setLanguage(a[0]);
        p.setCountry(a[1]);
      }
      p.setProviderId(getProviderId());
      userProfile = p;
      return p;

    } catch (Exception ex) {
      throw new ServerDataException(
View Full Code Here

    isVerify = true;
    return getProfile();
  }

  private Profile getProfile() throws Exception {
    Profile profile = new Profile();
    String url = PROFILE_URL + accessToken.getAttribute("screen_name");
    LOG.debug("Obtaining user profile. Profile URL : " + url);
    Response serviceResponse = null;
    try {
      serviceResponse = authenticationStrategy.executeFeed(url);
    } catch (Exception e) {
      throw new SocialAuthException(
          "Failed to retrieve the user profile from  " + url, e);
    }
    if (serviceResponse.getStatus() != 200) {
      throw new SocialAuthException(
          "Failed to retrieve the user profile from  " + url
              + ". Status :" + serviceResponse.getStatus());
    }
    String result;
    try {
      result = serviceResponse
          .getResponseBodyAsString(Constants.ENCODING);
      LOG.debug("User Profile :" + result);
    } catch (Exception exc) {
      throw new SocialAuthException("Failed to read response from  "
          + url, exc);
    }
    try {
      JSONObject pObj = new JSONObject(result);
      if (pObj.has("id_str")) {
        profile.setValidatedId(pObj.getString("id_str"));
      }
      if (pObj.has("name")) {
        profile.setFullName(pObj.getString("name"));
      }
      if (pObj.has("location")) {
        profile.setLocation(pObj.getString("location"));
      }
      if (pObj.has("screen_name")) {
        profile.setDisplayName(pObj.getString("screen_name"));
      }
      if (pObj.has("lang")) {
        profile.setLanguage(pObj.getString("lang"));
      }
      if (pObj.has("profile_image_url")) {
        profile.setProfileImageURL(pObj.getString("profile_image_url"));
      }
      profile.setProviderId(getProviderId());
      userProfile = profile;
      return profile;
    } catch (Exception e) {
      throw new ServerDataException(
          "Failed to parse the user profile json : " + result, e);
View Full Code Here

    authenticationStrategy.logout();
  }

  private Profile getProfile() throws Exception {
    LOG.debug("Obtaining user profile");
    Profile profile = new Profile();
    Response serviceResponse = null;
    try {
      serviceResponse = authenticationStrategy.executeFeed(PROFILE_URL);
    } catch (Exception e) {
      throw new SocialAuthException(
          "Failed to retrieve the user profile from  " + PROFILE_URL,
          e);
    }
    if (serviceResponse.getStatus() != 200) {
      throw new SocialAuthException(
          "Failed to retrieve the user profile from  " + PROFILE_URL
              + ". Staus :" + serviceResponse.getStatus());
    }

    Element root;
    try {
      root = XMLParseUtil.loadXmlResource(serviceResponse
          .getInputStream());
    } catch (Exception e) {
      throw new ServerDataException(
          "Failed to parse the profile from response." + PROFILE_URL,
          e);
    }

    if (root != null) {
      String fname = XMLParseUtil.getElementData(root, "first-name");
      String lname = XMLParseUtil.getElementData(root, "last-name");
      NodeList dob = root.getElementsByTagName("date-of-birth");
      if (dob != null && dob.getLength() > 0) {
        Element dobel = (Element) dob.item(0);
        if (dobel != null) {
          String y = XMLParseUtil.getElementData(dobel, "year");
          String m = XMLParseUtil.getElementData(dobel, "month");
          String d = XMLParseUtil.getElementData(dobel, "day");
          BirthDate bd = new BirthDate();
          if (m != null) {
            bd.setMonth(Integer.parseInt(m));
          }
          if (d != null) {
            bd.setDay(Integer.parseInt(d));
          }
          if (y != null) {
            bd.setYear(Integer.parseInt(y));
          }
          profile.setDob(bd);
        }
      }
      String picUrl = XMLParseUtil.getElementData(root, "picture-url");
      String id = XMLParseUtil.getElementData(root, "id");
      if (picUrl != null) {
        profile.setProfileImageURL(picUrl);
      }
      String email = XMLParseUtil.getElementData(root, "email-address");
      if (email != null) {
        profile.setEmail(email);
      }
      NodeList location = root.getElementsByTagName("location");
      if (location != null && location.getLength() > 0) {
        Element locationEl = (Element) location.item(0);
        String loc = XMLParseUtil.getElementData(locationEl, "name");
        if (loc != null) {
          profile.setLocation(loc);
        }
      }
      Map<String, String> map = new HashMap<String, String>();
      NodeList phoneNodes = root.getElementsByTagName("phone-number");
      if (phoneNodes != null && phoneNodes.getLength() > 0) {
        Element phoneEl = (Element) phoneNodes.item(0);
        String type = XMLParseUtil
            .getElementData(phoneEl, "phone-type");
        String phone = XMLParseUtil.getElementData(phoneEl,
            "phone-number");
        if (type != null && type.length() > 0 && phone != null) {
          map.put(type, phone);
        }
      }
      String mainAddress = XMLParseUtil.getElementData(root,
          "main-address");
      if (mainAddress != null) {
        map.put("mainAddress", mainAddress);
      }
      if (map != null && !map.isEmpty()) {
        profile.setContactInfo(map);
      }
      profile.setFirstName(fname);
      profile.setLastName(lname);
      profile.setValidatedId(id);
      profile.setProviderId(getProviderId());
      LOG.debug("User Profile :" + profile.toString());
      userProfile = profile;
    }
    return profile;
  }
View Full Code Here

          + PROFILE_URL, e);
    }
    try {
      LOG.debug("User Profile : " + presp);
      JSONObject resp = new JSONObject(presp);
      Profile p = new Profile();
      if (resp.has("profile")) {
        String purl = resp.getString("profile");
        String parr[] = purl.split("/");
        p.setValidatedId(parr[parr.length - 1]);
      }
      if (resp.has("name")) {
        p.setFirstName(resp.getString("name"));
        p.setFullName(resp.getString("name"));
      }

      if (resp.has("location")) {
        p.setLocation(resp.getString("location"));
      }
      if (resp.has("birthday")) {
        String bstr = resp.getString("birthday");
        if (bstr != null) {
          if (bstr.matches("[A-Za-z]{3}, \\d{1,2} [A-Za-z]{3} \\d{4} \\d{2}:\\d{2}:\\d{2}")) {
            DateFormat df = new SimpleDateFormat(
                "EEE, dd MMM yyyy hh:mm:ss");
            Date d = df.parse(bstr);
            Calendar c = Calendar.getInstance();
            c.setTime(d);
            BirthDate bd = new BirthDate();
            bd.setDay(c.get(Calendar.DAY_OF_MONTH));
            bd.setYear(c.get(Calendar.YEAR));
            bd.setMonth(c.get(Calendar.MONTH) + 1);
            p.setDob(bd);
          }
        }
      }
      if (resp.has("gender")) {
        p.setGender(resp.getString("gender"));
      }
      if (resp.has("normal_picture")) {
        p.setProfileImageURL(resp.getString("normal_picture"));
      }
      p.setProviderId(getProviderId());
      userProfile = p;
      return p;

    } catch (Exception ex) {
      throw new ServerDataException(
View Full Code Here

      // examine the verification result and extract the verified
      // identifier
      Identifier verified = verification.getVerifiedId();
      if (verified != null) {
        LOG.debug("Verified Id : " + verified.getIdentifier());
        Profile p = new Profile();
        p.setValidatedId(verified.getIdentifier());
        AuthSuccess authSuccess = (AuthSuccess) verification
            .getAuthResponse();

        if (authSuccess.hasExtension(AxMessage.OPENID_NS_AX)) {
          FetchResponse fetchResp = (FetchResponse) authSuccess
              .getExtension(AxMessage.OPENID_NS_AX);

          p.setEmail(fetchResp.getAttributeValue("email"));
          p.setFirstName(fetchResp.getAttributeValue("firstname"));
          p.setLastName(fetchResp.getAttributeValue("lastname"));
          p.setFullName(fetchResp.getAttributeValue("fullname"));

          // also use the ax namespace for compatibility
          if (p.getEmail() == null) {
            p.setEmail(fetchResp.getAttributeValue("emailax"));
          }
          if (p.getFirstName() == null) {
            p.setFirstName(fetchResp
                .getAttributeValue("firstnameax"));
          }
          if (p.getLastName() == null) {
            p.setLastName(fetchResp.getAttributeValue("lastnameax"));
          }
          if (p.getFullName() == null) {
            p.setFullName(fetchResp.getAttributeValue("fullnameax"));
          }

        }
        userProfile = p;
        return p;
View Full Code Here

  private Profile getProfile() throws Exception {
    if (!isVerify || accessToken == null) {
      throw new SocialAuthException(
          "Please call verifyResponse function first to get Access Token and then update status");
    }
    Profile p = new Profile();
    Response serviceResponse;
    if (profileId == null) {
      profileId = (String) accessGrant.getAttribute("profileId");
    }
    String profileURL = String.format(PROFILE_URL, profileId, accessToken);
    Map<String, String> headerParam = new HashMap<String, String>();
    headerParam.put("Authorization", "Bearer " + accessToken);
    try {

      serviceResponse = HttpUtil.doHttpRequest(profileURL, "GET", null,
          headerParam);
    } catch (Exception e) {
      throw new SocialAuthException(
          "Failed to retrieve the user profile from  " + profileURL,
          e);
    }
    String result;
    try {
      result = serviceResponse
          .getResponseBodyAsString(Constants.ENCODING);
      LOG.debug("User Profile :" + result);
    } catch (Exception e) {
      throw new SocialAuthException("Failed to read response from  "
          + profileURL, e);
    }
    try {
      JSONObject resp = new JSONObject(result);
      if (resp.has("full_name")) {
        p.setFullName(resp.getString("full_name"));
      }
      if (resp.has("location")) {
        p.setLocation(resp.getString("location"));
      }
      if (resp.has("mugshot_url")) {
        p.setProfileImageURL(resp.getString("mugshot_url"));
      }
      if (resp.has("birth_date")) {
        String dstr = resp.getString("birth_date");
        if (dstr != null) {
          String arr[] = dstr.split("\\s+");
          BirthDate bd = new BirthDate();
          if (arr.length == 1) {
            Calendar currentDate = Calendar.getInstance();
            bd.setMonth(currentDate.get(Calendar.MONTH) + 1);
            bd.setDay(currentDate.get(Calendar.DAY_OF_MONTH));
          } else {
            if (arr.length > 0) {
              bd.setDay(Integer.parseInt(arr[1]));
            }
            if (arr.length > 1) {
              bd.setMonth(new Integer(SocialAuthUtil
                  .getMonthInInt(arr[0])));
            }
          }
          p.setDob(bd);
        }
      }
      JSONObject userContactDetails = resp.getJSONObject("contact");
      JSONArray emailArr = userContactDetails
          .getJSONArray("email_addresses");

      JSONObject eobj = emailArr.getJSONObject(0);
      if (eobj.has("address")) {
        p.setEmail(eobj.getString("address"));
      }

      p.setProviderId(getProviderId());
      userProfile = p;
      return userProfile;
    } catch (Exception e) {
      throw new SocialAuthException(
          "Failed to parse the user profile json : " + result, e);
View Full Code Here

    accessGrant = null;
    authenticationStrategy.logout();
  }

  private Profile getProfile() throws Exception {
    Profile p = new Profile();
    Response serviceResponse;
    try {
      serviceResponse = authenticationStrategy.executeFeed(PROFILE_URL);
    } catch (Exception e) {
      throw new SocialAuthException(
          "Failed to retrieve the user profile from  " + PROFILE_URL,
          e);
    }

    String result;
    try {
      result = serviceResponse
          .getResponseBodyAsString(Constants.ENCODING);
      LOG.debug("User Profile :" + result);
    } catch (Exception e) {
      throw new SocialAuthException("Failed to read response from  "
          + PROFILE_URL, e);
    }
    try {
      JSONObject resp = new JSONObject(result);
      if (resp.has("id")) {
        p.setValidatedId(resp.getString("id"));
      }
      if (resp.has("name")) {
        p.setFullName(resp.getString("name"));
      }
      if (resp.has("first_name")) {
        p.setFirstName(resp.getString("first_name"));
      }
      if (resp.has("last_name")) {
        p.setLastName(resp.getString("last_name"));
      }
      if (resp.has("Location")) {
        p.setLocation(resp.getString("Location"));
      }
      if (resp.has("gender")) {
        p.setGender(resp.getString("gender"));
      }
      if (resp.has("ThumbnailImageLink")) {
        p.setProfileImageURL(resp.getString("ThumbnailImageLink"));
      }

      if (resp.has("birth_day") && !resp.isNull("birth_day")) {
        BirthDate bd = new BirthDate();
        bd.setDay(resp.getInt("birth_day"));
        if (resp.has("birth_month") && !resp.isNull("birth_month")) {
          bd.setMonth(resp.getInt("birth_month"));
        }
        if (resp.has("birth_year") && !resp.isNull("birth_year")) {
          bd.setYear(resp.getInt("birth_year"));
        }
        p.setDob(bd);
      }

      if (resp.has("emails")) {
        JSONObject eobj = resp.getJSONObject("emails");
        String email = null;
        if (eobj.has("preferred")) {
          email = eobj.getString("preferred");
        }
        if ((email == null || email.isEmpty()) && eobj.has("account")) {
          email = eobj.getString("account");
        }
        if ((email == null || email.isEmpty()) && eobj.has("personal")) {
          email = eobj.getString("personal");
        }
        p.setEmail(email);

      }
      if (resp.has("locale")) {
        p.setLanguage(resp.getString("locale"));
      }
      serviceResponse.close();
      p.setProviderId(getProviderId());
      String picUrl = String.format(PROFILE_PICTURE_URL,
          accessGrant.getKey());
      p.setProfileImageURL(picUrl);
      userProfile = p;
      return p;
    } catch (Exception e) {
      throw new SocialAuthException(
          "Failed to parse the user profile json : " + result, e);
View Full Code Here

TOP

Related Classes of org.brickred.socialauth.Profile

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.