调试修复
This commit is contained in:
@@ -2,11 +2,12 @@
|
||||
##本项目的参数配置说明
|
||||
- 用户登录接口url`/user/login`
|
||||
- 图片验证码获取接口url`/code/image` ,在进行图片验证码校验时传递参数为`imageCode`
|
||||
- 使用redis存储验证码,key是根据发起请求的`deviceId`生成的。所以生成和校验验证码的时候必须传入`deviceId`
|
||||
- `ms.security.code.image.width` 图片验证码宽度,默认值是`67` 可以在请求中使用`width`参数设置
|
||||
- `ms.security.code.image.height`图片验证码高度,默认值是`23` 可以在请求中使用`height`参数设置
|
||||
- `ms.security.code.image.length`图片验证码的code长度,默认是`4` 不能在请求中设置
|
||||
- `ms.security.code.image.expireIn` 图片验证码的有效时间`60`秒 不能在请求中设置
|
||||
- `ms.security.code.image.url` 需要进行验证码校验的地址,默认值是`/user/login` 可以是`/user/*`这种格式,多个适用,号分割
|
||||
- `ms.security.code.image.url` 需要进行验证码校验的地址,默认值是`/user/login` 可以是`/user/*`这种格式,多个使用,号分割
|
||||
不能在请求中设置
|
||||
- 本着增量开发的原则,可以实现`imageCodeUtil`生成验证码的方法,并定义名称为`imageCodeUtil`的bean便可替换原有的图片验证码
|
||||
的生成逻辑
|
||||
@@ -19,3 +20,10 @@
|
||||
- 短信登录的接口为`/authentication/mobile`,传递参数为`smsCode`和`mobile`
|
||||
- oauth2发起的请求的用户需要有一个`ROLE_USER`的用户权限
|
||||
- oauth2中相同的用户会得到相同的token
|
||||
- `ms.security.oauth2.storeType`token的策略,不设置这个值的是时候默认生成`jwt`的token,如果设置值为`redis`的时候生成的默认的token将会存储在redis中
|
||||
- `ms.security.oauth2.jwtSigningKey` 生成jwt的token的秘钥
|
||||
- `ms.security.oauth2.clients[i].clientId` 配置oauth2授权的clientId
|
||||
- `ms.security.oauth2.clients[i].clientSecret` 配置oauth2授权的clientId对应的clientSecret
|
||||
- `ms.security.oauth2.clients[i].accessTokenValiditySeconds` 数组token过期时间,单位是秒
|
||||
- `ms.security.oauth2.clients[i].authorizedGrantTypes[i]` 数组,授权类型默认是"refresh_token","password","custom"
|
||||
- `ms.security.oauth2.clients[i].scopes[i]` 作用范围默认是"all","read","write"
|
||||
|
||||
+6
-3
@@ -85,11 +85,14 @@ public class AuthorizationProviderConfig extends AuthorizationServerConfigurerAd
|
||||
if (ArrayUtils.isNotEmpty(securityProperties.getOauth2().getClients())){
|
||||
for (OAuth2ClientProperties client: securityProperties.getOauth2().getClients()){
|
||||
builder.withClient(client.getClientId()).secret(client.getClientSecret())
|
||||
//token的过期时间
|
||||
.accessTokenValiditySeconds(client.getAccessTokenValiditySeconds())
|
||||
.authorizedGrantTypes("refresh_token","password")
|
||||
//授权类型
|
||||
.authorizedGrantTypes(client.getAuthorizedGrantTypes())
|
||||
//refreshToken的过期时间,refreshToken是用来在用户无感知的情况下换取token的
|
||||
.refreshTokenValiditySeconds(2592000)
|
||||
.scopes("all","read","write");
|
||||
.refreshTokenValiditySeconds(client.getAccessTokenValiditySeconds())
|
||||
//授权scope
|
||||
.scopes(client.getScopes());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
-8
@@ -22,10 +22,6 @@ import org.springframework.security.web.authentication.UsernamePasswordAuthentic
|
||||
@EnableResourceServer
|
||||
public class AuthorizationResourceConfig extends ResourceServerConfigurerAdapter {
|
||||
|
||||
/**
|
||||
* todo 待优化,不唯一,应从启动参数中获取
|
||||
*/
|
||||
public static final String DRUID = "/druid/*";
|
||||
|
||||
@Autowired
|
||||
private MsAuthenticationFailureHandler msAuthenticationFailureHandler;
|
||||
@@ -75,10 +71,6 @@ public class AuthorizationResourceConfig extends ResourceServerConfigurerAdapter
|
||||
, SecurityConstants.FORM_LOGIN_PROCESSOR_URI
|
||||
, SecurityConstants.GET_VALIDATE_CODE_URI
|
||||
, SecurityConstants.LOGIN_PAGE
|
||||
, DRUID
|
||||
//用户注册或绑定的页面
|
||||
, "处理用户的注册绑定请求的url"
|
||||
,"/social/signUp"
|
||||
)
|
||||
.permitAll()
|
||||
//任何请求
|
||||
|
||||
+14
-2
@@ -27,13 +27,25 @@ public class SecurityController {
|
||||
*/
|
||||
private RequestCache requestCache = new HttpSessionRequestCache();
|
||||
|
||||
/**
|
||||
* 告知前台,需要进行登录
|
||||
* @param request
|
||||
* @param response
|
||||
* @return
|
||||
* @throws IOException
|
||||
*/
|
||||
@RequestMapping(SecurityConstants.LOGIN_PAGE)
|
||||
@ResponseStatus(code = HttpStatus.UNAUTHORIZED)
|
||||
public ServerResponse requireAuthentication(HttpServletRequest request, HttpServletResponse response) throws IOException {
|
||||
//根据当前请求获取上一次请求的缓存
|
||||
SavedRequest savedRequest = requestCache.getRequest(request, response);
|
||||
String redirectUrl = savedRequest.getRedirectUrl();
|
||||
log.info("用户访问的url是{}但未进行身份认证,触发了跳转。",redirectUrl);
|
||||
String redirectUrl = null;
|
||||
if(savedRequest !=null){
|
||||
redirectUrl= savedRequest.getRedirectUrl();
|
||||
}
|
||||
if (redirectUrl!=null){
|
||||
log.info("用户访问的url是{}但未进行身份认证,触发了跳转。",redirectUrl);
|
||||
}
|
||||
return ServerResponse.errorMsg("未进行身份认证");
|
||||
}
|
||||
}
|
||||
|
||||
+4
-3
@@ -9,13 +9,14 @@ import lombok.Setter;
|
||||
@Getter
|
||||
@Setter
|
||||
public class OAuth2ClientProperties {
|
||||
|
||||
private String clientId;
|
||||
|
||||
private String clientSecret;
|
||||
|
||||
private int accessTokenValiditySeconds;
|
||||
private int accessTokenValiditySeconds = 2592000;
|
||||
|
||||
private String authorizedGrantTypes;
|
||||
private String[] authorizedGrantTypes = new String[]{"refresh_token","password","custom"};
|
||||
|
||||
private String scopes;
|
||||
private String[] scopes = new String[]{"all","read","write"};
|
||||
}
|
||||
|
||||
-2
@@ -18,7 +18,5 @@ public class SecurityProperties {
|
||||
|
||||
private ValidateCodeProperties code = new ValidateCodeProperties();
|
||||
|
||||
private Boolean createRememberTable = true;
|
||||
|
||||
private OAuth2Properties oauth2 = new OAuth2Properties();
|
||||
}
|
||||
|
||||
+3
-1
@@ -27,7 +27,9 @@ public class SmsCodeAuthenticationSecurityConfig extends SecurityConfigurerAdapt
|
||||
@Qualifier("msAuthenticationFailureHandler")
|
||||
private AuthenticationFailureHandler authenticationFailureHandler;
|
||||
|
||||
//todo 需要改成根据手机号获取用户的信息
|
||||
/**
|
||||
* todo 需要改成根据手机号获取用户的信息
|
||||
*/
|
||||
@Autowired
|
||||
@Qualifier("msUserDetailsServiceImpl")
|
||||
private UserDetailsService userDetailsService;
|
||||
|
||||
+4
-17
@@ -1,11 +1,15 @@
|
||||
package com.micro.fast.security.app.validate.code.config.param;
|
||||
|
||||
import com.micro.fast.security.app.master.SecurityConstants;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
/**
|
||||
* 图形验证码默认的配置
|
||||
* @author lsy
|
||||
*/
|
||||
@Getter
|
||||
@Setter
|
||||
public class ImageCodeProperties extends SmsCodeProperties{
|
||||
/**
|
||||
* 验证码的宽度
|
||||
@@ -23,21 +27,4 @@ public class ImageCodeProperties extends SmsCodeProperties{
|
||||
setLength(4);
|
||||
setUrl(SecurityConstants.FORM_LOGIN_PROCESSOR_URI);
|
||||
}
|
||||
|
||||
public int getWidth() {
|
||||
return width;
|
||||
}
|
||||
|
||||
public void setWidth(int width) {
|
||||
this.width = width;
|
||||
}
|
||||
|
||||
public int getHeight() {
|
||||
return height;
|
||||
}
|
||||
|
||||
public void setHeight(int height) {
|
||||
this.height = height;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+4
-24
@@ -1,10 +1,14 @@
|
||||
package com.micro.fast.security.app.validate.code.config.param;
|
||||
|
||||
import com.micro.fast.security.app.master.SecurityConstants;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
/**
|
||||
* @author lsy
|
||||
*/
|
||||
@Getter
|
||||
@Setter
|
||||
public class SmsCodeProperties {
|
||||
|
||||
/**
|
||||
@@ -19,28 +23,4 @@ public class SmsCodeProperties {
|
||||
* 需要进行验证码校验的url
|
||||
*/
|
||||
private String url = SecurityConstants.MOBILE_LOGIN_PROCESSOR_URI;
|
||||
|
||||
public String getUrl() {
|
||||
return url;
|
||||
}
|
||||
|
||||
public void setUrl(String url) {
|
||||
this.url = url;
|
||||
}
|
||||
|
||||
public int getLength() {
|
||||
return length;
|
||||
}
|
||||
|
||||
public void setLength(int length) {
|
||||
this.length = length;
|
||||
}
|
||||
|
||||
public int getExpireIn() {
|
||||
return expireIn;
|
||||
}
|
||||
|
||||
public void setExpireIn(int expireIn) {
|
||||
this.expireIn = expireIn;
|
||||
}
|
||||
}
|
||||
|
||||
+5
-16
@@ -1,28 +1,17 @@
|
||||
package com.micro.fast.security.app.validate.code.config.param;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
/**
|
||||
* 验证码配置参数
|
||||
* @author lsy
|
||||
*/
|
||||
@Getter
|
||||
@Setter
|
||||
public class ValidateCodeProperties {
|
||||
|
||||
private ImageCodeProperties image = new ImageCodeProperties();
|
||||
|
||||
private SmsCodeProperties sms = new SmsCodeProperties();
|
||||
|
||||
public SmsCodeProperties getSms() {
|
||||
return sms;
|
||||
}
|
||||
|
||||
public void setSms(SmsCodeProperties sms) {
|
||||
this.sms = sms;
|
||||
}
|
||||
|
||||
public ImageCodeProperties getImage() {
|
||||
return image;
|
||||
}
|
||||
|
||||
public void setImage(ImageCodeProperties image) {
|
||||
this.image = image;
|
||||
}
|
||||
}
|
||||
|
||||
+20
-10
@@ -15,13 +15,6 @@
|
||||
<version>0.0.1-SNAPSHOT</version>
|
||||
</parent>
|
||||
|
||||
<properties>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
|
||||
<java.version>1.8</java.version>
|
||||
<spring-cloud.version>Edgware.SR1</spring-cloud.version>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
<!--web-->
|
||||
<dependency>
|
||||
@@ -42,10 +35,15 @@
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-actuator</artifactId>
|
||||
</dependency>
|
||||
<!--熔断,断的是这个服务调用其他服务时失败的时候断-->
|
||||
<!--调用其他服务的时候熔断情况的图形化展示-->
|
||||
<dependency>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-starter-hystrix</artifactId>
|
||||
</dependency>
|
||||
<!--调用其他服务的时候熔断情况的图形化展示-->
|
||||
<dependency>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-starter-hystrix</artifactId>
|
||||
<artifactId>spring-cloud-starter-hystrix-dashboard</artifactId>
|
||||
</dependency>
|
||||
<!--对服务的断路由情况进行聚合-->
|
||||
<dependency>
|
||||
@@ -64,7 +62,6 @@
|
||||
<dependency>
|
||||
<groupId>io.zipkin.java</groupId>
|
||||
<artifactId>zipkin-autoconfigure-ui</artifactId>
|
||||
<scope>runtime</scope>
|
||||
</dependency>
|
||||
<!--测试-->
|
||||
<dependency>
|
||||
@@ -80,7 +77,20 @@
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-maven-plugin</artifactId>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
</plugin>
|
||||
<!--<plugin>-->
|
||||
<!--<groupId>org.apache.maven.plugins</groupId>-->
|
||||
<!--<artifactId>maven-javadoc-plugin</artifactId>-->
|
||||
<!--</plugin>-->
|
||||
<plugin>
|
||||
<groupId>com.spotify</groupId>
|
||||
<artifactId>docker-maven-plugin</artifactId>
|
||||
</plugin>
|
||||
</plugins>
|
||||
<finalName>ms-monitor-center</finalName>
|
||||
</build>
|
||||
|
||||
|
||||
|
||||
+4
@@ -2,6 +2,8 @@ package com.micro.fast.monitor.center;
|
||||
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.cloud.client.SpringCloudApplication;
|
||||
import org.springframework.cloud.netflix.hystrix.EnableHystrix;
|
||||
import org.springframework.cloud.netflix.hystrix.dashboard.EnableHystrixDashboard;
|
||||
import org.springframework.cloud.netflix.turbine.EnableTurbine;
|
||||
import zipkin.server.EnableZipkinServer;
|
||||
|
||||
@@ -13,6 +15,8 @@ import zipkin.server.EnableZipkinServer;
|
||||
@EnableTurbine
|
||||
//集群间服务调用情况的聚合展示
|
||||
@EnableZipkinServer
|
||||
@EnableHystrixDashboard
|
||||
@EnableHystrix
|
||||
public class MsMonitorCenterApplication {
|
||||
|
||||
public static void main(String[] args) {
|
||||
|
||||
@@ -12,11 +12,12 @@ import org.springframework.security.core.userdetails.UserDetailsService;
|
||||
import org.springframework.security.core.userdetails.UsernameNotFoundException;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
|
||||
/**
|
||||
* 获取用户的信息
|
||||
* @author lsy
|
||||
*/
|
||||
@Component
|
||||
@Component("msUserDetailsServiceImpl")
|
||||
public class UserDetailsServiceImpl implements UserDetailsService {
|
||||
|
||||
@Autowired
|
||||
|
||||
Reference in New Issue
Block a user