当前位置: 首页>>代码示例>>Java>>正文


Java Connection.getApi方法代码示例

本文整理汇总了Java中org.springframework.social.connect.Connection.getApi方法的典型用法代码示例。如果您正苦于以下问题:Java Connection.getApi方法的具体用法?Java Connection.getApi怎么用?Java Connection.getApi使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.springframework.social.connect.Connection的用法示例。


在下文中一共展示了Connection.getApi方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: authenticate

import org.springframework.social.connect.Connection; //导入方法依赖的package包/类
public void authenticate(Connection<?> connection) {
    Facebook facebook = (Facebook) connection.getApi();
    String [] fields = { "id", "name", "email", "first_name", "last_name" };
    User userProfile = facebook.fetchObject("me", User.class, fields);
    String username = userProfile.getName();

    log.info("User Profile by facebook {} {} {}", userProfile.getFirstName(), userProfile.getLastName(), userProfile.getEmail());

    Optional<io.osoon.domain.User> byEmail = userService.findByEmail(userProfile.getEmail());
    io.osoon.domain.User osoonUser;

    if (byEmail.isPresent()) {
        osoonUser = byEmail.get();
    } else {
        io.osoon.domain.User newUser = io.osoon.domain.User.of(userProfile.getEmail(), username);
        newUser.setImageUrl(connection.getImageUrl());
        osoonUser = userService.saveOne(newUser);
    }

    OSoonUserDetails userDetails = new OSoonUserDetails(osoonUser);
    RememberMeAuthenticationToken rememberMeToken = new RememberMeAuthenticationToken("osoon-remember-me", userDetails, null);
    SecurityContextHolder.getContext().setAuthentication(rememberMeToken);

    log.info("User {} {} {} connected.", userProfile.getFirstName(), userProfile.getLastName(), userProfile.getEmail());
}
 
开发者ID:spring-sprout,项目名称:osoon,代码行数:26,代码来源:AuthUtil.java

示例2: facebook

import org.springframework.social.connect.Connection; //导入方法依赖的package包/类
@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;
}
 
开发者ID:PacktPublishing,项目名称:OAuth-2.0-Cookbook,代码行数:9,代码来源:FacebookConfiguration.java

示例3: signIn

import org.springframework.social.connect.Connection; //导入方法依赖的package包/类
@RequestMapping(method = RequestMethod.POST, consumes = MediaType.APPLICATION_FORM_URLENCODED_VALUE)
public RedirectView signIn(@RequestParam("username") String username, @RequestParam("password") String password, NativeWebRequest request) {
    try {
        GarminConnectConnectionFactory connectionFactory = (GarminConnectConnectionFactory) this.connectionFactoryLocator.getConnectionFactory(GarminConnectConnection.PROVIDER_ID);

        MultiValueMap<String, String> parameters = new LinkedMultiValueMap<String, String>();
        preSignIn(connectionFactory, parameters, request);

        Connection<GarminConnect> connection = connectionFactory.createConnection(username, password);

        GarminConnect api = connection.getApi();
        // will throw exception if authentication fails
        api.authenticate();

        return handleSignIn(connection, connectionFactory, request);
    } catch (Exception e) {
        LOGGER.error("Exception while signing in to Garmin", e);
        return redirect(URIBuilder.fromUri(signInUrl).queryParam("error", "provider").build().toString());
    }
}
 
开发者ID:tomwetjens,项目名称:spring-social-garmin,代码行数:21,代码来源:GarminSigninController.java

示例4: assertNewConnection

import org.springframework.social.connect.Connection; //导入方法依赖的package包/类
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());
}
 
开发者ID:xm-online,项目名称:xm-uaa,代码行数:14,代码来源:CustomSocialUsersConnectionRepositoryIntTest.java

示例5: assertTwitterConnection

import org.springframework.social.connect.Connection; //导入方法依赖的package包/类
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());
}
 
开发者ID:xm-online,项目名称:xm-uaa,代码行数:12,代码来源:CustomSocialUsersConnectionRepositoryIntTest.java

示例6: assertFacebookConnection

import org.springframework.social.connect.Connection; //导入方法依赖的package包/类
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());
}
 
开发者ID:xm-online,项目名称:xm-uaa,代码行数:13,代码来源:CustomSocialUsersConnectionRepositoryIntTest.java

示例7: getApi

import org.springframework.social.connect.Connection; //导入方法依赖的package包/类
@Override
public Discord getApi() {
    if (log.isDebugEnabled()) {
        log.debug("Getting API binding instance for Discord");
    }

    Connection<Discord> connection = usersConnectionRepository.createConnectionRepository(userIdSource.getUserId()).findPrimaryConnection(Discord.class);
    if (log.isDebugEnabled() && connection == null) {
        log.debug("No current connection; Returning default DiscordTemplate instance.");
    }
    return connection != null ? connection.getApi() : null;
}
 
开发者ID:quanticc,项目名称:sentry,代码行数:13,代码来源:DiscordApiHelper.java

示例8: google

import org.springframework.social.connect.Connection; //导入方法依赖的package包/类
@Bean
@Scope(value = "request", proxyMode = ScopedProxyMode.INTERFACES)
public Google google(final ConnectionRepository repository) {
	final Connection<Google> connection = repository
			.findPrimaryConnection(Google.class);
	return connection != null ? connection.getApi() : null;
}
 
开发者ID:PacktPublishing,项目名称:OAuth-2.0-Cookbook,代码行数:8,代码来源:GoogleConfigurerAdapter.java

示例9: gitHub

import org.springframework.social.connect.Connection; //导入方法依赖的package包/类
@Bean
@Scope(value = "request", proxyMode = ScopedProxyMode.INTERFACES)
public GitHub gitHub(ConnectionRepository repository) {
	Connection<GitHub> connection = repository
			.findPrimaryConnection(GitHub.class);
	return connection != null ? connection.getApi() : null;
}
 
开发者ID:PacktPublishing,项目名称:OAuth-2.0-Cookbook,代码行数:8,代码来源:GitHubConfiguration.java

示例10: vkontakte

import org.springframework.social.connect.Connection; //导入方法依赖的package包/类
@Bean
@ConditionalOnMissingBean
@Scope(value = "request", proxyMode = ScopedProxyMode.INTERFACES)
public VKontakte vkontakte(ConnectionRepository repository) {
    Connection<VKontakte> connection = repository.findPrimaryConnection(VKontakte.class);
    if (connection != null) {
        return connection.getApi();
    }
    return new VKontakteTemplate();
}
 
开发者ID:saladinkzn,项目名称:social-vkontakte-spring-boot-starter,代码行数:11,代码来源:VKontakteAutoConfiguration.java

示例11: twitter

import org.springframework.social.connect.Connection; //导入方法依赖的package包/类
@Bean
@ConditionalOnMissingBean
@Scope(value = "request", proxyMode = ScopedProxyMode.INTERFACES)
public Twitter twitter(ConnectionRepository repository) {
	Connection<Twitter> connection = repository
			.findPrimaryConnection(Twitter.class);
	if (connection != null) {
		return connection.getApi();
	}
	return new TwitterTemplate(this.properties.getAppId(),
			this.properties.getAppSecret());
}
 
开发者ID:vikrammane23,项目名称:https-github.com-g0t4-jenkins2-course-spring-boot,代码行数:13,代码来源:TwitterAutoConfiguration.java

示例12: linkedin

import org.springframework.social.connect.Connection; //导入方法依赖的package包/类
@Bean
@ConditionalOnMissingBean(LinkedIn.class)
@Scope(value = "request", proxyMode = ScopedProxyMode.INTERFACES)
public LinkedIn linkedin(ConnectionRepository repository) {
	Connection<LinkedIn> connection = repository
			.findPrimaryConnection(LinkedIn.class);
	return connection != null ? connection.getApi() : null;
}
 
开发者ID:vikrammane23,项目名称:https-github.com-g0t4-jenkins2-course-spring-boot,代码行数:9,代码来源:LinkedInAutoConfiguration.java

示例13: getSession

import org.springframework.social.connect.Connection; //导入方法依赖的package包/类
@Override
public Map<String, String> getSession() throws DCMAApplicationException {

	Map<String, String> map = new HashMap<String, String>();
	Alfresco alfresco = null;
	try {
		validateClientKey(clientKey);
		validateSecretKey(secretKey);
		validateRefreshToken(refreshToken);
		validateNetwork(network);
		AlfrescoConnectionFactory connectionFactory = new AlfrescoConnectionFactory(clientKey, secretKey);
		OAuth2Parameters parameters = new OAuth2Parameters();
		parameters.setScope(Alfresco.DEFAULT_SCOPE);
		AccessGrant accessGrant = connectionFactory.getOAuthOperations().refreshAccess(refreshToken, null, parameters);
		Connection<Alfresco> connection = connectionFactory.createConnection(accessGrant);
		alfresco = connection.getApi();
		map.put(CMISProperties.CMIS_REFRESH_TOKEN.getPropertyKey(), accessGrant.getRefreshToken());
		if (alfresco != null) {
			alfresco.getCMISSession(network);
		} else {
			throw new DCMAApplicationException("Unable to create alfresco instance");
		}

		// Get CMIS Session
	} catch (HttpClientErrorException httpClientErrorException) {
		throw new DCMAApplicationException(CMISExportConstant.CMIS_AUTHENTICATION_FAIL, httpClientErrorException);
	} catch (ResourceAccessException resourceAccessException) {
		throw new DCMAApplicationException(CMISExportConstant.CMIS_CONNECTION_FAIL, resourceAccessException);
	} catch (CmisUnauthorizedException cmisUnauthorizedException) {
		throw new DCMAApplicationException(CMISExportConstant.CMIS_UNAUTHORIZED_ACCESS, cmisUnauthorizedException);
	}
	return map;
}
 
开发者ID:kuzavas,项目名称:ephesoft,代码行数:34,代码来源:OAuthCMISSession.java

示例14: assertNewConnection

import org.springframework.social.connect.Connection; //导入方法依赖的package包/类
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());
}
 
开发者ID:priitl,项目名称:p2p-webtv,代码行数:14,代码来源:CustomSocialUsersConnectionRepositoryTest.java

示例15: assertTwitterConnection

import org.springframework.social.connect.Connection; //导入方法依赖的package包/类
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());
}
 
开发者ID:priitl,项目名称:p2p-webtv,代码行数:12,代码来源:CustomSocialUsersConnectionRepositoryTest.java


注:本文中的org.springframework.social.connect.Connection.getApi方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。