forked from xkcoding/spring-boot-demo
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
17 changed files
with
690 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 2 additions & 0 deletions
2
...g-boot-demo-social/src/main/java/com/xkcoding/social/SpringBootDemoSocialApplication.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
spring-boot-demo-social/src/main/java/com/xkcoding/social/config/DemoSocialConfigure.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package com.xkcoding.social.config; | ||
|
||
import org.springframework.social.security.SocialAuthenticationFilter; | ||
import org.springframework.social.security.SpringSocialConfigurer; | ||
|
||
/** | ||
* <p> | ||
* 继承默认的社交登录配置,加入自定义的后处理逻辑 | ||
* </p> | ||
* | ||
* @package: com.xkcoding.social.config | ||
* @description: 继承默认的社交登录配置,加入自定义的后处理逻辑 | ||
* @author: yangkai.shen | ||
* @date: Created in 2019-02-21 14:01 | ||
* @copyright: Copyright (c) 2019 | ||
* @version: V1.0 | ||
* @modified: yangkai.shen | ||
*/ | ||
public class DemoSocialConfigure extends SpringSocialConfigurer { | ||
private String filterProcessUrl; | ||
|
||
public DemoSocialConfigure(String filterProcessUrl) { | ||
this.filterProcessUrl = filterProcessUrl; | ||
} | ||
|
||
@Override | ||
protected <T> T postProcess(T object) { | ||
SocialAuthenticationFilter socialAuthenticationFilter = (SocialAuthenticationFilter) super.postProcess(object); | ||
socialAuthenticationFilter.setFilterProcessesUrl(filterProcessUrl); | ||
return (T) socialAuthenticationFilter; | ||
} | ||
} |
34 changes: 34 additions & 0 deletions
34
spring-boot-demo-social/src/main/java/com/xkcoding/social/config/DemoUserDetailService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package com.xkcoding.social.config; | ||
|
||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.security.core.authority.AuthorityUtils; | ||
import org.springframework.security.core.userdetails.UsernameNotFoundException; | ||
import org.springframework.security.crypto.password.PasswordEncoder; | ||
import org.springframework.social.security.SocialUser; | ||
import org.springframework.social.security.SocialUserDetails; | ||
import org.springframework.social.security.SocialUserDetailsService; | ||
import org.springframework.stereotype.Service; | ||
|
||
/** | ||
* <p> | ||
* 根据userId获取用户信息 | ||
* </p> | ||
* | ||
* @package: com.xkcoding.social.config | ||
* @description: 根据userId获取用户信息 | ||
* @author: yangkai.shen | ||
* @date: Created in 2019-02-21 14:41 | ||
* @copyright: Copyright (c) 2019 | ||
* @version: V1.0 | ||
* @modified: yangkai.shen | ||
*/ | ||
@Service | ||
public class DemoUserDetailService implements SocialUserDetailsService { | ||
@Autowired | ||
private PasswordEncoder passwordEncoder; | ||
|
||
@Override | ||
public SocialUserDetails loadUserByUserId(String userId) throws UsernameNotFoundException { | ||
return new SocialUser(userId, passwordEncoder.encode("123456"), AuthorityUtils.commaSeparatedStringToAuthorityList("xxx")); | ||
} | ||
} |
34 changes: 34 additions & 0 deletions
34
spring-boot-demo-social/src/main/java/com/xkcoding/social/config/QQProperties.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package com.xkcoding.social.config; | ||
|
||
import lombok.Data; | ||
|
||
/** | ||
* <p> | ||
* QQ 配置 | ||
* </p> | ||
* | ||
* @package: com.xkcoding.social.config | ||
* @description: QQ 配置 | ||
* @author: yangkai.shen | ||
* @date: Created in 2019-02-21 14:20 | ||
* @copyright: Copyright (c) 2019 | ||
* @version: V1.0 | ||
* @modified: yangkai.shen | ||
*/ | ||
@Data | ||
public class QQProperties { | ||
/** | ||
* 第三方应用标识 | ||
*/ | ||
private String providerId = "qq"; | ||
|
||
/** | ||
* clientId | ||
*/ | ||
private String clientId; | ||
|
||
/** | ||
* clientSecret | ||
*/ | ||
private String clientSecret; | ||
} |
67 changes: 67 additions & 0 deletions
67
spring-boot-demo-social/src/main/java/com/xkcoding/social/config/SocialConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
package com.xkcoding.social.config; | ||
|
||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.boot.context.properties.EnableConfigurationProperties; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; | ||
import org.springframework.security.crypto.encrypt.Encryptors; | ||
import org.springframework.security.crypto.password.PasswordEncoder; | ||
import org.springframework.social.UserIdSource; | ||
import org.springframework.social.config.annotation.EnableSocial; | ||
import org.springframework.social.config.annotation.SocialConfigurerAdapter; | ||
import org.springframework.social.connect.ConnectionFactoryLocator; | ||
import org.springframework.social.connect.UsersConnectionRepository; | ||
import org.springframework.social.connect.jdbc.JdbcUsersConnectionRepository; | ||
import org.springframework.social.security.AuthenticationNameUserIdSource; | ||
import org.springframework.social.security.SpringSocialConfigurer; | ||
|
||
import javax.sql.DataSource; | ||
|
||
/** | ||
* <p> | ||
* 社交登录配置 | ||
* </p> | ||
* | ||
* @package: com.xkcoding.social.config | ||
* @description: 社交登录配置 | ||
* @author: yangkai.shen | ||
* @date: Created in 2019-02-21 13:52 | ||
* @copyright: Copyright (c) 2019 | ||
* @version: V1.0 | ||
* @modified: yangkai.shen | ||
*/ | ||
@Configuration | ||
@EnableSocial | ||
@EnableConfigurationProperties({SocialProperties.class}) | ||
public class SocialConfig extends SocialConfigurerAdapter { | ||
@Autowired | ||
private DataSource dataSource; | ||
|
||
@Autowired | ||
private SocialProperties socialProperties; | ||
|
||
@Override | ||
public UsersConnectionRepository getUsersConnectionRepository(ConnectionFactoryLocator connectionFactoryLocator) { | ||
JdbcUsersConnectionRepository jdbcUsersConnectionRepository = new JdbcUsersConnectionRepository(dataSource, connectionFactoryLocator, Encryptors | ||
.noOpText()); | ||
jdbcUsersConnectionRepository.setTablePrefix("demo_"); | ||
return jdbcUsersConnectionRepository; | ||
} | ||
|
||
@Bean | ||
public SpringSocialConfigurer springSocialConfigurer() { | ||
DemoSocialConfigure demoSocialConfigure = new DemoSocialConfigure(socialProperties.getFilterProcessUrl()); | ||
return demoSocialConfigure; | ||
} | ||
|
||
@Bean | ||
public PasswordEncoder passwordEncoder() { | ||
return new BCryptPasswordEncoder(); | ||
} | ||
|
||
@Override | ||
public UserIdSource getUserIdSource() { | ||
return new AuthenticationNameUserIdSource(); | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
spring-boot-demo-social/src/main/java/com/xkcoding/social/config/SocialProperties.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package com.xkcoding.social.config; | ||
|
||
import lombok.Data; | ||
import org.springframework.boot.context.properties.ConfigurationProperties; | ||
|
||
/** | ||
* <p> | ||
* 社交登录配置类 | ||
* </p> | ||
* | ||
* @package: com.xkcoding.social.config | ||
* @description: 社交登录配置类 | ||
* @author: yangkai.shen | ||
* @date: Created in 2019-02-21 14:12 | ||
* @copyright: Copyright (c) 2019 | ||
* @version: V1.0 | ||
* @modified: yangkai.shen | ||
*/ | ||
@Data | ||
@ConfigurationProperties(prefix = "demo.social") | ||
public class SocialProperties { | ||
private String filterProcessUrl = "/auth"; | ||
|
||
private QQProperties qq = new QQProperties(); | ||
} |
24 changes: 24 additions & 0 deletions
24
spring-boot-demo-social/src/main/java/com/xkcoding/social/qq/api/QQ.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package com.xkcoding.social.qq.api; | ||
|
||
/** | ||
* <p> | ||
* 获取QQ用户信息接口 | ||
* </p> | ||
* | ||
* @package: com.xkcoding.social.qq.api | ||
* @description: 获取QQ用户信息接口 | ||
* @author: yangkai.shen | ||
* @date: Created in 2019-02-21 10:52 | ||
* @copyright: Copyright (c) 2019 | ||
* @version: V1.0 | ||
* @modified: yangkai.shen | ||
*/ | ||
public interface QQ { | ||
|
||
/** | ||
* 获取QQ用户信息 | ||
* @return QQ用户信息 | ||
*/ | ||
QQUserInfo getUserInfo(); | ||
|
||
} |
82 changes: 82 additions & 0 deletions
82
spring-boot-demo-social/src/main/java/com/xkcoding/social/qq/api/QQUserInfo.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
package com.xkcoding.social.qq.api; | ||
|
||
import lombok.Data; | ||
|
||
/** | ||
* <p> | ||
* QQ用户信息 | ||
* </p> | ||
* | ||
* @package: com.xkcoding.social.qq.api | ||
* @description: QQ用户信息 | ||
* @author: yangkai.shen | ||
* @date: Created in 2019-02-21 10:52 | ||
* @copyright: Copyright (c) 2019 | ||
* @version: V1.0 | ||
* @modified: yangkai.shen | ||
*/ | ||
@Data | ||
public class QQUserInfo { | ||
/** | ||
* QQ唯一标识 | ||
*/ | ||
private String openId; | ||
/** | ||
* 返回码 | ||
*/ | ||
private String ret; | ||
/** | ||
* 如果ret<0,会有相应的错误信息提示,返回数据全部用UTF-8编码。 | ||
*/ | ||
private String msg; | ||
/** | ||
* 用户在QQ空间的昵称。 | ||
*/ | ||
private String nickname; | ||
/** | ||
* 大小为30×30像素的QQ空间头像URL。 | ||
*/ | ||
private String figureurl; | ||
/** | ||
* 大小为50×50像素的QQ空间头像URL。 | ||
*/ | ||
private String figureurl_1; | ||
/** | ||
* 大小为100×100像素的QQ空间头像URL。 | ||
*/ | ||
private String figureurl_2; | ||
/** | ||
* 大小为40×40像素的QQ头像URL。 | ||
*/ | ||
private String figureurl_qq_1; | ||
/** | ||
* 大小为100×100像素的QQ头像URL。需要注意,不是所有的用户都拥有QQ的100x100的头像,但40x40像素则是一定会有。 | ||
*/ | ||
private String figureurl_qq_2; | ||
/** | ||
* 性别。 如果获取不到则默认返回"男" | ||
*/ | ||
private String gender; | ||
/** | ||
* 是否黄钻 | ||
*/ | ||
private String is_yellow_vip; | ||
/** | ||
* 是否会员 | ||
*/ | ||
private String vip; | ||
/** | ||
* 黄钻等级 | ||
*/ | ||
private String yellow_vip_level; | ||
/** | ||
* 会员等级 | ||
*/ | ||
private String level; | ||
/** | ||
* 是否年费黄钻 | ||
*/ | ||
private String is_yellow_year_vip; | ||
|
||
|
||
} |
Oops, something went wrong.