Package org.brickred.socialauth

Examples of org.brickred.socialauth.Profile


  @Action(value = "/socialAuthSuccessAction")
  public String execute() throws Exception {

    SASFHelper helper = SASFStaticHelper.getHelper(request);
    try {
      Profile profile = helper.getProfile();

      List<Contact> contactsList = helper.getContactList();

      if (contactsList != null && contactsList.size() > 0) {
        for (Contact p : contactsList) {
View Full Code Here


    return props;
  }

  @Override
  public Profile getProfile() {
    Profile profile = null;
    SocialAuthManager manager = getAuthManager();
    if (manager != null) {
      try {
        AuthProvider provider = manager.getCurrentAuthProvider();
        profile = provider.getUserProfile();
View Full Code Here

    return null;
  }

  private ModelAndView registration(final AuthProvider provider)
      throws Exception {
    Profile profile = provider.getUserProfile();
    if (profile.getFullName() == null) {
      String name = null;
      if (profile.getFirstName() != null) {
        name = profile.getFirstName();
      }
      if (profile.getLastName() != null) {
        if (profile.getFirstName() != null) {
          name += " " + profile.getLastName();
        } else {
          name = profile.getLastName();
        }
      }
      if (name == null && profile.getDisplayName() != null) {
        name = profile.getDisplayName();
      }
      if (name != null) {
        profile.setFullName(name);
      }
    }
    ModelAndView view = new ModelAndView("registrationForm", "profile",
        profile);
    return view;
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("given_name")) {
        p.setFirstName(resp.getString("given_name"));
      }
      if (resp.has("family_name")) {
        p.setLastName(resp.getString("family_name"));
      }
      if (resp.has("email")) {
        p.setEmail(resp.getString("email"));
      }
      if (resp.has("gender")) {
        p.setGender(resp.getString("gender"));
      }
      if (resp.has("picture")) {
        p.setProfileImageURL(resp.getString("picture"));
      }
      if (resp.has("id")) {
        p.setValidatedId(resp.getString("id"));
      }

      p.setProviderId(getProviderId());
      userProfile = p;
      return p;

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

    return getProfile();
  }

  private Profile getProfile() throws Exception {
    LOG.debug("Obtaining user profile");
    Profile profile = new Profile();
    String guid = (String) accessToken.getAttribute("xoauth_yahoo_guid");
    if (guid.indexOf("<") != -1) {
      guid = guid.substring(0, guid.indexOf("<")).trim();
      accessToken.setAttribute("xoauth_yahoo_guid", guid);
    }
    String url = String.format(PROFILE_URL, guid);
    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
              + ". Staus :" + 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 jobj = new JSONObject(result);
      if (jobj.has("profile")) {
        JSONObject pObj = jobj.getJSONObject("profile");
        if (pObj.has("guid")) {
          profile.setValidatedId(pObj.getString("guid"));
        }
        if (pObj.has("familyName")) {
          profile.setLastName(pObj.getString("familyName"));
        }
        if (pObj.has("gender")) {
          profile.setGender(pObj.getString("gender"));
        }
        if (pObj.has("givenName")) {
          profile.setFirstName(pObj.getString("givenName"));
        }
        if (pObj.has("location")) {
          profile.setLocation(pObj.getString("location"));
        }
        if (pObj.has("nickname")) {
          profile.setDisplayName(pObj.getString("nickname"));
        }
        if (pObj.has("lang")) {
          profile.setLanguage(pObj.getString("lang"));
        }
        if (pObj.has("birthdate")) {
          String dstr = pObj.getString("birthdate");
          if (dstr != null) {
            String arr[] = dstr.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]));
            }
            profile.setDob(bd);
          }
        }
        if (pObj.has("image")) {
          JSONObject imgObj = pObj.getJSONObject("image");
          if (imgObj.has("imageUrl")) {
            profile.setProfileImageURL(imgObj.getString("imageUrl"));
          }
        }
        if (pObj.has("emails")) {
          JSONArray earr = pObj.getJSONArray("emails");
          for (int i = 0; i < earr.length(); i++) {
            JSONObject eobj = earr.getJSONObject(i);
            if (eobj.has("primary")
                && "true".equals(eobj.getString("primary"))) {
              if (eobj.has("handle")) {
                profile.setEmail(eobj.getString("handle"));
              }
              break;
            }
          }
        }

      }
      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

  private Profile getProfile() throws Exception {
    if (accessGrant.getAttribute("id") != null) {
      profileURL = (String) accessGrant.getAttribute("id");
    }
    LOG.debug("Profile URL : " + profileURL);
    Profile p = new Profile();
    Map<String, String> headerParam = new HashMap<String, String>();
    headerParam.put("Authorization", "OAuth " + accessGrant.getKey());
    headerParam.put("Content-Type", "application/json");
    headerParam.put("Accept", "application/json");
    Response serviceResponse;
    try {
      serviceResponse = authenticationStrategy.executeFeed(profileURL,
          MethodType.GET.toString(), null, headerParam, null);
      // 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("user_id")) {
        p.setValidatedId(resp.getString("user_id"));
      }
      if (resp.has("first_name")) {
        p.setFirstName(resp.getString("first_name"));
      }
      if (resp.has("last_name")) {
        p.setLastName(resp.getString("last_name"));
      }
      p.setDisplayName(resp.getString("display_name"));

      p.setEmail(resp.getString("email"));
      String locale = resp.getString("locale");
      if (locale != null) {
        String a[] = locale.split("_");
        p.setLanguage(a[0]);
        p.setCountry(a[1]);
      }
      if (resp.has("photos")) {
        JSONObject photosResp = resp.getJSONObject("photos");

        if (p.getProfileImageURL() == null
            || p.getProfileImageURL().length() <= 0) {
          p.setProfileImageURL(photosResp.getString("thumbnail"));
        }
      }
      serviceResponse.close();
      p.setProviderId(getProviderId());
      userProfile = p;
      return p;
    } catch (Exception e) {
      throw new SocialAuthException(
          "Failed to parse the user profile json : " + result, e);
View Full Code Here

      String respStr = response
          .getResponseBodyAsString(Constants.ENCODING);
      LOG.debug("Profile JSON string :: " + respStr);
      JSONObject obj = new JSONObject(respStr);
      JSONObject data = obj.getJSONObject("data");
      Profile p = new Profile();
      p.setValidatedId(data.optString("id"));
      String full_name = data.optString("full_name");
      p.setDisplayName(full_name);
      if (full_name != null) {
        String[] names = full_name.split(" ");
        if (names.length > 1) {
          p.setFirstName(names[0]);
          p.setLastName(names[1]);
        } else {
          p.setFirstName(full_name);
        }
      }
      p.setProfileImageURL(data.optString("profile_picture"));
      p.setProviderId(getProviderId());
      return p;
    } else {
      throw new SocialAuthException(
          "Failed to retrieve the user profile from " + PROFILE_URL
              + ". Server response " + response.getStatus());
View Full Code Here

    isVerify = true;
    return getProfile();
  }

  private Profile getProfile() throws Exception {
    Profile profile = new Profile();
    String url = PROFILE_URL;
    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
              + ". Staus :" + 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 pRes = new JSONObject(result);
      JSONObject pObj = pRes.getJSONObject("main");
      if (pObj.has("profile_id")) {
        profile.setValidatedId(pObj.getString("profile_id"));
      }
      if (pObj.has("name")) {
        String name = pObj.getString("name");
        if (name != null && name.trim().length() > 0) {
          profile.setFirstName(pObj.getString("name"));
        }
      }
      if (pObj.has("photo")) {
        String photo = pObj.getString("photo");
        if (photo != null && photo.trim().length() > 0) {
          profile.setProfileImageURL(pObj.getString("photo"));
        }
      }
      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

    }
  }

  private Profile getProfile() throws Exception {
    LOG.debug("Obtaining user profile");
    Profile profile = 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 res;
    try {
      res = serviceResponse.getResponseBodyAsString(Constants.ENCODING);
    } catch (Exception exc) {
      throw new SocialAuthException("Failed to read response from  "
          + PROFILE_URL, exc);
    }

    JSONObject jobj = new JSONObject(res);
    JSONObject rObj;
    JSONObject uObj;
    if (jobj.has("response")) {
      rObj = jobj.getJSONObject("response");
    } else {
      throw new SocialAuthException(
          "Failed to parse the user profile json : " + res);
    }
    if (rObj.has("user")) {
      uObj = rObj.getJSONObject("user");
    } else {
      throw new SocialAuthException(
          "Failed to parse the user profile json : " + res);
    }
    if (uObj.has("id")) {
      profile.setValidatedId(uObj.getString("id"));
    }
    if (uObj.has("firstName")) {
      profile.setFirstName(uObj.getString("firstName"));
    }
    if (uObj.has("lastName")) {
      profile.setLastName(uObj.getString("lastName"));
    }
    if (uObj.has("photo")) {
      profile.setProfileImageURL(uObj.getString("photo"));
    }
    if (uObj.has("gender")) {
      profile.setGender(uObj.getString("gender"));
    }
    if (uObj.has("homeCity")) {
      profile.setLocation(uObj.getString("homeCity"));
    }
    if (uObj.has("contact")) {
      JSONObject cobj = uObj.getJSONObject("contact");
      if (cobj.has("email")) {
        profile.setEmail(cobj.getString("email"));
      }
    }
    profile.setProviderId(getProviderId());
    userProfile = profile;
    return profile;
  }
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
          + authenticationStrategy.getAccessGrant().getKey());
    } 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

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.