Java Code Examples for org.brickred.socialauth.Profile#setFullName()
The following examples show how to use
org.brickred.socialauth.Profile#setFullName() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SuccessController.java From socialauth with MIT License | 6 votes |
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; }
Example 2
Source File: GitHubImpl.java From socialauth with MIT License | 5 votes |
private Profile getProfile() throws Exception { String presp; try { Response response = authenticationStrategy.executeFeed(ENDPOINTS.get(Constants.API_URL) + "/user"); presp = response.getResponseBodyAsString(Constants.ENCODING); } catch (Exception e) { throw new SocialAuthException("Error while getting profile from " + ENDPOINTS.get(Constants.API_URL) + "/user", e); } try { LOG.debug("User Profile : " + presp); JSONObject resp = new JSONObject(presp); Profile p = new Profile(); p.setValidatedId(resp.optString("id", null)); p.setFullName(resp.optString("name", null)); p.setEmail(resp.optString("email", null)); p.setLocation(resp.optString("location", null)); p.setProfileImageURL(resp.optString("avatar_url", null)); p.setDisplayName(resp.optString("login", null)); p.setProviderId(getProviderId()); if (config.isSaveRawResponse()) { p.setRawResponse(presp); } userProfile = p; return p; } catch (Exception ex) { throw new ServerDataException( "Failed to parse the user profile json : " + presp, ex); } }
Example 3
Source File: AmazonImpl.java From socialauth with MIT License | 5 votes |
private Profile getProfile() throws Exception { String presp; try { Response response = authenticationStrategy.executeFeed(PROFILE_URL); presp = response.getResponseBodyAsString(Constants.ENCODING); } catch (Exception e) { throw new SocialAuthException("Error while getting profile from " + PROFILE_URL, e); } try { LOG.debug("User Profile : " + presp); JSONObject resp = new JSONObject(presp); Profile p = new Profile(); p.setFullName(resp.optString("name", null)); p.setEmail(resp.optString("email", null)); p.setValidatedId(resp.optString("user_id", null)); p.setLocation(resp.optString("postal_code", null)); if (config.isSaveRawResponse()) { p.setRawResponse(presp); } p.setProviderId(getProviderId()); if (config.isSaveRawResponse()) { p.setRawResponse(presp); } userProfile = p; return p; } catch (Exception ex) { throw new ServerDataException( "Failed to parse the user profile json : " + presp, ex); } }
Example 4
Source File: RunkeeperImpl.java From socialauth with MIT License | 4 votes |
private Profile getProfile() throws Exception { String presp; try { Map<String, String> hmap = new HashMap<String, String>(); hmap.put("Accept", "application/vnd.com.runkeeper.Profile+json"); Response response = authenticationStrategy.executeFeed(PROFILE_URL, MethodType.GET.toString(), null, hmap, null); presp = response.getResponseBodyAsString(Constants.ENCODING); } catch (Exception e) { throw new SocialAuthException("Error while getting profile from " + 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( "Failed to parse the user profile json : " + presp, ex); } }
Example 5
Source File: GooglePlusImpl.java From socialauth with MIT License | 4 votes |
private Profile getProfile() throws Exception { String presp; try { Response response = authenticationStrategy.executeFeed(PROFILE_URL); presp = response.getResponseBodyAsString(Constants.ENCODING); } catch (Exception e) { throw new SocialAuthException("Error while getting profile from " + PROFILE_URL, e); } try { LOG.debug("User Profile : " + presp); JSONObject resp = new JSONObject(presp); Profile p = new Profile(); p.setValidatedId(resp.optString("id", null)); p.setFullName(resp.optString("name", null)); p.setFirstName(resp.optString("given_name", null)); p.setLastName(resp.optString("family_name", null)); p.setEmail(resp.optString("email", null)); p.setGender(resp.optString("gender", null)); p.setProfileImageURL(resp.optString("picture", null)); if (config.isSaveRawResponse()) { p.setRawResponse(presp); } String locale = resp.optString("locale", (String)null); if(locale != null) { if (locale.contains("_")) { String[] a = locale.split("_"); p.setLanguage(a[0]); p.setCountry(a[1]); } else { p.setLanguage(locale); } } p.setProviderId(getProviderId()); userProfile = p; return p; } catch (Exception ex) { throw new ServerDataException( "Failed to parse the user profile json : " + presp, ex); } }
Example 6
Source File: OpenIdImpl.java From socialauth with MIT License | 4 votes |
/** * Verifies the user when the external provider redirects back to our * application. * * * @param requestParams * request parameters, received from the provider * @return Profile object containing the profile information * @throws Exception */ @Override public Profile verifyResponse(final Map<String, String> requestParams) throws Exception { if (!providerState) { throw new ProviderStateException(); } try { // extract the parameters from the authentication response // (which comes in as a HTTP request from the OpenID provider) ParameterList response = new ParameterList(requestParams); // extract the receiving URL from the HTTP request StringBuffer receivingURL = new StringBuffer(); receivingURL.append(successUrl); StringBuffer sb = new StringBuffer(); for (Map.Entry<String, String> entry : requestParams.entrySet()) { String key = entry.getKey(); String value = entry.getValue(); if (sb.length() > 0) { sb.append("&"); } sb.append(key).append("=").append(value); } receivingURL.append("?").append(sb.toString()); // verify the response; ConsumerManager needs to be the same // (static) instance used to place the authentication request VerificationResult verification = manager.verify( receivingURL.toString(), response, discovered); // 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; } } catch (OpenIDException e) { throw e; } return null; }
Example 7
Source File: StackExchangeImpl.java From socialauth with MIT License | 4 votes |
private Profile getProfile() throws Exception { String presp; String profileURL = PROFILE_URL; String site = "stackoverflow"; if (config.getCustomProperties() != null) { if (config.getCustomProperties().get("site") != null) { site = config.getCustomProperties().get("site"); } profileURL += "?key=" + config.getCustomProperties().get("key") + "&site=" + site; } else { throw new SocialAuthException( "Please set 'stackapps.com.custom.key' property in oauth_consumer.properties "); } try { Response response = authenticationStrategy.executeFeed(profileURL); presp = response.getResponseBodyAsString(Constants.ENCODING); } catch (Exception e) { throw new SocialAuthException("Error while getting profile from " + profileURL, e); } try { LOG.debug("User Profile : " + presp); JSONObject jsonResp = new JSONObject(presp); Profile p = new Profile(); if (jsonResp.has("items")) { JSONArray items = jsonResp.getJSONArray("items"); if (items.length() > 0) { JSONObject resp = items.getJSONObject(0); p.setDisplayName(resp.optString("display_name", null)); p.setFullName(resp.optString("display_name", null)); p.setProfileImageURL(resp.optString("profile_image", null)); p.setValidatedId(resp.optString("user_id", null)); p.setLocation(resp.optString("location", null)); if (config.isSaveRawResponse()) { p.setRawResponse(presp); } p.setProviderId(getProviderId()); if (config.isSaveRawResponse()) { p.setRawResponse(presp); } } } userProfile = p; return p; } catch (Exception ex) { throw new ServerDataException( "Failed to parse the user profile json : " + presp, ex); } }
Example 8
Source File: FacebookImpl.java From socialauth with MIT License | 4 votes |
private Profile authFacebookLogin() throws Exception { String presp; try { Response response = authenticationStrategy.executeFeed(PROFILE_URL); presp = response.getResponseBodyAsString(Constants.ENCODING); } catch (Exception e) { throw new SocialAuthException("Error while getting profile from " + PROFILE_URL, e); } try { LOG.debug("User Profile : " + presp); JSONObject resp = new JSONObject(presp); Profile p = new Profile(); p.setValidatedId(resp.optString("id", null)); p.setFullName(resp.optString("name", null)); p.setFirstName(resp.optString("first_name", null)); p.setLastName(resp.optString("last_name", null)); p.setEmail(resp.optString("email", null)); if (resp.has("location")) { p.setLocation(resp.getJSONObject("location").optString("name", null)); } if (resp.has("birthday")) { String bstr = resp.optString("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); } p.setGender(resp.optString("gender", null)); p.setProfileImageURL(String.format(PROFILE_IMAGE_URL, resp.getString("id"))); String locale = resp.optString("locale", null); if (locale != null) { String a[] = locale.split("_"); p.setLanguage(a[0]); p.setCountry(a[1]); } p.setProviderId(getProviderId()); if (config.isSaveRawResponse()) { p.setRawResponse(presp); } userProfile = p; return p; } catch (Exception ex) { throw new ServerDataException( "Failed to parse the user profile json : " + presp, ex); } }