org.springframework.social.connect.Connection.getDisplayName()方法的使用及代码示例

x33g5p2x  于2022-01-18 转载在 其他  
字(5.9k)|赞(0)|评价(0)|浏览(139)

本文整理了Java中org.springframework.social.connect.Connection.getDisplayName()方法的一些代码示例,展示了Connection.getDisplayName()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Connection.getDisplayName()方法的具体详情如下:
包路径:org.springframework.social.connect.Connection
类名称:Connection
方法名:getDisplayName

Connection.getDisplayName介绍

[英]A display name or label for this connection. Should be suitable for display on a UI and distinguish this connection from others with the same provider. Generally the full name or screen name of the connected provider user e.g. "Keith Donald" or "@kdonald". May be null if this information is not public or not provided. The value of this property may change if the user updates his or her profile.
[中]此连接的显示名称或标签。应适合在UI上显示,并将此连接与具有相同提供程序的其他连接区分开来。通常是连接的提供商用户的全名或屏幕名,例如“Keith Donald”或“@kdonald”。如果此信息未公开或未提供,则可能为空。如果用户更新其配置文件,此属性的值可能会更改。

代码示例

代码示例来源:origin: tihomcode/TiHom-Security

@Override
  public String execute(Connection<?> connection) {
    //根据社交用户信息默认创建用户并返回用户唯一标识,下面的唯一标识可以自定义设定根据业务需求
    return connection.getDisplayName();
  }
}

代码示例来源:origin: org.craftercms/crafter-security-provider

String displayName;
if (StringUtils.isNotEmpty(connection.getDisplayName())) {
  displayName = connection.getDisplayName();
} else {
  displayName = firstName + " " + lastName;

代码示例来源:origin: io.loli.social/custom-social-core-extension

private void assertFacebookConnection(Connection<TestFacebookApi> facebook) {
  assertEquals(new ConnectionKey("facebook", "9"), facebook.getKey());
  assertEquals(null, facebook.getDisplayName());
  assertEquals(null, facebook.getProfileUrl());
  assertEquals(null, facebook.getImageUrl());
  TestFacebookApi facebookApi = facebook.getApi();
  assertEquals("234567890", facebookApi.getAccessToken());
  facebook.sync();
  assertEquals("Keith Donald", facebook.getDisplayName());
  assertEquals("http://facebook.com/keith.donald",
      facebook.getProfileUrl());
  assertEquals("http://facebook.com/keith.donald/picture",
      facebook.getImageUrl());
}

代码示例来源:origin: tihomcode/TiHom-Security

/**
 * 用户第一次社交登录时,会引导用户进行用户注册或绑定,此服务用于在注册或绑定页面获取社交网站用户信息
 * @param request
 * @return
 */
@GetMapping("/social/user")
public SocialUserInfo getSocialUserInfo(HttpServletRequest request){
  SocialUserInfo userInfo = new SocialUserInfo();
  Connection<?> connection = providerSignInUtils.getConnectionFromSession(new ServletWebRequest(request));
  userInfo.setProviderId(connection.getKey().getProviderId());
  userInfo.setProviderUserId(connection.getKey().getProviderUserId());
  userInfo.setNickname(connection.getDisplayName());
  userInfo.setHeadimg(connection.getImageUrl());
  return userInfo;
}

代码示例来源:origin: tihomcode/TiHom-Security

/**
   * 要注册时跳到这里,返回401和用户信息给前端
   * @param request
   * @return
   */
  @GetMapping("/social/signUp")
  @ResponseStatus(HttpStatus.UNAUTHORIZED)
  public SocialUserInfo getSocialUserInfo(HttpServletRequest request){
    SocialUserInfo userInfo = new SocialUserInfo();
    Connection<?> connection = providerSignInUtils.getConnectionFromSession(new ServletWebRequest(request));
    userInfo.setProviderId(connection.getKey().getProviderId());
    userInfo.setProviderUserId(connection.getKey().getProviderUserId());
    userInfo.setNickname(connection.getDisplayName());
    userInfo.setHeadimg(connection.getImageUrl());
    //从connection中拿出数据存入redis中,做转存
    appSignUpUtils.saveConnectionData(new ServletWebRequest(request),connection.createData());
    return userInfo;
  }
}

代码示例来源:origin: tigerphz/tgcloud-master

/**
 * 根据Connection信息构建SocialUserInfo
 *
 * @param connection the connection
 * @return social user info
 */
protected SocialUserInfo buildSocialUserInfo(Connection<?> connection) {
  SocialUserInfo userInfo = new SocialUserInfo();
  userInfo.setProviderId(connection.getKey().getProviderId());
  userInfo.setProviderUserId(connection.getKey().getProviderUserId());
  userInfo.setNickname(connection.getDisplayName());
  userInfo.setHeadimg(connection.getImageUrl());
  return userInfo;
}

代码示例来源:origin: alien4cloud/alien4cloud

@Override
public List<String> findUserIdsWithConnection(Connection<?> connection) {
  ConnectionKey key = connection.getKey();
  String userId = key.getProviderId() + "::" + key.getProviderUserId();
  User user = alienUserDao.find(userId);
  if (user == null) {
    user = new User();
    user.setUsername(userId);
    user.setFirstName(connection.getDisplayName());
    alienUserDao.save(user);
    return Lists.newArrayList(userId);
    // TODO what connexion(s) means in spring sec ?
    // createConnectionRepository(newUserId).addConnection(connection);
  }
  return Lists.newArrayList(userId);
}

代码示例来源:origin: io.loli.social/custom-social-core-extension

private void assertTwitterConnection(Connection<TestTwitterApi> twitter) {
  assertEquals(new ConnectionKey("twitter", "1"), twitter.getKey());
  assertEquals("@kdonald", twitter.getDisplayName());
  assertEquals("http://twitter.com/kdonald", twitter.getProfileUrl());
  assertEquals("http://twitter.com/kdonald/picture",
      twitter.getImageUrl());
  TestTwitterApi twitterApi = twitter.getApi();
  assertEquals("123456789", twitterApi.getAccessToken());
  assertEquals("987654321", twitterApi.getSecret());
  twitter.sync();
  assertEquals("http://twitter.com/kdonald/a_new_picture",
      twitter.getImageUrl());
}

代码示例来源:origin: io.loli.social/custom-social-core-extension

private void assertNewConnection(Connection<TestFacebookApi> connection) {
  assertEquals("facebook", connection.getKey().getProviderId());
  assertEquals("9", connection.getKey().getProviderUserId());
  assertEquals("Keith Donald", connection.getDisplayName());
  assertEquals("http://facebook.com/keith.donald",
      connection.getProfileUrl());
  assertEquals("http://facebook.com/keith.donald/picture",
      connection.getImageUrl());
  assertTrue(connection.test());
  TestFacebookApi api = connection.getApi();
  assertNotNull(api);
  assertEquals("123456789", api.getAccessToken());
  assertEquals("123456789", connection.createData().getAccessToken());
  assertEquals("987654321", connection.createData().getRefreshToken());
}

相关文章