.ExpressionInterceptUrlRegistry config);
17 | }
18 |
--------------------------------------------------------------------------------
/security-core/src/main/java/com/earthchen/security/core/properties/ImageCodeProperties.java:
--------------------------------------------------------------------------------
1 | package com.earthchen.security.core.properties;
2 |
3 | /**
4 | * 图片验证码选项
5 | */
6 | public class ImageCodeProperties extends SmsCodeProperties {
7 |
8 | public ImageCodeProperties() {
9 | setLength(4);
10 | }
11 |
12 | /**
13 | * 验证码的宽
14 | */
15 | private int width = 67;
16 |
17 | /**
18 | * 验证码的高
19 | */
20 | private int height = 23;
21 |
22 | public int getWidth() {
23 | return width;
24 | }
25 | public void setWidth(int width) {
26 | this.width = width;
27 | }
28 | public int getHeight() {
29 | return height;
30 | }
31 | public void setHeight(int height) {
32 | this.height = height;
33 | }
34 | }
35 |
--------------------------------------------------------------------------------
/security-core/src/main/java/com/earthchen/security/core/properties/LoginResponseType.java:
--------------------------------------------------------------------------------
1 | package com.earthchen.security.core.properties;
2 |
3 | public enum LoginResponseType {
4 |
5 | /**
6 | * 跳转
7 | */
8 | REDIRECT,
9 |
10 | /**
11 | * 返回json
12 | */
13 | JSON
14 |
15 | }
--------------------------------------------------------------------------------
/security-core/src/main/java/com/earthchen/security/core/properties/OAuth2ClientProperties.java:
--------------------------------------------------------------------------------
1 | package com.earthchen.security.core.properties;
2 |
3 | /**
4 | * 认证服务器注册的第三方应用配置项
5 | */
6 | public class OAuth2ClientProperties {
7 |
8 | /**
9 | * 第三方应用appId
10 | */
11 | private String clientId;
12 | /**
13 | * 第三方应用appSecret
14 | */
15 | private String clientSecret;
16 | /**
17 | * 针对此应用发出的token的有效时间
18 | */
19 | private int accessTokenValidateSeconds = 7200;
20 |
21 | public String getClientId() {
22 | return clientId;
23 | }
24 |
25 | public void setClientId(String clientId) {
26 | this.clientId = clientId;
27 | }
28 |
29 | public String getClientSecret() {
30 | return clientSecret;
31 | }
32 |
33 | public void setClientSecret(String clientSecret) {
34 | this.clientSecret = clientSecret;
35 | }
36 |
37 | public int getAccessTokenValidateSeconds() {
38 | return accessTokenValidateSeconds;
39 | }
40 |
41 | public void setAccessTokenValidateSeconds(int accessTokenValidateSeconds) {
42 | this.accessTokenValidateSeconds = accessTokenValidateSeconds;
43 | }
44 | }
45 |
--------------------------------------------------------------------------------
/security-core/src/main/java/com/earthchen/security/core/properties/OAuth2Properties.java:
--------------------------------------------------------------------------------
1 | package com.earthchen.security.core.properties;
2 |
3 |
4 | /**
5 | * oauth2配置
6 | */
7 | public class OAuth2Properties {
8 |
9 | /**
10 | * 客户端配置
11 | */
12 | private OAuth2ClientProperties[] clients = {};
13 |
14 | /**
15 | * jwt的签名
16 | */
17 | private String jwtSigningKey = "earthchen";
18 |
19 | public OAuth2ClientProperties[] getClients() {
20 | return clients;
21 | }
22 |
23 | public void setClients(OAuth2ClientProperties[] clients) {
24 | this.clients = clients;
25 | }
26 |
27 | public String getJwtSigningKey() {
28 | return jwtSigningKey;
29 | }
30 |
31 | public void setJwtSigningKey(String jwtSigningKey) {
32 | this.jwtSigningKey = jwtSigningKey;
33 | }
34 |
35 |
36 | }
37 |
--------------------------------------------------------------------------------
/security-core/src/main/java/com/earthchen/security/core/properties/QQProperties.java:
--------------------------------------------------------------------------------
1 | package com.earthchen.security.core.properties;
2 |
3 | import org.springframework.boot.autoconfigure.social.SocialProperties;
4 |
5 | /**
6 | * qq登录配置项
7 | */
8 | public class QQProperties extends SocialProperties {
9 |
10 | /**
11 | * providerId
12 | */
13 | private String providerId = "qq";
14 |
15 | public String getProviderId() {
16 | return providerId;
17 | }
18 |
19 | public void setProviderId(String providerId) {
20 | this.providerId = providerId;
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/security-core/src/main/java/com/earthchen/security/core/properties/SessionProperties.java:
--------------------------------------------------------------------------------
1 | package com.earthchen.security.core.properties;
2 |
3 | /**
4 | * session配置
5 | */
6 | public class SessionProperties {
7 |
8 | /**
9 | * 同一个用户在系统中的最大session数,默认1
10 | */
11 | private int maximumSessions = 1;
12 | /**
13 | * 达到最大session时是否阻止新的登录请求,默认为false,不阻止,新的登录会将老的登录失效掉
14 | */
15 | private boolean maxSessionsPreventsLogin;
16 | /**
17 | * session失效时跳转的地址
18 | */
19 | private String sessionInvalidUrl = SecurityConstants.DEFAULT_SESSION_INVALID_URL;
20 |
21 | public int getMaximumSessions() {
22 | return maximumSessions;
23 | }
24 |
25 | public void setMaximumSessions(int maximumSessions) {
26 | this.maximumSessions = maximumSessions;
27 | }
28 |
29 | public boolean isMaxSessionsPreventsLogin() {
30 | return maxSessionsPreventsLogin;
31 | }
32 |
33 | public void setMaxSessionsPreventsLogin(boolean maxSessionsPreventsLogin) {
34 | this.maxSessionsPreventsLogin = maxSessionsPreventsLogin;
35 | }
36 |
37 | public String getSessionInvalidUrl() {
38 | return sessionInvalidUrl;
39 | }
40 |
41 | public void setSessionInvalidUrl(String sessionInvalidUrl) {
42 | this.sessionInvalidUrl = sessionInvalidUrl;
43 | }
44 | }
45 |
--------------------------------------------------------------------------------
/security-core/src/main/java/com/earthchen/security/core/properties/SmsCodeProperties.java:
--------------------------------------------------------------------------------
1 | package com.earthchen.security.core.properties;
2 |
3 | /**
4 | * 短信验证码配置项
5 | */
6 | public class SmsCodeProperties {
7 |
8 | /**
9 | * 短信验证码的长度
10 | */
11 | private int length = 6;
12 |
13 | /**
14 | * 过期时间
15 | */
16 | private int expireIn = 60;
17 |
18 | /**
19 | * 需要处理的url
20 | */
21 | private String url;
22 |
23 |
24 | public int getLength() {
25 | return length;
26 | }
27 |
28 | public void setLength(int lenght) {
29 | this.length = lenght;
30 | }
31 |
32 | public int getExpireIn() {
33 | return expireIn;
34 | }
35 |
36 | public void setExpireIn(int expireIn) {
37 | this.expireIn = expireIn;
38 | }
39 |
40 | public String getUrl() {
41 | return url;
42 | }
43 |
44 | public void setUrl(String url) {
45 | this.url = url;
46 | }
47 | }
48 |
--------------------------------------------------------------------------------
/security-core/src/main/java/com/earthchen/security/core/properties/SocialProperties.java:
--------------------------------------------------------------------------------
1 | package com.earthchen.security.core.properties;
2 |
3 | /**
4 | * 社交登录相关配置项
5 | */
6 | public class SocialProperties {
7 |
8 | /**
9 | * qq配置项
10 | *
11 | * @return
12 | */
13 | private QQProperties qq = new QQProperties();
14 |
15 | /**
16 | * 微信配置项
17 | */
18 | private WeixinProperties weixin = new WeixinProperties();
19 |
20 | /**
21 | * 拦截社交登录过滤url
22 | */
23 | private String filterProcessesUrl = "/auth";
24 |
25 | public QQProperties getQq() {
26 | return qq;
27 | }
28 |
29 | public void setQq(QQProperties qq) {
30 | this.qq = qq;
31 | }
32 |
33 | public String getFilterProcessesUrl() {
34 | return filterProcessesUrl;
35 | }
36 |
37 | public void setFilterProcessesUrl(String filterProcessesUrl) {
38 | this.filterProcessesUrl = filterProcessesUrl;
39 | }
40 |
41 | public WeixinProperties getWeixin() {
42 | return weixin;
43 | }
44 |
45 | public void setWeixin(WeixinProperties weixin) {
46 | this.weixin = weixin;
47 | }
48 | }
49 |
--------------------------------------------------------------------------------
/security-core/src/main/java/com/earthchen/security/core/properties/ValidateCodeProperties.java:
--------------------------------------------------------------------------------
1 | package com.earthchen.security.core.properties;
2 |
3 | /**
4 | * 验证码配置
5 | *
6 | * 图形验证码和短信验证码
7 | */
8 | public class ValidateCodeProperties {
9 |
10 | /**
11 | * 图片验证码选项
12 | */
13 | private ImageCodeProperties imageCode = new ImageCodeProperties();
14 |
15 | /**
16 | * 短信验证码
17 | */
18 | private SmsCodeProperties smsCode = new SmsCodeProperties();
19 |
20 |
21 | public SmsCodeProperties getSmsCode() {
22 | return smsCode;
23 | }
24 |
25 | public void setSmsCode(SmsCodeProperties smsCode) {
26 | this.smsCode = smsCode;
27 | }
28 |
29 | public ImageCodeProperties getImageCode() {
30 | return imageCode;
31 | }
32 |
33 | public void setImageCode(ImageCodeProperties imageCode) {
34 | this.imageCode = imageCode;
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/security-core/src/main/java/com/earthchen/security/core/properties/WeixinProperties.java:
--------------------------------------------------------------------------------
1 | package com.earthchen.security.core.properties;
2 |
3 | import org.springframework.boot.autoconfigure.social.SocialProperties;
4 |
5 |
6 | /**
7 | * 微信登录配置项
8 | */
9 | public class WeixinProperties extends SocialProperties {
10 |
11 | /**
12 | * 第三方id,用来决定发起第三方登录的url,默认是 weixin。
13 | */
14 | private String providerId = "weixin";
15 |
16 | /**
17 | * @return the providerId
18 | */
19 | public String getProviderId() {
20 | return providerId;
21 | }
22 |
23 | /**
24 | * @param providerId the providerId to set
25 | */
26 | public void setProviderId(String providerId) {
27 | this.providerId = providerId;
28 | }
29 |
30 |
31 | }
32 |
--------------------------------------------------------------------------------
/security-core/src/main/java/com/earthchen/security/core/social/qq/api/QQ.java:
--------------------------------------------------------------------------------
1 | package com.earthchen.security.core.social.qq.api;
2 |
3 |
4 |
5 | /**
6 | * qq的api
7 | */
8 | public interface QQ {
9 |
10 | /**
11 | * 获取qq的用户信息
12 | * @return
13 | */
14 | QQUserInfo getUserInfo() ;
15 |
16 | }
17 |
--------------------------------------------------------------------------------
/security-core/src/main/java/com/earthchen/security/core/social/qq/config/QQAutoConfig.java:
--------------------------------------------------------------------------------
1 | package com.earthchen.security.core.social.qq.config;
2 |
3 | import com.earthchen.security.core.properties.QQProperties;
4 | import com.earthchen.security.core.properties.SecurityProperties;
5 | import com.earthchen.security.core.social.qq.connet.QQConnectionFactory;
6 | import org.springframework.beans.factory.annotation.Autowired;
7 | import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
8 | import org.springframework.boot.autoconfigure.social.SocialAutoConfigurerAdapter;
9 | import org.springframework.context.annotation.Configuration;
10 | import org.springframework.social.connect.ConnectionFactory;
11 |
12 | @Configuration
13 | @ConditionalOnProperty(prefix = "earthchen.security.social.qq", name = "app-id")
14 | public class QQAutoConfig extends SocialAutoConfigurerAdapter {
15 |
16 | @Autowired
17 | private SecurityProperties securityProperties;
18 |
19 | /**
20 | * qq连接工厂
21 | * @return
22 | */
23 | @Override
24 | protected ConnectionFactory> createConnectionFactory() {
25 | QQProperties qqProperties = securityProperties.getSocial().getQq();
26 | return new QQConnectionFactory(
27 | qqProperties.getProviderId(),
28 | qqProperties.getAppId(),
29 | qqProperties.getAppSecret());
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/security-core/src/main/java/com/earthchen/security/core/social/qq/connet/QQConnectionFactory.java:
--------------------------------------------------------------------------------
1 | package com.earthchen.security.core.social.qq.connet;
2 |
3 | import com.earthchen.security.core.social.qq.api.QQ;
4 | import org.springframework.social.connect.support.OAuth2ConnectionFactory;
5 |
6 | /**
7 | * qq连接工厂
8 | */
9 | public class QQConnectionFactory extends OAuth2ConnectionFactory {
10 |
11 | public QQConnectionFactory(String providerId, String appId, String appSecret) {
12 | super(providerId, new QQServiceProvider(appId, appSecret), new QQAdapter());
13 | }
14 |
15 | }
16 |
--------------------------------------------------------------------------------
/security-core/src/main/java/com/earthchen/security/core/social/support/SocialAuthenticationFilterPostProcessor.java:
--------------------------------------------------------------------------------
1 | package com.earthchen.security.core.social.support;
2 |
3 | import org.springframework.social.security.SocialAuthenticationFilter;
4 |
5 | /**
6 | * 社交认证过滤器后处理器
7 | */
8 | public interface SocialAuthenticationFilterPostProcessor {
9 |
10 | void process(SocialAuthenticationFilter socialAuthenticationFilter);
11 |
12 | }
13 |
--------------------------------------------------------------------------------
/security-core/src/main/java/com/earthchen/security/core/social/support/SocialUserInfo.java:
--------------------------------------------------------------------------------
1 | package com.earthchen.security.core.social.support;
2 |
3 | /**
4 | * 社交用户信息
5 | */
6 | public class SocialUserInfo {
7 |
8 | /**
9 | * 第三方登录的providerId
10 | */
11 | private String providerId;
12 |
13 | /**
14 | * openid
15 | */
16 | private String providerUserId;
17 |
18 | /**
19 | * 用户的昵称
20 | */
21 | private String nickname;
22 |
23 | /**
24 | * 用户的头像
25 | */
26 | private String headimg;
27 |
28 | public String getProviderId() {
29 | return providerId;
30 | }
31 |
32 | public void setProviderId(String providerId) {
33 | this.providerId = providerId;
34 | }
35 |
36 | public String getProviderUserId() {
37 | return providerUserId;
38 | }
39 |
40 | public void setProviderUserId(String providerUserId) {
41 | this.providerUserId = providerUserId;
42 | }
43 |
44 | public String getNickname() {
45 | return nickname;
46 | }
47 |
48 | public void setNickname(String nickname) {
49 | this.nickname = nickname;
50 | }
51 |
52 | public String getHeadimg() {
53 | return headimg;
54 | }
55 |
56 | public void setHeadimg(String headimg) {
57 | this.headimg = headimg;
58 | }
59 | }
60 |
--------------------------------------------------------------------------------
/security-core/src/main/java/com/earthchen/security/core/social/view/ImoocConnectView.java:
--------------------------------------------------------------------------------
1 | package com.earthchen.security.core.social.view;
2 |
3 | import java.util.Map;
4 |
5 | import javax.servlet.http.HttpServletRequest;
6 | import javax.servlet.http.HttpServletResponse;
7 |
8 | import org.springframework.web.servlet.view.AbstractView;
9 |
10 | /**
11 | * 绑定结果视图
12 | */
13 | public class ImoocConnectView extends AbstractView {
14 |
15 | /*
16 | * (non-Javadoc)
17 | *
18 | * @see
19 | * org.springframework.web.servlet.view.AbstractView#renderMergedOutputModel
20 | * (java.util.Map, javax.servlet.http.HttpServletRequest,
21 | * javax.servlet.http.HttpServletResponse)
22 | */
23 | @Override
24 | protected void renderMergedOutputModel(Map model, HttpServletRequest request,
25 | HttpServletResponse response) throws Exception {
26 |
27 | response.setContentType("text/html;charset=UTF-8");
28 | if (model.get("connections") == null) {
29 | response.getWriter().write("解绑成功
");
30 | } else {
31 | response.getWriter().write("绑定成功
");
32 | }
33 |
34 | }
35 |
36 | }
--------------------------------------------------------------------------------
/security-core/src/main/java/com/earthchen/security/core/social/weixin/api/Weixin.java:
--------------------------------------------------------------------------------
1 | package com.earthchen.security.core.social.weixin.api;
2 |
3 | public interface Weixin {
4 |
5 | WeixinUserInfo getUserInfo(String openId);
6 | }
7 |
--------------------------------------------------------------------------------
/security-core/src/main/java/com/earthchen/security/core/social/weixin/connet/WeixinAccessGrant.java:
--------------------------------------------------------------------------------
1 | package com.earthchen.security.core.social.weixin.connet;
2 |
3 |
4 | import org.springframework.social.oauth2.AccessGrant;
5 |
6 | /**
7 | * 微信的access_token信息。与标准OAuth2协议不同,微信在获取access_token时会同时返回openId,并没有单独的通过accessToke换取openId的服务
8 | *
9 | * 所以在这里继承了标准AccessGrant,添加了openId字段,作为对微信access_token信息的封装。
10 | *
11 | *
12 | */
13 | public class WeixinAccessGrant extends AccessGrant {
14 |
15 | /**
16 | *
17 | */
18 | private static final long serialVersionUID = -7243374526633186782L;
19 |
20 | private String openId;
21 |
22 | public WeixinAccessGrant() {
23 | super("");
24 | }
25 |
26 | public WeixinAccessGrant(String accessToken, String scope, String refreshToken, Long expiresIn) {
27 | super(accessToken, scope, refreshToken, expiresIn);
28 | }
29 |
30 | /**
31 | * @return the openId
32 | */
33 | public String getOpenId() {
34 | return openId;
35 | }
36 |
37 | /**
38 | * @param openId the openId to set
39 | */
40 | public void setOpenId(String openId) {
41 | this.openId = openId;
42 | }
43 |
44 | }
45 |
46 |
--------------------------------------------------------------------------------
/security-core/src/main/java/com/earthchen/security/core/social/weixin/connet/WeixinServiceProvider.java:
--------------------------------------------------------------------------------
1 | package com.earthchen.security.core.social.weixin.connet;
2 |
3 | import com.earthchen.security.core.social.weixin.api.Weixin;
4 | import com.earthchen.security.core.social.weixin.api.WeixinImpl;
5 | import org.springframework.social.oauth2.AbstractOAuth2ServiceProvider;
6 |
7 | /**
8 | * 微信的OAuth2流程处理器的提供器,供spring social的connect体系调用
9 | */
10 | public class WeixinServiceProvider extends AbstractOAuth2ServiceProvider {
11 |
12 | /**
13 | * 微信获取授权码的url
14 | */
15 | private static final String URL_AUTHORIZE = "https://open.weixin.qq.com/connect/qrconnect";
16 | /**
17 | * 微信获取accessToken的url
18 | */
19 | private static final String URL_ACCESS_TOKEN = "https://api.weixin.qq.com/sns/oauth2/access_token";
20 |
21 | /**
22 | * @param appId
23 | * @param appSecret
24 | */
25 | public WeixinServiceProvider(String appId, String appSecret) {
26 | super(new WeixinOAuth2Template(appId, appSecret, URL_AUTHORIZE, URL_ACCESS_TOKEN));
27 | }
28 |
29 |
30 | /* (non-Javadoc)
31 | * @see org.springframework.social.oauth2.AbstractOAuth2ServiceProvider#getApi(java.lang.String)
32 | */
33 | @Override
34 | public Weixin getApi(String accessToken) {
35 | return new WeixinImpl(accessToken);
36 | }
37 |
38 | }
39 |
--------------------------------------------------------------------------------
/security-core/src/main/java/com/earthchen/security/core/support/SimpleResponse.java:
--------------------------------------------------------------------------------
1 | package com.earthchen.security.core.support;
2 |
3 | public class SimpleResponse {
4 |
5 | public SimpleResponse(Object content){
6 | this.content = content;
7 | }
8 |
9 | private Object content;
10 |
11 | public Object getContent() {
12 | return content;
13 | }
14 |
15 | public void setContent(Object content) {
16 | this.content = content;
17 | }
18 |
19 | }
--------------------------------------------------------------------------------
/security-core/src/main/java/com/earthchen/security/core/validate/code/ValidateCode.java:
--------------------------------------------------------------------------------
1 | package com.earthchen.security.core.validate.code;
2 |
3 | import java.io.Serializable;
4 | import java.time.LocalDateTime;
5 |
6 | /**
7 | * 验证码父类
8 | */
9 | public class ValidateCode implements Serializable{
10 |
11 | private static final long serialVersionUID = -436475944223625617L;
12 |
13 | private String code;
14 |
15 | private LocalDateTime expireTime;
16 |
17 | public ValidateCode(String code, int expireIn){
18 | this.code = code;
19 | this.expireTime = LocalDateTime.now().plusSeconds(expireIn);
20 | }
21 |
22 | public ValidateCode(String code, LocalDateTime expireTime){
23 | this.code = code;
24 | this.expireTime = expireTime;
25 | }
26 |
27 | public boolean isExpried() {
28 | return LocalDateTime.now().isAfter(expireTime);
29 | }
30 |
31 | public String getCode() {
32 | return code;
33 | }
34 |
35 | public void setCode(String code) {
36 | this.code = code;
37 | }
38 |
39 | public LocalDateTime getExpireTime() {
40 | return expireTime;
41 | }
42 |
43 | public void setExpireTime(LocalDateTime expireTime) {
44 | this.expireTime = expireTime;
45 | }
46 |
47 | }
--------------------------------------------------------------------------------
/security-core/src/main/java/com/earthchen/security/core/validate/code/ValidateCodeException.java:
--------------------------------------------------------------------------------
1 | package com.earthchen.security.core.validate.code;
2 |
3 | import org.springframework.security.core.AuthenticationException;
4 |
5 | /**
6 | * 验证码异常
7 | *
8 | * 继承身份验证异常的基类
9 | */
10 | public class ValidateCodeException extends AuthenticationException {
11 |
12 | private static final long serialVersionUID = 1L;
13 |
14 | /**
15 | * 实现一个父类的构造方法
16 | *
17 | * @param msg
18 | */
19 | public ValidateCodeException(String msg) {
20 | super(msg);
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/security-core/src/main/java/com/earthchen/security/core/validate/code/ValidateCodeGenerator.java:
--------------------------------------------------------------------------------
1 | package com.earthchen.security.core.validate.code;
2 |
3 | import org.springframework.web.context.request.ServletWebRequest;
4 |
5 | /**
6 | * 验证码接口
7 | */
8 | public interface ValidateCodeGenerator {
9 | /**
10 | * 图形验证码实现方法接口
11 | * @param request
12 | * @return
13 | */
14 | ValidateCode generate(ServletWebRequest request);
15 |
16 | }
--------------------------------------------------------------------------------
/security-core/src/main/java/com/earthchen/security/core/validate/code/ValidateCodeProcessor.java:
--------------------------------------------------------------------------------
1 | package com.earthchen.security.core.validate.code;
2 |
3 |
4 | import org.springframework.web.context.request.ServletWebRequest;
5 |
6 | /**
7 | * 验证码处理器,封装不同的验证码处理逻辑
8 | */
9 | public interface ValidateCodeProcessor {
10 |
11 | /**
12 | * 验证码放入session时的前缀
13 | */
14 | String SESSION_KEY_PREFIX = "SESSION_KEY_FOR_CODE_";
15 |
16 |
17 | /**
18 | * 创建校验码
19 | *
20 | * @param servletWebRequest
21 | * @throws Exception
22 | */
23 | void create(ServletWebRequest servletWebRequest) throws Exception;
24 |
25 | /**
26 | * 校验验证码
27 | *
28 | * @param servletWebRequest
29 | * @throws Exception
30 | */
31 | void validate(ServletWebRequest servletWebRequest);
32 | }
33 |
--------------------------------------------------------------------------------
/security-core/src/main/java/com/earthchen/security/core/validate/code/ValidateCodeProcessorHolder.java:
--------------------------------------------------------------------------------
1 | package com.earthchen.security.core.validate.code;
2 |
3 | import java.util.Map;
4 |
5 | import org.springframework.beans.factory.annotation.Autowired;
6 | import org.springframework.stereotype.Component;
7 |
8 | /**
9 | * @author zhailiang
10 | *
11 | */
12 | @Component
13 | public class ValidateCodeProcessorHolder {
14 |
15 | @Autowired
16 | private Map validateCodeProcessors;
17 |
18 | public ValidateCodeProcessor findValidateCodeProcessor(ValidateCodeType type) {
19 | return findValidateCodeProcessor(type.toString().toLowerCase());
20 | }
21 |
22 | public ValidateCodeProcessor findValidateCodeProcessor(String type) {
23 | String name = type.toLowerCase() + ValidateCodeProcessor.class.getSimpleName();
24 | ValidateCodeProcessor processor = validateCodeProcessors.get(name);
25 | if (processor == null) {
26 | throw new ValidateCodeException("验证码处理器" + name + "不存在");
27 | }
28 | return processor;
29 | }
30 |
31 | }
32 |
--------------------------------------------------------------------------------
/security-core/src/main/java/com/earthchen/security/core/validate/code/ValidateCodeRepository.java:
--------------------------------------------------------------------------------
1 | package com.earthchen.security.core.validate.code;
2 |
3 | import org.springframework.web.context.request.ServletWebRequest;
4 |
5 | /**
6 | * 校验码存取器
7 | */
8 | public interface ValidateCodeRepository {
9 |
10 | /**
11 | * 保存验证码
12 | *
13 | * @param request
14 | * @param code
15 | * @param validateCodeType
16 | */
17 | void save(ServletWebRequest request, ValidateCode code, ValidateCodeType validateCodeType);
18 |
19 | /**
20 | * 获取验证码
21 | *
22 | * @param request
23 | * @param validateCodeType
24 | * @return
25 | */
26 | ValidateCode get(ServletWebRequest request, ValidateCodeType validateCodeType);
27 |
28 | /**
29 | * 移除验证码
30 | *
31 | * @param request
32 | * @param codeType
33 | */
34 | void remove(ServletWebRequest request, ValidateCodeType codeType);
35 | }
36 |
--------------------------------------------------------------------------------
/security-core/src/main/java/com/earthchen/security/core/validate/code/ValidateCodeSecurityConfig.java:
--------------------------------------------------------------------------------
1 | package com.earthchen.security.core.validate.code;
2 |
3 | import javax.servlet.Filter;
4 |
5 | import org.springframework.beans.factory.annotation.Autowired;
6 | import org.springframework.security.config.annotation.SecurityConfigurerAdapter;
7 | import org.springframework.security.config.annotation.web.builders.HttpSecurity;
8 | import org.springframework.security.web.DefaultSecurityFilterChain;
9 | import org.springframework.security.web.authentication.preauth.AbstractPreAuthenticatedProcessingFilter;
10 | import org.springframework.stereotype.Component;
11 |
12 | /**
13 | * @author zhailiang
14 | *
15 | */
16 | @Component("validateCodeSecurityConfig")
17 | public class ValidateCodeSecurityConfig extends SecurityConfigurerAdapter {
18 |
19 | @Autowired
20 | private Filter validateCodeFilter;
21 |
22 | @Override
23 | public void configure(HttpSecurity http) throws Exception {
24 | http.addFilterBefore(validateCodeFilter, AbstractPreAuthenticatedProcessingFilter.class);
25 | }
26 |
27 | }
--------------------------------------------------------------------------------
/security-core/src/main/java/com/earthchen/security/core/validate/code/ValidateCodeType.java:
--------------------------------------------------------------------------------
1 | package com.earthchen.security.core.validate.code;
2 |
3 |
4 | import com.earthchen.security.core.properties.SecurityConstants;
5 |
6 | /**
7 | * 验证码类型
8 | */
9 | public enum ValidateCodeType {
10 |
11 | /**
12 | * 短信验证码
13 | */
14 | SMS {
15 | @Override
16 | public String getParamNameOnValidate() {
17 | return SecurityConstants.DEFAULT_PARAMETER_NAME_CODE_SMS;
18 | }
19 | },
20 | /**
21 | * 图片验证码
22 | */
23 | IMAGE {
24 | @Override
25 | public String getParamNameOnValidate() {
26 | return SecurityConstants.DEFAULT_PARAMETER_NAME_CODE_IMAGE;
27 | }
28 | };
29 |
30 | /**
31 | * 校验时从请求中获取的参数的名字
32 | * @return
33 | */
34 | public abstract String getParamNameOnValidate();
35 | }
36 |
--------------------------------------------------------------------------------
/security-core/src/main/java/com/earthchen/security/core/validate/code/image/ImageCode.java:
--------------------------------------------------------------------------------
1 | package com.earthchen.security.core.validate.code.image;
2 |
3 | import com.earthchen.security.core.validate.code.ValidateCode;
4 |
5 | import java.awt.image.BufferedImage;
6 | import java.time.LocalDateTime;
7 |
8 | /**
9 | * 图片验证码
10 | */
11 | public class ImageCode extends ValidateCode {
12 |
13 | private static final long serialVersionUID = -500010999504413020L;
14 |
15 | private BufferedImage image;
16 |
17 | public ImageCode(BufferedImage image, String code, int expireIn){
18 | super(code, expireIn);
19 | this.image = image;
20 | }
21 |
22 | public ImageCode(BufferedImage image, String code, LocalDateTime expireTime){
23 | super(code, expireTime);
24 | this.image = image;
25 | }
26 |
27 | public BufferedImage getImage() {
28 | return image;
29 | }
30 |
31 | public void setImage(BufferedImage image) {
32 | this.image = image;
33 | }
34 |
35 | }
36 |
37 |
--------------------------------------------------------------------------------
/security-core/src/main/java/com/earthchen/security/core/validate/code/image/ImageCodeProcessor.java:
--------------------------------------------------------------------------------
1 | package com.earthchen.security.core.validate.code.image;
2 |
3 | import com.earthchen.security.core.validate.code.impl.AbstractValidateCodeProcessor;
4 | import org.springframework.stereotype.Component;
5 | import org.springframework.web.context.request.ServletWebRequest;
6 |
7 | import javax.imageio.ImageIO;
8 |
9 | /**
10 | * 图片验证码处理器
11 | */
12 | @Component("imageValidateCodeProcessor")
13 | public class ImageCodeProcessor extends AbstractValidateCodeProcessor {
14 |
15 | /**
16 | * 发送图形验证码,将其写到响应中
17 | */
18 | @Override
19 | protected void send(ServletWebRequest request, ImageCode imageCode) throws Exception {
20 | ImageIO.write(imageCode.getImage(), "JPEG", request.getResponse().getOutputStream());
21 | }
22 |
23 | }
24 |
--------------------------------------------------------------------------------
/security-core/src/main/java/com/earthchen/security/core/validate/code/sms/DefaultSmsCodeSender.java:
--------------------------------------------------------------------------------
1 | package com.earthchen.security.core.validate.code.sms;
2 |
3 | /**
4 | * 默认的短信验证码发送方法实现
5 | */
6 | public class DefaultSmsCodeSender implements SmsCodeSender {
7 |
8 | /**
9 | * 发送方法逻辑
10 | * @param mobile 手机号
11 | * @param code 验证码
12 | */
13 | @Override
14 | public void send(String mobile, String code) {
15 | System.out.println("向手机"+mobile+"发送短信验证码"+code);
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/security-core/src/main/java/com/earthchen/security/core/validate/code/sms/SmsCodeGenerator.java:
--------------------------------------------------------------------------------
1 | package com.earthchen.security.core.validate.code.sms;
2 |
3 | import com.earthchen.security.core.properties.SecurityProperties;
4 | import com.earthchen.security.core.validate.code.ValidateCode;
5 | import com.earthchen.security.core.validate.code.ValidateCodeGenerator;
6 | import org.apache.commons.lang.RandomStringUtils;
7 | import org.springframework.beans.factory.annotation.Autowired;
8 | import org.springframework.stereotype.Component;
9 | import org.springframework.web.context.request.ServletWebRequest;
10 |
11 | /**
12 | * 短信验证码生成器
13 | */
14 | @Component("smsValidateCodeGenerator")
15 | public class SmsCodeGenerator implements ValidateCodeGenerator {
16 |
17 |
18 | @Autowired
19 | private SecurityProperties securityProperties;
20 |
21 | @Override
22 | public ValidateCode generate(ServletWebRequest request) {
23 | String code = RandomStringUtils.randomNumeric(securityProperties.getValidateCode().getSmsCode().getLength());
24 | return new ValidateCode(code, securityProperties.getValidateCode().getSmsCode().getExpireIn());
25 | }
26 |
27 |
28 | public SecurityProperties getSecurityProperties() {
29 | return securityProperties;
30 | }
31 |
32 | public void setSecurityProperties(SecurityProperties securityProperties) {
33 | this.securityProperties = securityProperties;
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/security-core/src/main/java/com/earthchen/security/core/validate/code/sms/SmsCodeProcessor.java:
--------------------------------------------------------------------------------
1 | package com.earthchen.security.core.validate.code.sms;
2 |
3 | import com.earthchen.security.core.properties.SecurityConstants;
4 | import com.earthchen.security.core.validate.code.ValidateCode;
5 | import com.earthchen.security.core.validate.code.impl.AbstractValidateCodeProcessor;
6 | import org.springframework.beans.factory.annotation.Autowired;
7 | import org.springframework.stereotype.Component;
8 | import org.springframework.web.bind.ServletRequestUtils;
9 | import org.springframework.web.context.request.ServletWebRequest;
10 |
11 | /**
12 | * 短信验证码处理器
13 | */
14 | @Component("smsValidateCodeProcessor")
15 | public class SmsCodeProcessor extends AbstractValidateCodeProcessor {
16 |
17 | /**
18 | * 短信验证码发送器
19 | */
20 | @Autowired
21 | private SmsCodeSender smsCodeSender;
22 |
23 | @Override
24 | protected void send(ServletWebRequest request, ValidateCode validateCode) throws Exception {
25 | String paramName = SecurityConstants.DEFAULT_PARAMETER_NAME_MOBILE;
26 | String mobile = ServletRequestUtils.getRequiredStringParameter(request.getRequest(), paramName);
27 | smsCodeSender.send(mobile, validateCode.getCode());
28 | }
29 |
30 | }
31 |
--------------------------------------------------------------------------------
/security-core/src/main/java/com/earthchen/security/core/validate/code/sms/SmsCodeSender.java:
--------------------------------------------------------------------------------
1 | package com.earthchen.security.core.validate.code.sms;
2 |
3 | /**
4 | * 短信发送接口
5 | */
6 | public interface SmsCodeSender {
7 |
8 | /**
9 | * 发送方法
10 | * @param mobile 手机号
11 | * @param code 验证码
12 | */
13 | void send(String mobile, String code);
14 |
15 | }
16 |
--------------------------------------------------------------------------------
/security-core/target/classes/META-INF/spring-configuration-metadata.json:
--------------------------------------------------------------------------------
1 | {
2 | "hints": [],
3 | "groups": [
4 | {
5 | "sourceType": "com.earthchen.security.core.properties.SecurityProperties",
6 | "name": "earthchen.security",
7 | "type": "com.earthchen.security.core.properties.SecurityProperties"
8 | }
9 | ],
10 | "properties": [
11 | {
12 | "sourceType": "com.earthchen.security.core.properties.SecurityProperties",
13 | "name": "earthchen.security.browser",
14 | "description": "浏览器端配置",
15 | "type": "com.earthchen.security.core.properties.BrowserProperties"
16 | },
17 | {
18 | "sourceType": "com.earthchen.security.core.properties.SecurityProperties",
19 | "name": "earthchen.security.oauth2",
20 | "description": "OAuth2认证服务器配置",
21 | "type": "com.earthchen.security.core.properties.OAuth2Properties"
22 | },
23 | {
24 | "sourceType": "com.earthchen.security.core.properties.SecurityProperties",
25 | "name": "earthchen.security.social",
26 | "description": "社交登录相关配置",
27 | "type": "com.earthchen.security.core.properties.SocialProperties"
28 | },
29 | {
30 | "sourceType": "com.earthchen.security.core.properties.SecurityProperties",
31 | "name": "earthchen.security.validate-code",
32 | "description": "验证码配置",
33 | "type": "com.earthchen.security.core.properties.ValidateCodeProperties"
34 | }
35 | ]
36 | }
--------------------------------------------------------------------------------
/security-core/target/maven-archiver/pom.properties:
--------------------------------------------------------------------------------
1 | #Generated by Maven
2 | #Fri Dec 15 11:34:01 CST 2017
3 | version=1.0-SNAPSHOT
4 | groupId=com.earthchen
5 | artifactId=security-core
6 |
--------------------------------------------------------------------------------
/security-demo/src/main/java/com/earthchen/DemoApplication.java:
--------------------------------------------------------------------------------
1 | package com.earthchen;
2 |
3 |
4 | import org.springframework.boot.SpringApplication;
5 | import org.springframework.boot.autoconfigure.SpringBootApplication;
6 |
7 | @SpringBootApplication
8 | public class DemoApplication {
9 |
10 | public static void main(String[] args){
11 | SpringApplication.run(DemoApplication.class,args);
12 | }
13 |
14 |
15 | }
16 |
--------------------------------------------------------------------------------
/security-demo/src/main/java/com/earthchen/code/DemoImageCodeGenerator.java:
--------------------------------------------------------------------------------
1 | package com.earthchen.code;
2 |
3 | import com.earthchen.security.core.validate.code.image.ImageCode;
4 | import com.earthchen.security.core.validate.code.ValidateCodeGenerator;
5 | import org.springframework.web.context.request.ServletWebRequest;
6 |
7 | /**
8 | * 自定义验证码生成器
9 | */
10 | //@Component("imageValidateCodeGenerator")
11 | public class DemoImageCodeGenerator implements ValidateCodeGenerator {
12 |
13 | /**
14 | * 新的验证码生成逻辑
15 | * @param request
16 | * @return
17 | */
18 | @Override
19 | public ImageCode generate(ServletWebRequest request) {
20 | System.out.println("更高级的图形验证码生成代码");
21 | return null;
22 | }
23 | }
24 |
--------------------------------------------------------------------------------
/security-demo/src/main/java/com/earthchen/dto/FileInfo.java:
--------------------------------------------------------------------------------
1 | package com.earthchen.dto;
2 |
3 | public class FileInfo {
4 |
5 | public FileInfo(String path){
6 | this.path = path;
7 | }
8 |
9 | private String path;
10 |
11 | public String getPath() {
12 | return path;
13 | }
14 |
15 | public void setPath(String path) {
16 | this.path = path;
17 | }
18 |
19 | }
--------------------------------------------------------------------------------
/security-demo/src/main/java/com/earthchen/dto/UserQueryCondition.java:
--------------------------------------------------------------------------------
1 | package com.earthchen.dto;
2 |
3 |
4 | import io.swagger.annotations.ApiModelProperty;
5 |
6 | /**
7 | * 用户查询条件类
8 | */
9 | public class UserQueryCondition {
10 |
11 | public String getUsername() {
12 | return username;
13 | }
14 |
15 | public void setUsername(String username) {
16 | this.username = username;
17 | }
18 |
19 | public int getAge() {
20 | return age;
21 | }
22 |
23 | public void setAge(int age) {
24 | this.age = age;
25 | }
26 |
27 | public int getAgeTo() {
28 | return ageTo;
29 | }
30 |
31 | public void setAgeTo(int ageTo) {
32 | this.ageTo = ageTo;
33 | }
34 |
35 | public String getXxx() {
36 | return xxx;
37 | }
38 |
39 | public void setXxx(String xxx) {
40 | this.xxx = xxx;
41 | }
42 |
43 | private String username;
44 |
45 | @ApiModelProperty(value = "用户年龄起始值")
46 | private int age;
47 |
48 | @ApiModelProperty(value = "用户年龄终止值")
49 | private int ageTo;
50 |
51 | private String xxx;
52 | }
53 |
--------------------------------------------------------------------------------
/security-demo/src/main/java/com/earthchen/excepetion/UserNotExistException.java:
--------------------------------------------------------------------------------
1 | package com.earthchen.excepetion;
2 |
3 |
4 | public class UserNotExistException extends RuntimeException {
5 |
6 |
7 | private static final long serialVersionUID=-1L;
8 |
9 | public String getId() {
10 | return id;
11 | }
12 |
13 | public void setId(String id) {
14 | this.id = id;
15 | }
16 |
17 | private String id;
18 |
19 |
20 | public UserNotExistException(String id){
21 | super("user not exist");
22 | this.id=id;
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/security-demo/src/main/java/com/earthchen/security/DemoAuthorizeConfigProvider.java:
--------------------------------------------------------------------------------
1 | package com.earthchen.security;
2 |
3 | import com.earthchen.security.core.authorize.AuthorizeConfigProvider;
4 | import org.springframework.core.annotation.Order;
5 | import org.springframework.security.config.annotation.web.builders.HttpSecurity;
6 | import org.springframework.security.config.annotation.web.configurers.ExpressionUrlAuthorizationConfigurer;
7 | import org.springframework.stereotype.Component;
8 |
9 |
10 | @Component
11 | @Order(Integer.MAX_VALUE)
12 | public class DemoAuthorizeConfigProvider implements AuthorizeConfigProvider {
13 |
14 | /**
15 | * demo项目授权配置
16 | * @param config
17 | * @return
18 | */
19 | @Override
20 | public boolean config(ExpressionUrlAuthorizationConfigurer.ExpressionInterceptUrlRegistry config) {
21 | //config.antMatchers("/demo.html").hasRole("ADMIN");
22 | config.anyRequest().access("@rbacService.hasPermission(request,authentication)");
23 | return true;
24 |
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/security-demo/src/main/java/com/earthchen/security/DemoConnectionSignUp.java:
--------------------------------------------------------------------------------
1 | package com.earthchen.security;
2 |
3 |
4 | import org.springframework.social.connect.Connection;
5 | import org.springframework.social.connect.ConnectionSignUp;
6 | import org.springframework.stereotype.Component;
7 |
8 |
9 | /**
10 | * 配置ConnectionSignUp实现类
11 | *
12 | * 实现用户使用第三方登录完默认注册一个用户并登录
13 | */
14 | @Component
15 | public class DemoConnectionSignUp implements ConnectionSignUp {
16 |
17 | /* (non-Javadoc)
18 | * @see org.springframework.social.connect.ConnectionSignUp#execute(org.springframework.social.connect.Connection)
19 | */
20 | @Override
21 | public String execute(Connection> connection) {
22 | //根据社交用户信息默认创建用户并返回用户唯一标识
23 | return connection.getDisplayName();
24 | }
25 |
26 | }
--------------------------------------------------------------------------------
/security-demo/src/main/java/com/earthchen/service/HelloService.java:
--------------------------------------------------------------------------------
1 | package com.earthchen.service;
2 |
3 | public interface HelloService {
4 |
5 | String greeting(String name);
6 | }
7 |
--------------------------------------------------------------------------------
/security-demo/src/main/java/com/earthchen/service/impl/HelloServiceImpl.java:
--------------------------------------------------------------------------------
1 | package com.earthchen.service.impl;
2 |
3 |
4 | import com.earthchen.service.HelloService;
5 | import org.springframework.stereotype.Service;
6 |
7 | @Service
8 | public class HelloServiceImpl implements HelloService{
9 |
10 | @Override
11 | public String greeting(String name) {
12 | System.out.println("greeting....");
13 | return "hello "+name;
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/security-demo/src/main/java/com/earthchen/validator/MyConstraintValidator.java:
--------------------------------------------------------------------------------
1 | package com.earthchen.validator;
2 |
3 | import com.earthchen.service.HelloService;
4 | import org.springframework.beans.factory.annotation.Autowired;
5 |
6 | import javax.validation.ConstraintValidator;
7 | import javax.validation.ConstraintValidatorContext;
8 |
9 | public class MyConstraintValidator implements ConstraintValidator {
10 |
11 | @Autowired
12 | private HelloService helloService;
13 |
14 | /**
15 | * 校验器初始化
16 | * @param constraintAnnotation
17 | */
18 | @Override
19 | public void initialize(MyValidConstraint constraintAnnotation) {
20 | System.out.println("MyConstraintValidator--init ");
21 | }
22 |
23 | /**
24 | * 真正的校验方法
25 | * @param value
26 | * @param context
27 | * @return
28 | */
29 | @Override
30 | public boolean isValid(Object value, ConstraintValidatorContext context) {
31 | helloService.greeting("tom");
32 | System.out.println(value);
33 | return false;
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/security-demo/src/main/java/com/earthchen/validator/MyValidConstraint.java:
--------------------------------------------------------------------------------
1 | package com.earthchen.validator;
2 |
3 |
4 | import javax.validation.Constraint;
5 | import javax.validation.Payload;
6 | import java.lang.annotation.ElementType;
7 | import java.lang.annotation.Retention;
8 | import java.lang.annotation.RetentionPolicy;
9 | import java.lang.annotation.Target;
10 |
11 | /**
12 | * 自定义校验器
13 | * 下面三个方法都是必须含有的
14 | */
15 | @Target({ElementType.METHOD, ElementType.FIELD})
16 | @Retention(RetentionPolicy.RUNTIME)
17 | @Constraint(validatedBy = MyConstraintValidator.class)
18 | public @interface MyValidConstraint {
19 |
20 | String message();
21 |
22 | Class>[] groups() default { };
23 |
24 | Class extends Payload>[] payload() default { };
25 | }
26 |
--------------------------------------------------------------------------------
/security-demo/src/main/java/com/earthchen/web/aspect/TimeAspect.java:
--------------------------------------------------------------------------------
1 | package com.earthchen.web.aspect;
2 |
3 |
4 | import org.aspectj.lang.ProceedingJoinPoint;
5 | import org.aspectj.lang.annotation.Around;
6 | import org.aspectj.lang.annotation.Aspect;
7 | import org.springframework.stereotype.Component;
8 |
9 | import java.util.Date;
10 |
11 | /**
12 | * 使用注解声明切片
13 | */
14 | @Aspect
15 | @Component
16 | public class TimeAspect {
17 |
18 | @Around("execution(* com.earthchen.web.controller.UserController.*(..))")
19 | public Object handleControllerMethod(ProceedingJoinPoint pjp) throws Throwable {
20 | System.out.println("time aspect start");
21 |
22 | Object[] args = pjp.getArgs();
23 | for (Object arg : args) {
24 | System.out.println("arg is " + arg);
25 | }
26 |
27 | long start = new Date().getTime();
28 |
29 | Object object = pjp.proceed();
30 |
31 | System.out.println("time aspect 耗时:" + (new Date().getTime() - start));
32 |
33 | System.out.println("time aspect end");
34 |
35 | return object;
36 | }
37 |
38 | }
39 |
--------------------------------------------------------------------------------
/security-demo/src/main/java/com/earthchen/web/async/DeferredResultHolder.java:
--------------------------------------------------------------------------------
1 | package com.earthchen.web.async;
2 |
3 |
4 | import java.util.HashMap;
5 | import java.util.Map;
6 |
7 | import org.springframework.stereotype.Component;
8 | import org.springframework.web.context.request.async.DeferredResult;
9 |
10 | @Component
11 | public class DeferredResultHolder {
12 |
13 | private Map> map = new HashMap<>();
14 |
15 | public Map> getMap() {
16 | return map;
17 | }
18 |
19 | public void setMap(Map> map) {
20 | this.map = map;
21 | }
22 |
23 | }
24 |
--------------------------------------------------------------------------------
/security-demo/src/main/java/com/earthchen/web/async/MockQueue.java:
--------------------------------------------------------------------------------
1 | package com.earthchen.web.async;
2 |
3 |
4 | import org.slf4j.Logger;
5 | import org.slf4j.LoggerFactory;
6 | import org.springframework.stereotype.Component;
7 |
8 | @Component
9 | public class MockQueue {
10 |
11 | private String placeOrder;
12 |
13 | private String completeOrder;
14 |
15 | private Logger logger = LoggerFactory.getLogger(getClass());
16 |
17 | public String getPlaceOrder() {
18 | return placeOrder;
19 | }
20 |
21 | public void setPlaceOrder(String placeOrder) throws Exception {
22 | new Thread(() -> {
23 | logger.info("接到下单请求, " + placeOrder);
24 | try {
25 | Thread.sleep(1000);
26 | } catch (Exception e) {
27 | e.printStackTrace();
28 | }
29 | this.completeOrder = placeOrder;
30 | logger.info("下单请求处理完毕," + placeOrder);
31 | }).start();
32 | }
33 |
34 | public String getCompleteOrder() {
35 | return completeOrder;
36 | }
37 |
38 | public void setCompleteOrder(String completeOrder) {
39 | this.completeOrder = completeOrder;
40 | }
41 |
42 | }
43 |
--------------------------------------------------------------------------------
/security-demo/src/main/java/com/earthchen/web/config/Swagger2.java:
--------------------------------------------------------------------------------
1 | package com.earthchen.web.config;
2 |
3 | import org.springframework.context.annotation.Bean;
4 | import org.springframework.context.annotation.Configuration;
5 |
6 | import springfox.documentation.builders.ApiInfoBuilder;
7 | import springfox.documentation.builders.PathSelectors;
8 | import springfox.documentation.builders.RequestHandlerSelectors;
9 | import springfox.documentation.service.ApiInfo;
10 | import springfox.documentation.spi.DocumentationType;
11 | import springfox.documentation.spring.web.plugins.Docket;
12 | import springfox.documentation.swagger2.annotations.EnableSwagger2;
13 |
14 | @Configuration
15 | @EnableSwagger2
16 | public class Swagger2 {
17 |
18 | @Bean
19 | public Docket createRestApi() {
20 | return new Docket(DocumentationType.SWAGGER_2)
21 | .apiInfo(apiInfo())
22 | .select()
23 | .apis(RequestHandlerSelectors.basePackage("com.earthchen.web"))
24 | .paths(PathSelectors.any())
25 | .build();
26 | }
27 |
28 | private ApiInfo apiInfo() {
29 | return new ApiInfoBuilder()
30 | .title("spring security")
31 | .description("spring security")
32 | .termsOfServiceUrl("http://earthchen.cn/")
33 | .contact("EarthChen")
34 | .version("1.0")
35 | .build();
36 | }
37 | }
--------------------------------------------------------------------------------
/security-demo/src/main/java/com/earthchen/web/controller/ControllerExceptionHandler.java:
--------------------------------------------------------------------------------
1 | package com.earthchen.web.controller;
2 |
3 | import com.earthchen.excepetion.UserNotExistException;
4 | import org.springframework.http.HttpStatus;
5 | import org.springframework.web.bind.annotation.ControllerAdvice;
6 | import org.springframework.web.bind.annotation.ExceptionHandler;
7 | import org.springframework.web.bind.annotation.ResponseBody;
8 | import org.springframework.web.bind.annotation.ResponseStatus;
9 |
10 | import java.util.HashMap;
11 | import java.util.Map;
12 |
13 | /**
14 | * controller异常处理
15 | */
16 | @ControllerAdvice
17 | public class ControllerExceptionHandler {
18 |
19 | /**
20 | * 返回值为
21 | * {
22 | "id": "1",
23 | "message": "user not exist"
24 | }
25 | * @param ex
26 | * @return
27 | */
28 | @ExceptionHandler(UserNotExistException.class)
29 | @ResponseBody
30 | @ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR)
31 | public Map handleUserNotExistException(UserNotExistException ex) {
32 | Map result = new HashMap<>();
33 | result.put("id", ex.getId());
34 | result.put("message", ex.getMessage());
35 | return result;
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/security-demo/src/main/java/com/earthchen/web/filter/TimeFilter.java:
--------------------------------------------------------------------------------
1 | package com.earthchen.web.filter;
2 |
3 | import org.springframework.stereotype.Component;
4 |
5 | import javax.servlet.*;
6 | import java.io.IOException;
7 | import java.util.Date;
8 |
9 | /**
10 | * 过滤器拦截请求
11 | */
12 | //@Component
13 | public class TimeFilter implements Filter {
14 |
15 | @Override
16 | public void init(FilterConfig filterConfig) throws ServletException {
17 | System.out.println("time filter init");
18 | }
19 |
20 | @Override
21 | public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
22 | System.out.println("time filter start");
23 | long start = new Date().getTime();
24 | chain.doFilter(request, response);
25 | System.out.println("time filter 耗时:" + (new Date().getTime() - start));
26 | System.out.println("time filter finish");
27 | }
28 |
29 | @Override
30 | public void destroy() {
31 | System.out.println("time filter destroy");
32 | }
33 | }
34 |
--------------------------------------------------------------------------------
/security-demo/src/main/java/com/earthchen/wiremock/MockServer.java:
--------------------------------------------------------------------------------
1 | package com.earthchen.wiremock;
2 |
3 |
4 | import static com.github.tomakehurst.wiremock.client.WireMock.aResponse;
5 | import static com.github.tomakehurst.wiremock.client.WireMock.configureFor;
6 | import static com.github.tomakehurst.wiremock.client.WireMock.get;
7 | import static com.github.tomakehurst.wiremock.client.WireMock.removeAllMappings;
8 | import static com.github.tomakehurst.wiremock.client.WireMock.stubFor;
9 | import static com.github.tomakehurst.wiremock.client.WireMock.urlPathEqualTo;
10 |
11 | import java.io.IOException;
12 |
13 | import org.apache.commons.io.FileUtils;
14 | import org.apache.commons.lang.StringUtils;
15 | import org.springframework.core.io.ClassPathResource;
16 |
17 | public class MockServer {
18 |
19 | public static void main(String[] args) throws IOException {
20 | configureFor(8062);
21 | removeAllMappings();
22 |
23 | mock("/order/1", "01");
24 | mock("/order/2", "02");
25 | }
26 |
27 | private static void mock(String url, String file) throws IOException {
28 | ClassPathResource resource = new ClassPathResource("mock/response/" + file + ".txt");
29 | String content = StringUtils.join(FileUtils.readLines(resource.getFile(), "UTF-8").toArray(), "\n");
30 | stubFor(get(urlPathEqualTo(url)).willReturn(aResponse().withBody(content).withStatus(200)));
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/security-demo/src/main/resources/mock/response/01.txt:
--------------------------------------------------------------------------------
1 | {
2 | "id":1,
3 | "type":"C"
4 | }
--------------------------------------------------------------------------------
/security-demo/src/main/resources/mock/response/02.txt:
--------------------------------------------------------------------------------
1 | {
2 | "id":2,
3 | "type":"B"
4 | }
--------------------------------------------------------------------------------
/security-demo/src/main/resources/resources/demo-logout.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Title
6 |
7 |
8 | demo退出成功页
9 |
10 |
--------------------------------------------------------------------------------
/security-demo/src/main/resources/resources/demo-signIn.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Title
6 |
7 |
8 | Demo登录页
9 |
10 |
--------------------------------------------------------------------------------
/security-demo/src/main/resources/resources/demo-signUp.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | 登录
6 |
7 |
8 | Demo注册页
9 |
10 |
28 |
29 |
--------------------------------------------------------------------------------
/security-demo/src/main/resources/resources/demo.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Insert title here
6 |
7 |
8 | DEMO
9 |
10 |
--------------------------------------------------------------------------------
/security-demo/src/main/resources/resources/error/403.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | 403
6 |
7 |
8 | 403错误 无权访问
9 |
10 |
--------------------------------------------------------------------------------
/security-demo/src/main/resources/resources/error/404.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Title
6 |
7 |
8 |
9 | 404 not find
10 |
11 |
--------------------------------------------------------------------------------
/security-demo/src/main/resources/resources/error/500.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Title
6 |
7 |
8 |
9 | 500 服务器内部错误
10 |
11 |
--------------------------------------------------------------------------------
/security-demo/src/main/resources/resources/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Insert title here
6 |
7 |
8 | index
9 | 退出登录
10 |
11 |
--------------------------------------------------------------------------------
/security-demo/target/classes/mock/response/01.txt:
--------------------------------------------------------------------------------
1 | {
2 | "id":1,
3 | "type":"C"
4 | }
--------------------------------------------------------------------------------
/security-demo/target/classes/mock/response/02.txt:
--------------------------------------------------------------------------------
1 | {
2 | "id":2,
3 | "type":"B"
4 | }
--------------------------------------------------------------------------------
/security-demo/target/classes/resources/demo-logout.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Title
6 |
7 |
8 | demo退出成功页
9 |
10 |
--------------------------------------------------------------------------------
/security-demo/target/classes/resources/demo-signIn.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Title
6 |
7 |
8 | Demo登录页
9 |
10 |
--------------------------------------------------------------------------------
/security-demo/target/classes/resources/demo-signUp.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | 登录
6 |
7 |
8 | Demo注册页
9 |
10 |
28 |
29 |
--------------------------------------------------------------------------------
/security-demo/target/classes/resources/demo.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Insert title here
6 |
7 |
8 | DEMO
9 |
10 |
--------------------------------------------------------------------------------
/security-demo/target/classes/resources/error/403.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | 403
6 |
7 |
8 | 403错误 无权访问
9 |
10 |
--------------------------------------------------------------------------------
/security-demo/target/classes/resources/error/404.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Title
6 |
7 |
8 |
9 | 404 not find
10 |
11 |
--------------------------------------------------------------------------------
/security-demo/target/classes/resources/error/500.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Title
6 |
7 |
8 |
9 | 500 服务器内部错误
10 |
11 |
--------------------------------------------------------------------------------
/security-demo/target/classes/resources/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Insert title here
6 |
7 |
8 | index
9 | 退出登录
10 |
11 |
--------------------------------------------------------------------------------
/security-demo/target/maven-archiver/pom.properties:
--------------------------------------------------------------------------------
1 | #Generated by Maven
2 | #Fri Dec 15 11:34:10 CST 2017
3 | version=1.0-SNAPSHOT
4 | groupId=com.earthchen
5 | artifactId=security-demo
6 |
--------------------------------------------------------------------------------
/security-demo/target/security-demo.jar.original:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/EarthChen/imooc-security-study/69e843d89d017953ec3e91b0701651ab4942eb43/security-demo/target/security-demo.jar.original
--------------------------------------------------------------------------------
/security-demo/target/surefire-reports/com.earthchen.web.controller.UserControllerTest.txt:
--------------------------------------------------------------------------------
1 | -------------------------------------------------------------------------------
2 | Test set: com.earthchen.web.controller.UserControllerTest
3 | -------------------------------------------------------------------------------
4 | Tests run: 7, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 7.809 sec
5 |
--------------------------------------------------------------------------------
/sso-client1/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 | sso-demo
7 | com.earthchen
8 | 1.0-SNAPSHOT
9 | ../sso-demo/pom.xml
10 |
11 | 4.0.0
12 |
13 | sso-client1
14 |
15 |
16 |
17 | org.springframework.boot
18 | spring-boot-starter-security
19 |
20 |
21 | org.springframework.boot
22 | spring-boot-starter-web
23 |
24 |
25 | org.springframework.security.oauth
26 | spring-security-oauth2
27 |
28 |
29 | org.springframework.security
30 | spring-security-jwt
31 |
32 |
33 |
34 |
35 |
--------------------------------------------------------------------------------
/sso-client1/src/main/java/com/earthchen/sso/client/SsoClient1Application.java:
--------------------------------------------------------------------------------
1 | package com.earthchen.sso.client;
2 |
3 | import org.springframework.boot.SpringApplication;
4 | import org.springframework.boot.autoconfigure.SpringBootApplication;
5 | import org.springframework.boot.autoconfigure.security.oauth2.client.EnableOAuth2Sso;
6 | import org.springframework.security.core.Authentication;
7 | import org.springframework.web.bind.annotation.GetMapping;
8 | import org.springframework.web.bind.annotation.RestController;
9 |
10 |
11 | @SpringBootApplication
12 | @RestController
13 | @EnableOAuth2Sso
14 | public class SsoClient1Application {
15 |
16 | @GetMapping("/user")
17 | public Authentication user(Authentication user) {
18 | return user;
19 | }
20 |
21 | public static void main(String[] args){
22 | SpringApplication.run(SsoClient1Application.class,args);
23 | }
24 |
25 |
26 | }
--------------------------------------------------------------------------------
/sso-client1/src/main/resources/application.yml:
--------------------------------------------------------------------------------
1 | security:
2 | oauth2:
3 | client:
4 | clientId: earthchen1
5 | clientSecret: earthchensecret1
6 | user-authorization-uri: http://127.0.0.1:9999/server/oauth/authorize
7 | access-token-uri: http://127.0.0.1:9999/server/oauth/token
8 | resource:
9 | jwt:
10 | key-uri: http://127.0.0.1:9999/server/oauth/token_key
11 | server:
12 | port: 8080
13 | context-path: /client1
14 |
15 |
16 |
--------------------------------------------------------------------------------
/sso-client1/src/main/resources/static/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | SSO Client1
6 |
7 |
8 | SSO Demo Client1
9 | 访问Client2
10 |
11 |
--------------------------------------------------------------------------------
/sso-client1/target/classes/application.yml:
--------------------------------------------------------------------------------
1 | security:
2 | oauth2:
3 | client:
4 | clientId: earthchen1
5 | clientSecret: earthchensecret1
6 | user-authorization-uri: http://127.0.0.1:9999/server/oauth/authorize
7 | access-token-uri: http://127.0.0.1:9999/server/oauth/token
8 | resource:
9 | jwt:
10 | key-uri: http://127.0.0.1:9999/server/oauth/token_key
11 | server:
12 | port: 8080
13 | context-path: /client1
14 |
15 |
16 |
--------------------------------------------------------------------------------
/sso-client1/target/classes/static/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | SSO Client1
6 |
7 |
8 | SSO Demo Client1
9 | 访问Client2
10 |
11 |
--------------------------------------------------------------------------------
/sso-client2/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 | sso-demo
7 | com.earthchen
8 | 1.0-SNAPSHOT
9 | ../sso-demo/pom.xml
10 |
11 | 4.0.0
12 |
13 | sso-client2
14 |
15 |
16 |
17 | org.springframework.boot
18 | spring-boot-starter-security
19 |
20 |
21 | org.springframework.boot
22 | spring-boot-starter-web
23 |
24 |
25 | org.springframework.security.oauth
26 | spring-security-oauth2
27 |
28 |
29 | org.springframework.security
30 | spring-security-jwt
31 |
32 |
33 |
34 |
35 |
--------------------------------------------------------------------------------
/sso-client2/src/main/java/com/earthchen/sso/client/SsoClient2Application.java:
--------------------------------------------------------------------------------
1 | package com.earthchen.sso.client;
2 |
3 | import org.springframework.boot.SpringApplication;
4 | import org.springframework.boot.autoconfigure.SpringBootApplication;
5 | import org.springframework.boot.autoconfigure.security.oauth2.client.EnableOAuth2Sso;
6 | import org.springframework.security.core.Authentication;
7 | import org.springframework.web.bind.annotation.GetMapping;
8 | import org.springframework.web.bind.annotation.RestController;
9 |
10 | @SpringBootApplication
11 | @RestController
12 | @EnableOAuth2Sso
13 | public class SsoClient2Application {
14 |
15 | @GetMapping("/user")
16 | public Authentication user(Authentication user) {
17 | return user;
18 | }
19 |
20 | public static void main(String[] args) {
21 | SpringApplication.run(SsoClient2Application.class, args);
22 | }
23 |
24 | }
--------------------------------------------------------------------------------
/sso-client2/src/main/resources/application.yml:
--------------------------------------------------------------------------------
1 | security:
2 | oauth2:
3 | client:
4 | client-id: earthchen2
5 | client-secret: earthchensecret2
6 | user-authorization-uri: http://127.0.0.1:9999/server/oauth/authorize
7 | access-token-uri: http://127.0.0.1:9999/server/oauth/token
8 | resource:
9 | jwt:
10 | key-uri: http://127.0.0.1:9999/server/oauth/token_key
11 | server:
12 | port: 8060
13 | context-path: /client2
--------------------------------------------------------------------------------
/sso-client2/src/main/resources/static/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | SSO Client1
6 |
7 |
8 | SSO Demo Client1
9 | 访问Client1
10 |
11 |
--------------------------------------------------------------------------------
/sso-client2/target/classes/application.yml:
--------------------------------------------------------------------------------
1 | security:
2 | oauth2:
3 | client:
4 | client-id: earthchen2
5 | client-secret: earthchensecret2
6 | user-authorization-uri: http://127.0.0.1:9999/server/oauth/authorize
7 | access-token-uri: http://127.0.0.1:9999/server/oauth/token
8 | resource:
9 | jwt:
10 | key-uri: http://127.0.0.1:9999/server/oauth/token_key
11 | server:
12 | port: 8060
13 | context-path: /client2
--------------------------------------------------------------------------------
/sso-client2/target/classes/static/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | SSO Client1
6 |
7 |
8 | SSO Demo Client1
9 | 访问Client1
10 |
11 |
--------------------------------------------------------------------------------
/sso-demo/sso-demo.iml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
--------------------------------------------------------------------------------
/sso-server/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 | sso-demo
7 | com.earthchen
8 | 1.0-SNAPSHOT
9 | ../sso-demo/pom.xml
10 |
11 | 4.0.0
12 |
13 | sso-server
14 |
15 |
16 |
17 | org.springframework.boot
18 | spring-boot-starter-security
19 |
20 |
21 | org.springframework.boot
22 | spring-boot-starter-web
23 |
24 |
25 | org.springframework.security.oauth
26 | spring-security-oauth2
27 |
28 |
29 | org.springframework.security
30 | spring-security-jwt
31 |
32 |
33 |
34 |
35 |
--------------------------------------------------------------------------------
/sso-server/src/main/java/com/earthchen/SsoServerApplication.java:
--------------------------------------------------------------------------------
1 | package com.earthchen;
2 |
3 |
4 | import org.springframework.boot.SpringApplication;
5 | import org.springframework.boot.autoconfigure.SpringBootApplication;
6 |
7 | @SpringBootApplication
8 | public class SsoServerApplication {
9 |
10 | public static void main(String[] args) {
11 | SpringApplication.run(SsoServerApplication.class, args);
12 | }
13 | }
14 |
--------------------------------------------------------------------------------
/sso-server/src/main/java/com/earthchen/sso/server/SsoUserDetailsService.java:
--------------------------------------------------------------------------------
1 | package com.earthchen.sso.server;
2 |
3 | import org.springframework.beans.factory.annotation.Autowired;
4 | import org.springframework.security.core.authority.AuthorityUtils;
5 | import org.springframework.security.core.userdetails.User;
6 | import org.springframework.security.core.userdetails.UserDetails;
7 | import org.springframework.security.core.userdetails.UserDetailsService;
8 | import org.springframework.security.core.userdetails.UsernameNotFoundException;
9 | import org.springframework.security.crypto.password.PasswordEncoder;
10 | import org.springframework.stereotype.Component;
11 |
12 |
13 | @Component
14 | public class SsoUserDetailsService implements UserDetailsService {
15 |
16 | @Autowired
17 | private PasswordEncoder passwordEncoder;
18 |
19 | /* (non-Javadoc)
20 | * @see org.springframework.security.core.userdetails.UserDetailsService#loadUserByUsername(java.lang.String)
21 | */
22 | @Override
23 | public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
24 | return new User(username, passwordEncoder.encode("123456"),
25 | AuthorityUtils.commaSeparatedStringToAuthorityList("ROLE_USER"));
26 | }
27 |
28 | }
--------------------------------------------------------------------------------
/sso-server/src/main/resources/application.yml:
--------------------------------------------------------------------------------
1 | server:
2 | port: 9999
3 | context-path: /server
4 | security:
5 | user:
6 | password: 123456
7 |
8 |
--------------------------------------------------------------------------------
/sso-server/target/classes/application.yml:
--------------------------------------------------------------------------------
1 | server:
2 | port: 9999
3 | context-path: /server
4 | security:
5 | user:
6 | password: 123456
7 |
8 |
--------------------------------------------------------------------------------
/test/src/main/java/com/earthchen/TestApplication.java:
--------------------------------------------------------------------------------
1 | package com.earthchen;
2 |
3 | import org.springframework.beans.factory.annotation.Autowired;
4 | import org.springframework.boot.SpringApplication;
5 | import org.springframework.boot.autoconfigure.SpringBootApplication;
6 | import org.springframework.security.core.Authentication;
7 | import org.springframework.social.connect.web.ProviderSignInUtils;
8 | import org.springframework.web.bind.annotation.GetMapping;
9 | import org.springframework.web.bind.annotation.PostMapping;
10 | import org.springframework.web.bind.annotation.RestController;
11 | import org.springframework.web.context.request.ServletWebRequest;
12 |
13 | import javax.servlet.http.HttpServletRequest;
14 |
15 | @SpringBootApplication
16 | @RestController
17 | public class TestApplication {
18 |
19 | @Autowired
20 | private ProviderSignInUtils providerSignInUtils;
21 |
22 |
23 | @GetMapping("/me")
24 | public Authentication me(Authentication user) {
25 | return user;
26 | }
27 |
28 | @PostMapping("/user/regist")
29 | public void regist(HttpServletRequest request) {
30 | providerSignInUtils.doPostSignUp("test", new ServletWebRequest(request));
31 | }
32 |
33 |
34 | public static void main(String[] args) {
35 | SpringApplication.run(TestApplication.class, args);
36 | }
37 |
38 | }
39 |
40 |
--------------------------------------------------------------------------------
/test/src/main/java/com/earthchen/TestAuthorizeConfigProvider.java:
--------------------------------------------------------------------------------
1 | package com.earthchen;
2 |
3 | import com.earthchen.security.core.authorize.AuthorizeConfigProvider;
4 | import org.springframework.http.HttpMethod;
5 | import org.springframework.security.config.annotation.web.builders.HttpSecurity;
6 | import org.springframework.security.config.annotation.web.configurers.ExpressionUrlAuthorizationConfigurer;
7 | import org.springframework.stereotype.Component;
8 |
9 | /**
10 | * 使用rbac将@Component取消
11 | */
12 | //@Component
13 | public class TestAuthorizeConfigProvider implements AuthorizeConfigProvider {
14 | @Override
15 | public boolean config(ExpressionUrlAuthorizationConfigurer.ExpressionInterceptUrlRegistry config) {
16 | config.antMatchers(HttpMethod.POST,"/user/regist").permitAll();
17 | return false;
18 | }
19 | }
20 |
--------------------------------------------------------------------------------
/test/src/main/resources/application.yml:
--------------------------------------------------------------------------------
1 | spring:
2 | datasource:
3 | driver-class-name: com.mysql.jdbc.Driver
4 | password: 123456
5 | username: root
6 | url: jdbc:mysql://127.0.0.1:3306/security-demo?useUnicode=yes&characterEncoding=UTF-8&useSSL=false
7 | dbcp2:
8 | min-evictable-idle-time-millis: 180000
9 | test-on-borrow: true
10 | test-on-return: true
11 | test-while-idle: true
12 | validation-query: select 1
13 | tomcat:
14 | max-active: 100
15 | min-idle: 10
16 | jpa:
17 | generate-ddl: true
18 | show-sql: true
19 |
20 | session:
21 | store-type: none
22 | server:
23 | session:
24 | timeout: 600
25 |
26 | earthchen:
27 | security:
28 | browser:
29 | loginType: REDIRECT
30 | singInSuccessUrl: /manage.html
31 | registerPage: /signUp.html
32 |
33 | social:
34 | qq:
35 | app-id: 100550231
36 | app-secret: 4444444444444
37 | # 设置providerId
38 | providerId: callback.do
39 | # 将社交登录social前缀的/auth改为以下内容
40 | weixin:
41 | app-id: wxd99431bbff8305a0
42 | app-secret: 60f78681d063590a469f1b297feff3c4
43 |
44 | # 最终url为/social-auth/callback.do
45 | filterProcessesUrl: /qqLogin
46 |
47 |
48 |
49 |
50 |
--------------------------------------------------------------------------------
/test/src/main/resources/resources/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Title
6 |
7 |
8 | index
9 |
10 |
--------------------------------------------------------------------------------
/test/src/main/resources/resources/signUp.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | 登录
6 |
7 |
8 | Demo注册页
9 |
10 |
28 |
29 |
--------------------------------------------------------------------------------
/test/target/classes/application.yml:
--------------------------------------------------------------------------------
1 | spring:
2 | datasource:
3 | driver-class-name: com.mysql.jdbc.Driver
4 | password: 123456
5 | username: root
6 | url: jdbc:mysql://127.0.0.1:3306/security-demo?useUnicode=yes&characterEncoding=UTF-8&useSSL=false
7 | dbcp2:
8 | min-evictable-idle-time-millis: 180000
9 | test-on-borrow: true
10 | test-on-return: true
11 | test-while-idle: true
12 | validation-query: select 1
13 | tomcat:
14 | max-active: 100
15 | min-idle: 10
16 | jpa:
17 | generate-ddl: true
18 | show-sql: true
19 |
20 | session:
21 | store-type: none
22 | server:
23 | session:
24 | timeout: 600
25 |
26 | earthchen:
27 | security:
28 | browser:
29 | loginType: REDIRECT
30 | singInSuccessUrl: /manage.html
31 | registerPage: /signUp.html
32 |
33 | social:
34 | qq:
35 | app-id: 100550231
36 | app-secret: 4444444444444
37 | # 设置providerId
38 | providerId: callback.do
39 | # 将社交登录social前缀的/auth改为以下内容
40 | weixin:
41 | app-id: wxd99431bbff8305a0
42 | app-secret: 60f78681d063590a469f1b297feff3c4
43 |
44 | # 最终url为/social-auth/callback.do
45 | filterProcessesUrl: /qqLogin
46 |
47 |
48 |
49 |
50 |
--------------------------------------------------------------------------------
/test/target/classes/resources/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Title
6 |
7 |
8 | index
9 |
10 |
--------------------------------------------------------------------------------
/test/target/classes/resources/signUp.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | 登录
6 |
7 |
8 | Demo注册页
9 |
10 |
28 |
29 |
--------------------------------------------------------------------------------