本文整理了Java中org.springframework.social.connect.Connection
类的一些代码示例,展示了Connection
类的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Connection
类的具体详情如下:
包路径:org.springframework.social.connect.Connection
类名称:Connection
[英]A link to a service provider user. Allows the client application to access or update user information using the provider's API. Exposes a set of operations that are common across all service providers, including the ability to #fetchUserProfile() and #updateStatus(String).
[中]指向服务提供商用户的链接。允许客户端应用程序使用提供程序的API访问或更新用户信息。公开一组在所有服务提供商中通用的操作,包括#fetchUserProfile()和#updateStatus(字符串)的功能。
代码示例来源:origin: spring-projects/spring-social-facebook
@Bean
@ConditionalOnMissingBean(Facebook.class)
@Scope(value = "request", proxyMode = ScopedProxyMode.INTERFACES)
public Facebook facebook(ConnectionRepository repository) {
Connection<Facebook> connection = repository
.findPrimaryConnection(Facebook.class);
return connection != null ? connection.getApi() : null;
}
代码示例来源:origin: at.molindo.social/spring-social-core
public void addConnection(Connection<?> connection) {
try {
ConnectionKey connectionKey = connection.getKey();
getConnection(connectionKey);
throw new DuplicateConnectionException(connectionKey);
} catch (NoSuchConnectionException e) {
connections.add(connection.createData().getProviderId(), connection);
}
}
代码示例来源:origin: org.springframework.social/spring-social-web
private UserProfile getProfileIfConnected(Map<String, Object> model) {
@SuppressWarnings("unchecked")
List<Connection<?>> connections = (List<Connection<?>>) model.get("connections");
if (connections != null) {
for (Connection<?> connection : connections) {
if (connection.getKey().getProviderId().equals(providerId)) {
return connection.fetchUserProfile();
}
}
}
return null;
}
代码示例来源:origin: socialsignin/spring-social-security
public P create(Connection<?> connection)
{
P profile = instantiate();
UserProfile userProfile = connection.fetchUserProfile();
init(profile,userProfile,connection.createData());
return profile;
}
public void init(P profile,UserProfile userProfile,ConnectionData connectionData)
代码示例来源: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: 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());
}
代码示例来源:origin: at.molindo.social/spring-social-core
@SuppressWarnings("rawtypes")
public boolean equals(Object o) {
if (!(o instanceof Connection)) {
return false;
}
Connection other = (Connection) o;
return key.equals(other.getKey());
}
代码示例来源:origin: org.springframework.social/spring-social-web
public ProviderSignInAttempt(Connection<?> connection) {
this.connectionData = connection.createData();
}
代码示例来源: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: io.loli.social/custom-social-core-extension
@Test
public void updateConnectionAccessFields() {
insertFacebookConnection();
Connection<TestFacebookApi> facebook = connectionRepository
.getPrimaryConnection(TestFacebookApi.class);
assertEquals("234567890", facebook.getApi().getAccessToken());
facebook.refresh();
connectionRepository.updateConnection(facebook);
Connection<TestFacebookApi> facebook2 = connectionRepository
.getPrimaryConnection(TestFacebookApi.class);
assertEquals("765432109", facebook2.getApi().getAccessToken());
ConnectionData data = facebook.createData();
assertEquals("654321098", data.getRefreshToken());
}
代码示例来源: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: com.jtbdevelopment.core-games/games-web
@Override
public String execute(final Connection<?> connection) {
try {
Player player = playerRepository.findBySourceAndSourceId(connection.getKey().getProviderId(),
connection.getKey().getProviderUserId());
if (player != null) {
return player.getIdAsString();
} else {
P p = playerFactory.newPlayer();
p.setDisabled(false);
p.setDisplayName(connection.fetchUserProfile().getName());
p.setSource(connection.getKey().getProviderId());
p.setSourceId(connection.getKey().getProviderUserId());
p.setProfileUrl(connection.getProfileUrl());
p.setImageUrl(connection.getImageUrl());
p = playerRepository.save(p);
return (p == null ? null : p.getIdAsString());
}
} catch (Exception e) {
logger.warn("Experienced exception in AutoConnectionSignUp", e);
return null;
}
}
}
代码示例来源:origin: FundRequest/platform
@Bean
public Gitter gitter(@Value("${io.fundrequest.notifications.gitter.consumer-key}") final String consumerKey,
@Value("${io.fundrequest.notifications.gitter.consumer-secret}") final String consumerSecret,
@Value("${io.fundrequest.notifications.gitter.access-token}") final String accessToken) {
final Connection<Gitter> gitterConnection = new GitterConnectionFactory(consumerKey, consumerSecret).createConnection(new AccessGrant(accessToken));
assert gitterConnection.test();
return gitterConnection.getApi();
}
代码示例来源: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: BroadleafCommerce/BroadleafCommerce
public String register(RegisterCustomerForm registerCustomerForm, HttpServletRequest request,
HttpServletResponse response, Model model) {
Connection<?> connection = ProviderSignInUtils.getConnection(new ServletWebRequest(request));
if (connection != null) {
UserProfile userProfile = connection.fetchUserProfile();
Customer customer = registerCustomerForm.getCustomer();
customer.setFirstName(userProfile.getFirstName());
customer.setLastName(userProfile.getLastName());
customer.setEmailAddress(userProfile.getEmail());
if (isUseEmailForLogin()){
customer.setUsername(userProfile.getEmail());
} else {
customer.setUsername(userProfile.getUsername());
}
}
return super.register(registerCustomerForm, request, response, model);
}
代码示例来源:origin: org.craftercms/crafter-security-provider
UserProfile providerProfile = connection.fetchUserProfile();
String displayName;
if (StringUtils.isNotEmpty(connection.getDisplayName())) {
displayName = connection.getDisplayName();
} else {
displayName = firstName + " " + lastName;
profile.setAttribute(DISPLAY_NAME_ATTRIBUTE_NAME, displayName);
if (StringUtils.isNotEmpty(connection.getImageUrl())) {
profile.setAttribute(AVATAR_LINK_ATTRIBUTE_NAME, connection.getImageUrl());
代码示例来源:origin: socialsignin/spring-social-security
private Set<ConnectionKey> toConnectionKeySet(
List<Connection<?>> connections,boolean includeExpiredConnections) {
Set<ConnectionKey> connectionKeys = new HashSet<ConnectionKey>();
for (Connection<?> connection : connections) {
if (includeExpiredConnections || !connection.hasExpired()) {
ConnectionData connectionData = connection.createData();
connectionKeys.add(new ConnectionKey(connectionData
.getProviderId(), connectionData.getProviderUserId()));
}
}
return connectionKeys;
}
代码示例来源:origin: io.loli.social/custom-social-core-extension
@Test
public void updateConnectionProfileFields() {
connectionFactoryRegistry
.addConnectionFactory(new TestTwitterConnectionFactory());
insertTwitterConnection();
Connection<TestTwitterApi> twitter = connectionRepository
.getPrimaryConnection(TestTwitterApi.class);
assertEquals("http://twitter.com/kdonald/picture",
twitter.getImageUrl());
twitter.sync();
assertEquals("http://twitter.com/kdonald/a_new_picture",
twitter.getImageUrl());
connectionRepository.updateConnection(twitter);
Connection<TestTwitterApi> twitter2 = connectionRepository
.getPrimaryConnection(TestTwitterApi.class);
assertEquals("http://twitter.com/kdonald/a_new_picture",
twitter2.getImageUrl());
}
代码示例来源:origin: tihomcode/TiHom-Security
@Override
public String execute(Connection<?> connection) {
//根据社交用户信息默认创建用户并返回用户唯一标识,下面的唯一标识可以自定义设定根据业务需求
return connection.getDisplayName();
}
}
代码示例来源: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());
}
内容来源于网络,如有侵权,请联系作者删除!