本文整理汇总了Java中org.springframework.social.connect.ConnectionFactory类的典型用法代码示例。如果您正苦于以下问题:Java ConnectionFactory类的具体用法?Java ConnectionFactory怎么用?Java ConnectionFactory使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ConnectionFactory类属于org.springframework.social.connect包,在下文中一共展示了ConnectionFactory类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: handleSignIn
import org.springframework.social.connect.ConnectionFactory; //导入依赖的package包/类
private RedirectView handleSignIn(Connection<?> connection, ConnectionFactory<?> connectionFactory,
NativeWebRequest request) {
List<String> userIds = usersConnectionRepository.findUserIdsWithConnection(connection);
if (userIds.isEmpty()) {
ProviderSignInAttempt signInAttempt = new ProviderSignInAttempt(connection);
sessionStrategy.setAttribute(request, ProviderSignInAttempt.SESSION_ATTRIBUTE, signInAttempt);
return redirect(getSignUpUrl());
} else if (userIds.size() == 1) {
usersConnectionRepository.createConnectionRepository(userIds.get(0)).updateConnection(connection);
String originalUrl = signInAdapter.signIn(userIds.get(0), connection, request);
return originalUrl != null ? redirect(originalUrl) : redirect(POST_SIGN_IN_URL);
} else {
log.error("Find more than one user with connection key: {}", connection.getKey());
return redirectOnError(connection.getKey().getProviderId());
}
}
示例2: getConnectionFactory
import org.springframework.social.connect.ConnectionFactory; //导入依赖的package包/类
@Override
public ConnectionFactory<?> getConnectionFactory(String providerId) {
HttpServletRequest req = ((ServletRequestAttributes) RequestContextHolder.currentRequestAttributes())
.getRequest();
String domain = TenantContext.getCurrent().getDomain();
Optional<SocialConfig> config = socialConfigRepository.findOneByProviderIdAndDomain(providerId, domain);
if (config.isPresent()) {
SocialConfig sc = config.get();
switch (sc.getProviderId()) {
case "facebook":
return new FacebookConnectionFactory(sc.getConsumerKey(), sc.getConsumerSecret());
case "google":
return new GoogleConnectionFactory(sc.getConsumerKey(), sc.getConsumerSecret());
case "twitter":
return new TwitterConnectionFactory(sc.getConsumerKey(), sc.getConsumerSecret());
case "linkedin":
return new LinkedInConnectionFactory(sc.getConsumerKey(), sc.getConsumerSecret());
default:
break;
}
}
throw new IllegalArgumentException("No provider config found for " + providerId);
}
示例3: socialUserConnectionToConnection
import org.springframework.social.connect.ConnectionFactory; //导入依赖的package包/类
private Connection<?> socialUserConnectionToConnection(final SocialUserConnection socialUserConnection) {
final ConnectionData connectionData = new ConnectionData(socialUserConnection.getProviderId(),
socialUserConnection.getProviderUserId(),
socialUserConnection.getDisplayName(),
socialUserConnection.getProfileURL(),
socialUserConnection.getImageURL(),
socialUserConnection.getAccessToken(),
socialUserConnection.getSecret(),
socialUserConnection.getRefreshToken(),
socialUserConnection.getExpireTime());
final ConnectionFactory<?> connectionFactory
= connectionFactoryLocator.getConnectionFactory(connectionData.getProviderId());
return connectionFactory.createConnection(connectionData);
}
示例4: createConnectionFactory
import org.springframework.social.connect.ConnectionFactory; //导入依赖的package包/类
public ConnectionFactory<?> createConnectionFactory(String appId, String appSecret) {
switch(this) {
case facebook:
return new FacebookConnectionFactory(appId, appSecret);
case twitter:
return new TwitterConnectionFactory(appId, appSecret);
case google:
GoogleConnectionFactory factory = new GoogleConnectionFactory(appId, appSecret);
factory.setScope("openid profile");
return factory;
case linkedin:
return new LinkedInConnectionFactory(appId, appSecret);
case github:
return new GitHubConnectionFactory(appId, appSecret);
default:
return null;
}
}
示例5: testCreateConnectionRepository
import org.springframework.social.connect.ConnectionFactory; //导入依赖的package包/类
@Test
public void testCreateConnectionRepository() throws Exception {
User user = new User(SocialTestUtils.USER_ONE);
user.setId(idProvider.getAndIncrement());
when(userRepository.findOneByPrimaryEmail(SocialTestUtils.USER_EMAIL_ONE))
.thenReturn(user);
Connection connection = mock(Connection.class);
ArgumentCaptor<ConnectionData> connectionDataCaptor =
ArgumentCaptor.forClass(ConnectionData.class);
ConnectionFactory connectionFactoryOne = mock(ConnectionFactory.class);
when(connectionFactoryLocator.getConnectionFactory(user.getAuthProviderId()))
.thenReturn(connectionFactoryOne);
when(connectionFactoryOne.createConnection(connectionDataCaptor.capture()))
.thenReturn(connection);
ConnectionRepository connectionRepository = usersConnectionRepository
.createConnectionRepository(SocialTestUtils.USER_EMAIL_ONE);
assertTrue(connectionRepository instanceof AwesomeAgileConnectionRepository);
}
示例6: signIn
import org.springframework.social.connect.ConnectionFactory; //导入依赖的package包/类
@PostMapping(value = "/signin/{providerId}")
public RedirectView signIn(@PathVariable String providerId, NativeWebRequest request) {
try {
ConnectionFactory<?> connectionFactory = connectionFactoryLocator.getConnectionFactory(providerId);
MultiValueMap<String, String> parameters = new LinkedMultiValueMap<>();
return redirectAbsolute(connectSupport.buildOAuthUrl(connectionFactory, request, parameters));
} catch (Exception e) {
log.error("Exception while building authorization URL: ", e);
return redirectOnError(providerId);
}
}
示例7: buildOAuthUrl
import org.springframework.social.connect.ConnectionFactory; //导入依赖的package包/类
/**
* Builds the provider URL to redirect the user to for connection authorization.
*
* @param connectionFactory the service provider's connection factory e.g. FacebookConnectionFactory
* @param request the current web request
* @param additionalParameters parameters to add to the authorization URL.
* @return the URL to redirect the user to for authorization
* @throws IllegalArgumentException if the connection factory is not OAuth1 based.
*/
public String buildOAuthUrl(ConnectionFactory<?> connectionFactory, NativeWebRequest request,
MultiValueMap<String, String> additionalParameters) {
if (connectionFactory instanceof OAuth1ConnectionFactory) {
return buildOAuth1Url((OAuth1ConnectionFactory<?>) connectionFactory, request, additionalParameters);
} else if (connectionFactory instanceof OAuth2ConnectionFactory) {
return buildOAuth2Url((OAuth2ConnectionFactory<?>) connectionFactory, request, additionalParameters);
} else {
throw new IllegalArgumentException("ConnectionFactory not supported");
}
}
示例8: handleSignIn
import org.springframework.social.connect.ConnectionFactory; //导入依赖的package包/类
private RedirectView handleSignIn(Connection<?> connection, ConnectionFactory<?> connectionFactory, NativeWebRequest request) {
List<String> userIds = usersConnectionRepository.findUserIdsWithConnection(connection);
if (userIds.size() == 0) {
ProviderSignInAttempt signInAttempt = new ProviderSignInAttempt(connection);
sessionStrategy.setAttribute(request, ProviderSignInAttempt.SESSION_ATTRIBUTE, signInAttempt);
return redirect(signUpUrl);
} else if (userIds.size() == 1) {
usersConnectionRepository.createConnectionRepository(userIds.get(0)).updateConnection(connection);
String originalUrl = signInAdapter.signIn(userIds.get(0), connection, request);
postSignIn(connectionFactory, connection, (WebRequest) request);
return originalUrl != null ? redirect(originalUrl) : redirect(postSignInUrl);
} else {
return redirect(URIBuilder.fromUri(signInUrl).queryParam("error", "multiple_users").build().toString());
}
}
示例9: interceptingSignInTo
import org.springframework.social.connect.ConnectionFactory; //导入依赖的package包/类
private List<ProviderSignInInterceptor<?>> interceptingSignInTo(ConnectionFactory<?> connectionFactory) {
Class<?> serviceType = GenericTypeResolver.resolveTypeArgument(connectionFactory.getClass(), ConnectionFactory.class);
List<ProviderSignInInterceptor<?>> typedInterceptors = signInInterceptors.get(serviceType);
if (typedInterceptors == null) {
typedInterceptors = Collections.emptyList();
}
return typedInterceptors;
}
示例10: findAllConnections
import org.springframework.social.connect.ConnectionFactory; //导入依赖的package包/类
@Override
public MultiValueMap<String, Connection<?>> findAllConnections() {
User user = getUser();
ConnectionFactory connectionFactory =
connectionFactoryLocator.getConnectionFactory(user.getAuthProviderId());
return toMultiValueMap(ImmutableMap.of(user.getAuthProviderId(),
(List<Connection<?>>)ImmutableList.<Connection<?>>of(
connectionFactory.createConnection(connectionData(user)))));
}
示例11: findConnections
import org.springframework.social.connect.ConnectionFactory; //导入依赖的package包/类
@Override
public <A> List<Connection<A>> findConnections(Class<A> apiType) {
User user = getUser();
ConnectionFactory<A> connectionFactory =
connectionFactoryLocator.getConnectionFactory(apiType);
if (connectionFactory != null) {
return ImmutableList.of(connectionFactory.createConnection(connectionData(user)));
}
return ImmutableList.of();
}
示例12: getConnection
import org.springframework.social.connect.ConnectionFactory; //导入依赖的package包/类
@Override
public Connection<?> getConnection(ConnectionKey key) {
User user = userRepository.findOneByAuthProviderUserId(
key.getProviderId(), key.getProviderUserId());
if (user.getId() == userId) {
ConnectionFactory<?> connectionFactory = connectionFactoryLocator
.getConnectionFactory(key.getProviderId());
return connectionFactory.createConnection(connectionData(user));
}
throw new NoSuchConnectionException(key);
}
示例13: findPrimaryConnection
import org.springframework.social.connect.ConnectionFactory; //导入依赖的package包/类
@Override
public <A> Connection<A> findPrimaryConnection(Class<A> apiType) {
ConnectionFactory<A> connectionFactory = getConnectionFactory(apiType);
User user = getUser();
String providerId = connectionFactory.getProviderId();
if (providerId.equals(user.getAuthProviderId())) {
return connectionFactory.createConnection(connectionData(user));
}
return null;
}
示例14: authToConnection
import org.springframework.social.connect.ConnectionFactory; //导入依赖的package包/类
private Connection<?> authToConnection(SocialAuthentication auth) {
ConnectionFactory<?> connectionFactory = locator.getConnectionFactory(auth.getProviderId());
ConnectionData data = new ConnectionData(auth.getProviderId(), auth.getProviderUserId(), null, null,
auth.getImageUrl(), auth.getToken(), auth.getSecret(), auth.getRefreshToken(),
auth.getExpirationTime());
return connectionFactory.createConnection(data);
}
示例15: socialUserConnectionToConnection
import org.springframework.social.connect.ConnectionFactory; //导入依赖的package包/类
private Connection<?> socialUserConnectionToConnection(SocialUserConnection socialUserConnection) {
ConnectionData connectionData = new ConnectionData(socialUserConnection.getProviderId(), socialUserConnection.getProviderUserId(),
socialUserConnection.getDisplayName(), socialUserConnection.getProfileUrl(), socialUserConnection.getImageURL(),
socialUserConnection.getAccessToken(), socialUserConnection.getSecret(), socialUserConnection.getRefreshToken(),
socialUserConnection.getExpireTime());
ConnectionFactory<?> connectionFactory = connectionFactoryLocator.getConnectionFactory(connectionData.getProviderId());
return connectionFactory.createConnection(connectionData);
}