Пример #1
0
 protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken token)
     throws DisabledAccountException {
   OAuthToken oauthToken = (OAuthToken) token;
   Profile credential = oauthToken.getCredentials();
   String openid = credential.getValidatedId();
   throw Lang.makeThrow(LockedAccountException.class, "Account [ %s ] is locked.", openid);
   /*Sys_user user = getUserService().fetchByOpenID(openid);
   if (Lang.isEmpty(user)) {
   	boolean isUpdated = StringUtils.isNotBlank(credential.getDisplayName());
   	String nickName = StringUtils.defaultString(credential.getDisplayName(), openid);
   	String providerid = credential.getProviderId();
   	//user = getUserService().initUser(nickName, openid, providerid, oauthToken.getAddr(), isUpdated);
   }
   //if (user.isLocked()) {
   	//throw Lang.makeThrow(LockedAccountException.class, "Account [ %s ] is locked.", user.getName());
   //}
   //oauthToken.setRname(!user.isUpdated());
   oauthToken.setUserId(openid);
   SimpleAuthenticationInfo account = new SimpleAuthenticationInfo(user, credential, getName());
   oauthToken.getSession().setAttribute(org.nutz.web.Webs.ME, user);
   return account;*/
 }
Пример #2
0
  @SuppressWarnings("unchecked")
  protected Profile authLogin() throws Exception {
    String presp;
    try {
      Response response = authenticationStrategy.executeFeed(PROFILE_URL);
      presp =
          response.getResponseBodyAsString(
              Constants.ENCODING); // callback( {"client_id":"YOUR_APPID","openid":"YOUR_OPENID"} );
      if (presp != null) {
        presp = presp.trim().intern();
        if (presp.startsWith("callback(") && presp.endsWith(");")) {
          presp = presp.substring(presp.indexOf("{"), presp.indexOf("}") + 1);
          Map<String, String> map = (Map<String, String>) Json.fromJson(presp);
          if (map.get("openid") != null) {
            Profile p = new Profile();
            p.setValidatedId(map.get("openid")); // QQ定义的
            p.setProviderId(getProviderId());
            userProfile = p;

            try {
              Map<String, String> params = new HashMap<String, String>();
              params.put("format", "json");
              params.put("openid", map.get("openid"));
              params.put("oauth_consumer_key", config.get_consumerKey());
              response =
                  authenticationStrategy.executeFeed(
                      "https://graph.qq.com/user/get_user_info", "GET", params, null, null);
              presp = response.getResponseBodyAsString(Constants.ENCODING);
              Map<String, Object> user_info = (Map<String, Object>) Json.fromJson(presp);
              if ((Integer) user_info.get("ret") == 0) { // 获取成功
                if (user_info.get("nickname") != null)
                  p.setDisplayName(user_info.get("nickname").toString());
                if (user_info.get("figureurl") != null)
                  p.setProfileImageURL(user_info.get("figureurl").toString());
                if (user_info.get("gender") != null)
                  p.setGender(user_info.get("gender").toString());
              }

              // TODO 尝试获取Email等详细信息

            } catch (Throwable e) {
              e.printStackTrace();
            }

            return p;
          }
        }
      }

      throw new SocialAuthException("QQ Error : " + presp);
    } catch (Exception e) {
      throw new SocialAuthException("Error while getting profile from " + PROFILE_URL, e);
    }
  }
Пример #3
0
  public static String getProfileDetails(HttpSession session) {
    Profile profile = (Profile) session.getAttribute("profile");
    if (profile == null) return "";
    String email = profile.getEmail();
    String fullName = profile.getFullName();
    String firstName = profile.getFirstName();
    String lastName = profile.getLastName();
    String location = profile.getLocation();
    String gender = profile.getGender();
    String image = profile.getProfileImageURL();
    String displayName = profile.getDisplayName();
    String validatedId = profile.getValidatedId();
    String providerId = profile.getProviderId();

    if (null == fullName) fullName = firstName + " " + lastName;
    String dob = "";
    if (profile.getDob() != null) {
      BirthDate bd = profile.getDob();
      dob = bd.toString();
    }

    StringBuffer basicJs = new StringBuffer();
    basicJs.append("<script> \n");
    basicJs.append("\tvar _email = '").append(email).append("'; \n");
    basicJs.append("\tvar _fullName = '").append(fullName).append("'; \n");
    basicJs.append("\tvar _dob = '").append(dob).append("'; \n");
    basicJs.append("\tvar _gender = '").append(gender).append("'; \n");
    basicJs.append("\tvar _location = '").append(location).append("'; \n");
    basicJs.append("\tvar _image = '").append(image).append("'; \n");
    basicJs.append("\tvar _displayName = '").append(displayName).append("'; \n");
    basicJs.append("\tvar _validatedId = '").append(validatedId).append("'; \n");
    basicJs.append("\tvar _providerId = '").append(providerId).append("'; \n");
    basicJs.append("</script> \n");

    return basicJs.toString();
  }
Пример #4
0
 public static String getUserIdFromSessionId(String sessionId) {
   Profile profile = getUserProfileFromSessionId(sessionId);
   if (profile == null) return null;
   return profile.getProviderId();
 }