org.springframework.social.connect.ConnectionRepository Java Examples
The following examples show how to use
org.springframework.social.connect.ConnectionRepository.
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: CurrencyExchangeServiceOfflineImpl.java From cloudstreetmarket.com with GNU General Public License v3.0 | 6 votes |
private void updateCurrencyExchangeFromYahoo(String ticker) { String guid = AuthenticationUtil.getPrincipal().getUsername(); String token = usersConnectionRepository.getRegisteredSocialUser(guid).getAccessToken(); ConnectionRepository connectionRepository = usersConnectionRepository.createConnectionRepository(guid); Connection<Yahoo2> connection = connectionRepository.getPrimaryConnection(Yahoo2.class); if (connection == null) { return; } List<YahooQuote> yahooQuotes = connection.getApi().financialOperations().getYahooQuotes(Lists.newArrayList(ticker), token); if(yahooQuotes == null || yahooQuotes.size() > 1){ throw new IllegalArgumentException("Currency ticker:"+ticker+" not found at Yahoo!"); } currencyExchangeRepository.save(yahooCurrencyConverter.convert(yahooQuotes.get(0))); }
Example #2
Source File: GitHubConfiguration.java From codeway_service with GNU General Public License v3.0 | 5 votes |
@Bean public ConnectController connectController( ConnectionFactoryLocator factoryLocator, ConnectionRepository repository) { ConnectController controller = new ConnectController( factoryLocator, repository); controller.setApplicationUrl("http://localhost:8090"); return controller; }
Example #3
Source File: SocialConfig.java From AIDR with GNU Affero General Public License v3.0 | 5 votes |
@Bean @Scope(value = "request", proxyMode = ScopedProxyMode.INTERFACES) public ConnectionRepository connectionRepository() { Authentication auth = SecurityContextHolder.getContext().getAuthentication(); if (auth == null) { throw new IllegalStateException("No User Signed in"); } return usersConnectionRepository.createConnectionRepository(auth.getName()); }
Example #4
Source File: SpringSocialUserDetailService.java From AIDR with GNU Affero General Public License v3.0 | 5 votes |
private List<Connection<?>> getConnections(ConnectionRepository connectionRepository) { MultiValueMap<String, Connection<?>> connections = connectionRepository.findAllConnections(); List<Connection<?>> allConnections = new ArrayList<Connection<?>>(); if (connections.size() > 0) { for (List<Connection<?>> connectionList : connections.values()) { for (Connection<?> connection : connectionList) { allConnections.add(connection); } } } return allConnections; }
Example #5
Source File: SocialConfig.java From AIDR with GNU Affero General Public License v3.0 | 5 votes |
@Bean @Scope(value = "request", proxyMode = ScopedProxyMode.INTERFACES) public ConnectionRepository connectionRepository() { Authentication auth = SecurityContextHolder.getContext().getAuthentication(); if (auth == null) { throw new IllegalStateException("No User Signed in"); } return usersConnectionRepository().createConnectionRepository(auth.getName()); }
Example #6
Source File: SpringSocialUserDetailService.java From AIDR with GNU Affero General Public License v3.0 | 5 votes |
private List<Connection<?>> getConnections(ConnectionRepository connectionRepository) { MultiValueMap<String, Connection<?>> connections = connectionRepository.findAllConnections(); List<Connection<?>> allConnections = new ArrayList<Connection<?>>(); if (connections.size() > 0) { for (List<Connection<?>> connectionList : connections.values()) { for (Connection<?> connection : connectionList) { allConnections.add(connection); } } } return allConnections; }
Example #7
Source File: IndexServiceOfflineImpl.java From cloudstreetmarket.com with GNU General Public License v3.0 | 5 votes |
private void updateChartIndexFromYahoo(Index index, ChartType type, ChartHistoSize histoSize, ChartHistoMovingAverage histoAverage, ChartHistoTimeSpan histoPeriod, Integer intradayWidth, Integer intradayHeight) { Preconditions.checkNotNull(index, "index must not be null!"); Preconditions.checkNotNull(type, "ChartType must not be null!"); String guid = AuthenticationUtil.getPrincipal().getUsername(); String token = usersConnectionRepository.getRegisteredSocialUser(guid).getAccessToken(); ConnectionRepository connectionRepository = usersConnectionRepository.createConnectionRepository(guid); Connection<Yahoo2> connection = connectionRepository.getPrimaryConnection(Yahoo2.class); if (connection != null) { byte[] yahooChart = connection.getApi().financialOperations().getYahooChart(index.getId(), type, histoSize, histoAverage, histoPeriod, intradayWidth, intradayHeight, token); DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd_HHmm"); LocalDateTime dateTime = LocalDateTime.now(); String formattedDateTime = dateTime.format(formatter); // "1986-04-08_1230" String imageName = index.getId().toLowerCase()+"_"+type.name().toLowerCase()+"_"+formattedDateTime+".png"; String pathToYahooPicture = env.getProperty("user.home").concat(env.getProperty("pictures.yahoo.path")).concat(File.separator+imageName); try { Path newPath = Paths.get(pathToYahooPicture); Files.write(newPath, yahooChart, StandardOpenOption.CREATE); } catch (IOException e) { throw new Error("Storage of " + pathToYahooPicture+ " failed", e); } ChartIndex chartIndex = new ChartIndex(index, type, histoSize, histoAverage, histoPeriod, intradayWidth, intradayHeight, pathToYahooPicture); chartIndexRepository.save(chartIndex); } }
Example #8
Source File: IndexServiceOfflineImpl.java From cloudstreetmarket.com with GNU General Public License v3.0 | 5 votes |
private void updateIndexAndQuotesFromYahoo(Set<Index> askedContent) { Set<Index> recentlyUpdated = askedContent.stream() .filter(t -> t.getLastUpdate() != null && DateUtil.isRecent(t.getLastUpdate(), 1)) .collect(Collectors.toSet()); if(askedContent.size() != recentlyUpdated.size()){ String guid = AuthenticationUtil.getPrincipal().getUsername(); String token = usersConnectionRepository.getRegisteredSocialUser(guid).getAccessToken(); ConnectionRepository connectionRepository = usersConnectionRepository.createConnectionRepository(guid); Connection<Yahoo2> connection = connectionRepository.getPrimaryConnection(Yahoo2.class); if (connection != null) { askedContent.removeAll(recentlyUpdated); List<String> updatableTickers = askedContent.stream() .map(Index::getId) .collect(Collectors.toList()); List<YahooQuote> yahooQuotes = connection.getApi().financialOperations().getYahooQuotes(updatableTickers, token); Set<Index> upToDateIndex = yahooQuotes.stream() .map(t -> yahooIndexConverter.convert(t)) .collect(Collectors.toSet()); final Map<String, Index> persistedStocks = indexRepository.save(upToDateIndex).stream() .collect(Collectors.toMap(Index::getId, Function.identity())); Set<IndexQuote> updatableQuotes = yahooQuotes.stream() .map(sq -> new IndexQuote(sq, persistedStocks.get(sq.getId()))) .collect(Collectors.toSet()); indexQuoteRepository.save(updatableQuotes); } } }
Example #9
Source File: StockProductServiceOfflineImpl.java From cloudstreetmarket.com with GNU General Public License v3.0 | 5 votes |
private void updateChartStockFromYahoo(StockProduct stock, ChartType type, ChartHistoSize histoSize, ChartHistoMovingAverage histoAverage, ChartHistoTimeSpan histoPeriod, Integer intradayWidth, Integer intradayHeight) { Preconditions.checkNotNull(stock, "stock must not be null!"); Preconditions.checkNotNull(type, "ChartType must not be null!"); String guid = AuthenticationUtil.getPrincipal().getUsername(); String token = usersConnectionRepository.getRegisteredSocialUser(guid).getAccessToken(); ConnectionRepository connectionRepository = usersConnectionRepository.createConnectionRepository(guid); Connection<Yahoo2> connection = connectionRepository.getPrimaryConnection(Yahoo2.class); if (connection != null) { byte[] yahooChart = connection.getApi().financialOperations().getYahooChart(stock.getId(), type, histoSize, histoAverage, histoPeriod, intradayWidth, intradayHeight, token); DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd_HHmm"); LocalDateTime dateTime = LocalDateTime.now(); String formattedDateTime = dateTime.format(formatter); // "1986-04-08_1230" String imageName = stock.getId().toLowerCase()+"_"+type.name().toLowerCase()+"_"+formattedDateTime+".png"; String pathToYahooPicture = env.getProperty("pictures.yahoo.path").concat(File.separator+imageName); try { Path newPath = Paths.get(pathToYahooPicture); Files.write(newPath, yahooChart, StandardOpenOption.CREATE); } catch (IOException e) { throw new Error("Storage of " + pathToYahooPicture+ " failed", e); } ChartStock chartStock = new ChartStock(stock, type, histoSize, histoAverage, histoPeriod, intradayWidth, intradayHeight, pathToYahooPicture); chartStockRepository.save(chartStock); } }
Example #10
Source File: SocialUserServiceImpl.java From cloudstreetmarket.com with GNU General Public License v3.0 | 5 votes |
public ConnectionRepository createConnectionRepository(String userId) { if (userId == null) { throw new IllegalArgumentException("userId cannot be null"); } return new SocialUserConnectionRepositoryImpl( userId, socialUserRepository, connectionFactoryLocator, textEncryptor); }
Example #11
Source File: _SocialService.java From jhipster-ribbon-hystrix with GNU General Public License v3.0 | 5 votes |
public void deleteUserSocialConnection(String login) { ConnectionRepository connectionRepository = usersConnectionRepository.createConnectionRepository(login); connectionRepository.findAllConnections().keySet().stream() .forEach(providerId -> { connectionRepository.removeConnections(providerId); log.debug("Delete user social connection providerId: {}", providerId); }); }
Example #12
Source File: FacebookConfiguration.java From OAuth-2.0-Cookbook with MIT License | 5 votes |
@Bean public ConnectController connectController( ConnectionFactoryLocator factoryLocator, ConnectionRepository repository) { ConnectController controller = new ConnectController( factoryLocator, repository); controller.setApplicationUrl("http://localhost:8080"); return controller; }
Example #13
Source File: FacebookConfiguration.java From OAuth-2.0-Cookbook with MIT License | 5 votes |
@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; }
Example #14
Source File: GitHubConfiguration.java From OAuth-2.0-Cookbook with MIT License | 5 votes |
@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; }
Example #15
Source File: LinkedInConfiguration.java From OAuth-2.0-Cookbook with MIT License | 5 votes |
@Bean public ConnectController connectController(ConnectionFactoryLocator locator, ConnectionRepository repository) { ConnectController controller = new ConnectController(locator, repository); controller.setApplicationUrl("http://localhost:8080"); return controller; }
Example #16
Source File: GitHubConfiguration.java From OAuth-2.0-Cookbook with MIT License | 5 votes |
@Bean public ConnectController connectController( ConnectionFactoryLocator factoryLocator, ConnectionRepository repository) { ConnectController controller = new ConnectController( factoryLocator, repository); controller.setApplicationUrl("http://localhost:8080"); return controller; }
Example #17
Source File: GoogleConfigurerAdapter.java From OAuth-2.0-Cookbook with MIT License | 5 votes |
@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; }
Example #18
Source File: SocialWebAutoConfiguration.java From spring-security-oauth2-boot with Apache License 2.0 | 5 votes |
@Bean @ConditionalOnMissingBean(ConnectController.class) public ConnectController connectController(ConnectionFactoryLocator factoryLocator, ConnectionRepository repository) { ConnectController controller = new ConnectController(factoryLocator, repository); if (!CollectionUtils.isEmpty(this.connectInterceptors)) { controller.setConnectInterceptors(this.connectInterceptors); } if (!CollectionUtils.isEmpty(this.disconnectInterceptors)) { controller.setDisconnectInterceptors(this.disconnectInterceptors); } return controller; }
Example #19
Source File: FacebookAutoConfiguration.java From spring-security-oauth2-boot with Apache License 2.0 | 5 votes |
@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; }
Example #20
Source File: FebsSocialWebAutoConfiguration.java From FEBS-Security with Apache License 2.0 | 5 votes |
@Bean @ConditionalOnMissingBean(ConnectController.class) public ConnectController connectController( ConnectionFactoryLocator factoryLocator, ConnectionRepository repository) { ConnectController controller = new ConnectController(factoryLocator, repository); if (!CollectionUtils.isEmpty(this.connectInterceptors)) { controller.setConnectInterceptors(this.connectInterceptors); } if (!CollectionUtils.isEmpty(this.disconnectInterceptors)) { controller.setDisconnectInterceptors(this.disconnectInterceptors); } return controller; }
Example #21
Source File: GitHubConfiguration.java From oauth2lab with MIT License | 5 votes |
@Bean public ConnectController connectController( ConnectionFactoryLocator factoryLocator, ConnectionRepository repository) { ConnectController controller = new ConnectController( factoryLocator, repository); controller.setApplicationUrl("http://localhost:8080"); return controller; }
Example #22
Source File: GitHubConfiguration.java From oauth2lab with MIT License | 5 votes |
@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; }
Example #23
Source File: GitHubConfiguration.java From codeway_service with GNU General Public License v3.0 | 5 votes |
@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; }
Example #24
Source File: GitHubConfiguration.java From codeway_service with GNU General Public License v3.0 | 5 votes |
@Bean public ConnectController connectController( ConnectionFactoryLocator factoryLocator, ConnectionRepository repository) { ConnectController controller = new ConnectController( factoryLocator, repository); controller.setApplicationUrl("http://localhost:8090"); return controller; }
Example #25
Source File: GitHubConfiguration.java From codeway_service with GNU General Public License v3.0 | 5 votes |
@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; }
Example #26
Source File: SocialConfig.java From JiwhizBlogWeb with Apache License 2.0 | 4 votes |
@Bean @Scope(value = "request", proxyMode = ScopedProxyMode.INTERFACES) public Google google(ConnectionRepository repository) { Connection<Google> connection = repository.findPrimaryConnection(Google.class); return connection != null ? connection.getApi() : new GoogleTemplate(); }
Example #27
Source File: MyConnectController.java From JiwhizBlogWeb with Apache License 2.0 | 4 votes |
@Inject public MyConnectController(ConnectionFactoryLocator connectionFactoryLocator, ConnectionRepository connectionRepository) { super(connectionFactoryLocator, connectionRepository); }
Example #28
Source File: MongoUsersConnectionRepositoryImpl.java From JiwhizBlogWeb with Apache License 2.0 | 4 votes |
public ConnectionRepository createConnectionRepository(String userId) { if (userId == null) { throw new IllegalArgumentException("userId cannot be null"); } return new MongoConnectionRepositoryImpl(userId, userSocialConnectionRepository, socialAuthenticationServiceLocator, textEncryptor); }
Example #29
Source File: SpringSocialUserDetailService.java From AIDR with GNU Affero General Public License v3.0 | 4 votes |
@Override public UserDetails loadUserByUsername(String combinedUserName)throws UsernameNotFoundException { String provider = combinedUserName.substring(0, combinedUserName.indexOf(Constants.USER_NAME_SPLITTER)); String userName = combinedUserName.substring(combinedUserName.indexOf(Constants.USER_NAME_SPLITTER)+1); ConnectionRepository connectionRepository = usersConnectionRepository.createConnectionRepository(userName); SpringSocialProfile springSocialProfile = null; //Fetching user with provider id springSecurity try{ springSocialProfile = signUpService.getUserProfile(userName); }catch(Exception e){ logger.error("Multiple accounts exist with same userName: "+userName,e); } List<Connection<?>> allConnections = getConnections(connectionRepository); if (allConnections.size() > 0) { Authentication authentication = null; if(springSocialProfile == null){ UserConnection userProfile = userConnectionService.getByUserIdAndProviderId(userName, provider); authentication = authenticationFactory.createAuthenticationForAllConnections(combinedUserName, userProfile.getAccessToken(),allConnections); }else{ authentication = authenticationFactory.createAuthenticationForAllConnections(combinedUserName, springSocialProfile.getPassword(),allConnections); } UserAccount user = userService.fetchByUserName(combinedUserName); List<GrantedAuthority> authorities = new ArrayList<GrantedAuthority>(); authorities.addAll(authentication.getAuthorities()); List<RoleType> roles = userService.getUserRoles(user.getId()); if(roles != null && !roles.isEmpty() ){ for(RoleType role : roles){ GrantedAuthority authority = new SimpleGrantedAuthority(role.name()); authorities.add(authority); } } return new User(combinedUserName, authentication.getCredentials().toString(), true, true, true, true,authorities); } else { logger.info("UsernameNotFoundException for user: "+combinedUserName); throw new UsernameNotFoundException(combinedUserName); } }
Example #30
Source File: SpringSocialUserDetailService.java From AIDR with GNU Affero General Public License v3.0 | 4 votes |
@Override public UserDetails loadUserByUsername(String combinedUserName)throws UsernameNotFoundException { String provider = combinedUserName.substring(0, combinedUserName.indexOf(ConstantUtils.USER_NAME_SPLITTER)); String userName = combinedUserName.substring(combinedUserName.indexOf(ConstantUtils.USER_NAME_SPLITTER)+1); ConnectionRepository connectionRepository = usersConnectionRepository.createConnectionRepository(userName); SpringSocialProfile springSocialProfile = null; try{ springSocialProfile = signUpService.getUserProfile(userName); }catch(Exception e){ logger.error("Multiple accounts exist with same userName: "+userName,e); } List<Connection<?>> allConnections = getConnections(connectionRepository); if (allConnections.size() > 0) { Authentication authentication = null; if(springSocialProfile == null){ UserConnection userProfile = userConnectionService.getByProviderIdAndUserId(provider, userName); authentication = authenticationFactory.createAuthenticationForAllConnections(combinedUserName, userProfile.getAccessToken(),allConnections); }else{ authentication = authenticationFactory.createAuthenticationForAllConnections(combinedUserName, springSocialProfile.getPassword(),allConnections); } UserAccount user = userService.fetchByUserName(combinedUserName); List<GrantedAuthority> authorities = new ArrayList<GrantedAuthority>(); authorities.addAll(authentication.getAuthorities()); List<RoleType> roles = userService.getUserRoles(user.getId()); if(roles != null && !roles.isEmpty() ){ for(RoleType role : roles){ GrantedAuthority authority = new SimpleGrantedAuthority(role.name()); authorities.add(authority); } } return new User(combinedUserName, authentication.getCredentials().toString(), true, true, true, true,authorities); } else { logger.info("UsernameNotFoundException for user: "+combinedUserName); throw new UsernameNotFoundException(combinedUserName); } }