Package org.brickred.socialauth

Examples of org.brickred.socialauth.Profile


          + 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("email")) {
        String email = resp.getString("email");
        if (!"null".equals(email)) {
          p.setEmail(resp.getString("email"));
        }
      }
      if (resp.has("location")) {
        p.setLocation(resp.getString("location"));
      }
      if (resp.has("avatar_url")) {
        p.setProfileImageURL(resp.getString("avatar_url"));
      }
      p.setProviderId(getProviderId());
      userProfile = p;
      return p;
    } catch (Exception ex) {
      throw new ServerDataException(
          "Failed to parse the user profile json : " + presp, ex);
View Full Code Here


    authenticationStrategy.setScope(getScope());
  }

  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());
    }

    String result;
    try {
      result = serviceResponse
          .getResponseBodyAsString(Constants.ENCODING);
      LOG.debug("User Profile :" + result);
    } catch (Exception exc) {
      throw new SocialAuthException("Failed to read response from  "
          + PROFILE_URL, exc);
    }
    JSONObject pObj = new JSONObject();
    JSONObject jobj = new JSONObject(result);
    if (jobj.has("person")) {
      pObj = jobj.getJSONObject("person");
    } else {
      throw new ServerDataException(
          "Failed to parse the user profile json : " + result);
    }
    if (pObj.has("displayName")) {
      profile.setDisplayName(pObj.getString("displayName"));
    }
    if (pObj.has("id")) {
      profile.setValidatedId(pObj.getString("id"));
    }
    if (pObj.has("name")) {
      JSONObject nobj = pObj.getJSONObject("name");
      if (nobj.has("familyName")) {
        profile.setLastName(nobj.getString("familyName"));
      }
      if (nobj.has("givenName")) {
        profile.setFirstName(nobj.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("thumbnailUrl")) {
      profile.setProfileImageURL(pObj.getString("thumbnailUrl"));
    }
    profile.setProviderId(getProviderId());
    userProfile = profile;
    return profile;
  }
View Full Code Here

  @SuppressWarnings("rawtypes")
  @Override
  public Profile verifyResponse(Map params) throws Exception {
    Map<String, Object> result = BrowserId.verify((String)params.get("audience"), (String)params.get("assertion"));
    if (result != null && "okay".equals(result.get("status"))) {
      Profile profile = new Profile();
      profile.setValidatedId(result.get("email").toString());
      profile.setEmail(result.get("email").toString());
      profile.setProviderId(getProviderId());
      this.profile = profile;
      return profile;
    }
    throw new SocialAuthException("Error: " + Json.toJson(result));
  }
View Full Code Here

    try {
      Map<String, Object> data = Json.fromJson(Map.class, presp);
      if (!data.containsKey("uid"))
        throw new SocialAuthException("Error: " + presp);
      if (userProfile == null)
        userProfile = new Profile();
      userProfile.setValidatedId(data.get("uid").toString());
      userProfile.setProviderId(getProviderId());
      //userProfile.setFullName(data.get("name").toString());
      return userProfile;
View Full Code Here

    in.read(d);
    String[] data = new String(d).trim().split("\n");
    System.out.println(Json.toJson(data));
    if ("yes".endsWith(data[0])) {
      String uid = data[1];
      Profile profile = new Profile();
      profile.setValidatedId(uid);
      profile.setProviderId(getProviderId());
      userProfile = profile;
      return profile;
    }
    throw new SocialAuthException("Sdo Error : " + Json.toJson(data));
  }
View Full Code Here

      //System.out.println("User Profile : " + presp);
      Map<String, Object> data = Json.fromJson(Map.class, presp);
      if (!data.containsKey("id"))
        throw new SocialAuthException("Error: " + presp);
      if (userProfile == null)
        userProfile = new Profile();
      userProfile.setValidatedId(data.get("id").toString());
      userProfile.setProviderId(getProviderId());
      return userProfile;

    } catch (Exception ex) {
View Full Code Here

    try {
      //System.out.println("User Profile : " + presp);
      Map<String, Object> data = Json.fromJson(Map.class, presp);
      if (!data.containsKey("uid"))
        throw new SocialAuthException("Error: " + presp);
      Profile p = new Profile();
      p.setValidatedId(data.get("uid").toString());
      p.setProviderId(getProviderId());
      userProfile = p;
      return p;

    } catch (Exception ex) {
      throw new ServerDataException(
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"));
      }
      //Fix issue 145
      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

    if (manager == null)
      throw new SocialAuthException("Not manager found!");
    session.removeAttribute("openid_manager"); //防止重复登录的可能性
    Map<String, String> paramsMap = SocialAuthUtil.getRequestParametersMap(request);
    AuthProvider provider = manager.connect(paramsMap);
    Profile p = provider.getUserProfile();
        BasicDBObject query = new BasicDBObject().append("validatedId", p.getValidatedId()).append("provider", providerId);
        User user = dao.findOne(User.class, query);
        if (user == null) {
          user = new User();
          user.setEmail(p.getEmail());
          user.setProvider(providerId);
          user.setValidatedId(p.getValidatedId());
          final User _u = user;
          dao.runNoError(new Callback<DB>() {
          public void invoke(DB arg0) {
            dao.save(_u);
          }
        });
        }
        Moo moo = Moo.SET("lastLoginDate", new Date()).set("email", p.getEmail());
        dao.update(User.class, new BasicDBObject("_id", user.getId()), moo);
       
        session.setAttribute("me", user);
        session.setMaxInactiveInterval(30 * 24 * 60 * 60);
        return user;
View Full Code Here

    try {
      Map<String, Object> data = Json.fromJson(Map.class, presp);
      if (!data.containsKey("id"))
        throw new SocialAuthException("Error: " + presp);
      if (userProfile == null)
        userProfile = new Profile();
      userProfile.setValidatedId(data.get("id").toString());
      userProfile.setProviderId(getProviderId());
      //System.out.println(Json.toJson(data));
      if (data.get("email") != null)
        userProfile.setValidatedId(data.get("email").toString());
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.