Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | ||||
4 | 5 | 6 | 7 | 8 | 9 | 10 |
11 | 12 | 13 | 14 | 15 | 16 | 17 |
18 | 19 | 20 | 21 | 22 | 23 | 24 |
25 | 26 | 27 | 28 | 29 | 30 | 31 |
Tags
- 알고리즘
- Spring
- 빅데이터
- sort
- 재귀
- data
- 설치
- linux
- Amazon
- 레드햇
- big data
- 리눅스
- algorithm
- 스토리지
- 스프링
- hadoop
- Data Structure
- 자바
- rhcsa
- java
- 하둡
- 도커
- redhat
- AWS
- docker
- storage
- 자료구조
- Redshift
- recursive
- 아마존
Archives
- Today
- Total
Developer MJ
[Spring Social] Social Configuration 본문
- Maven pom.xml로 Spring Social Dependency 추가
- Application.properties 파일에 Connection 유지를 위한 H2 Database 설정과 소셜미디어 AppID와 Secret 설정
- Spring Social 관련 Configuration Bean 등록
1. ConnectionFactoryLocator
2. UsersConnectRepository
3. ConnectionRepository
4. Facebook
5. Twitter
6. Google
import javax.sql.DataSource;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Scope;
import org.springframework.context.annotation.ScopedProxyMode;
import org.springframework.core.env.Environment;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.security.crypto.encrypt.Encryptors;
import org.springframework.social.UserIdSource;
import org.springframework.social.config.annotation.SocialConfigurerAdapter;
import org.springframework.social.connect.Connection;
import org.springframework.social.connect.ConnectionFactoryLocator;
import org.springframework.social.connect.ConnectionRepository;
import org.springframework.social.connect.UsersConnectionRepository;
import org.springframework.social.connect.jdbc.JdbcUsersConnectionRepository;
import org.springframework.social.connect.support.ConnectionFactoryRegistry;
import org.springframework.social.facebook.api.Facebook;
import org.springframework.social.google.api.Google;
import org.springframework.social.google.connect.GoogleConnectionFactory;
import org.springframework.social.security.AuthenticationNameUserIdSource;
import org.springframework.social.twitter.api.Twitter;
@Configuration
public class SocialConfig extends SocialConfigurerAdapter {
@Autowired
private DataSource dataSource;
@Autowired
private Environment environment;
@Bean
public UserIdSource getUserIdSource() {
return new AuthenticationNameUserIdSource();
}
/*
* 각 소셜 미디어 AppID와 Secret 등록
* Facebook과 Twitter는 properties에서 바로 적용가능
*/
@Bean
@Scope(value = "singleton", proxyMode = ScopedProxyMode.INTERFACES)
public ConnectionFactoryLocator connectionFactoryLocator() {
ConnectionFactoryRegistry registry = new ConnectionFactoryRegistry();
registry.addConnectionFactory(new GoogleConnectionFactory(environment.getProperty("google.consumerKey"),
environment.getProperty("google.consumerSecret")));
return registry;
}
/*
* 소셜미디어와의 Connection을 database에서 관리할 수 있도록 JDBC연결
*/
@Bean
@Scope(value = "singleton", proxyMode = ScopedProxyMode.INTERFACES)
public UsersConnectionRepository usersConnectionRepository() {
return new JdbcUsersConnectionRepository(dataSource, connectionFactoryLocator(), Encryptors.noOpText());
}
@Bean
@Scope(value = "request", proxyMode = ScopedProxyMode.INTERFACES)
public ConnectionRepository connectionRepository() {
Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
if (authentication == null) {
throw new IllegalStateException("Unable to get a ConnectionRepository : no user signed in");
}
return usersConnectionRepository().createConnectionRepository(authentication.getName());
}
/*
* 소셜미디어의 API Binding
*/
@Bean
@Scope(value = "request", proxyMode = ScopedProxyMode.INTERFACES)
public Facebook facebook() {
Connection facebook = connectionRepository().findPrimaryConnection(Facebook.class);
return facebook.getApi();
}
@Bean
@Scope(value = "request", proxyMode = ScopedProxyMode.INTERFACES)
public Twitter twitter() {
Connection twitter = connectionRepository().findPrimaryConnection(Twitter.class);
return twitter.getApi();
}
@Bean
@Scope(value = "request", proxyMode = ScopedProxyMode.INTERFACES)
public Google google(){
Connection google = connectionRepository().findPrimaryConnection(Google.class);
return google.getApi();
}
}
'Framework > Spring' 카테고리의 다른 글
[Spring Social] ProviderSignInController (0) | 2017.08.31 |
---|---|
[Spring Soical] ConnectController (0) | 2017.08.31 |
[MAVEN] Local Repository 등록 (OJDBC) (0) | 2017.07.26 |
[Spring] Spring & Eclipse 시작하기 part-2 (0) | 2017.02.07 |
[Spring] Spring & Eclipse 시작하기 part-1 (0) | 2017.02.04 |