Skip to content

Commit 2620b1e

Browse files
authored
Merge pull request #79 from hocgin/v1.0.20
V1.0.20
2 parents 45514f7 + 9d5f56e commit 2620b1e

File tree

7 files changed

+114
-5
lines changed

7 files changed

+114
-5
lines changed

README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
# spring-boot-starters-project
22

3-
> [![Publish Package](https://github.com/hocgin/spring-boot-starters-project/actions/workflows/publish.yml/badge.svg)](https://github.com/hocgin/spring-boot-starters-project/actions/workflows/publish.yml)
3+
> [![Deploy](https://github.com/hocgin/spring-boot-starters-project/actions/workflows/deploy.yml/badge.svg?branch=v1.0.20)](https://github.com/hocgin/spring-boot-starters-project/actions/workflows/deploy.yml)
4+
> [![Maven Central](https://maven-badges.herokuapp.com/maven-central/in.hocg.boot/spring-boot-starters-project/badge.svg)](https://search.maven.org/search?q=in.hocg.boot)
5+
46

57
[Maven Center](https://search.maven.org/search?q=in.hocg.boot)
68

@@ -33,7 +35,6 @@
3335
|wx-ma-spring-boot-starter|微信公众号(配置化)|-|
3436
|wx-mp-spring-boot-starter|微信小程序(配置化)|-|
3537
|xxljob-spring-boot-starter|xxljob(薄封装)|-|
36-
3738
|spring-boot-webmagic|挖坑|-|
3839
|spring-boot-excel|挖坑|-|
3940
|spring-boot-elasticsearch|挖坑|-|

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
<version>${revision}</version>
1717

1818
<properties>
19-
<revision>1.0.19</revision>
19+
<revision>1.0.20</revision>
2020

2121
<java.version>1.8</java.version>
2222
<java.source.version>1.8</java.source.version>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package in.hocg.boot.mybatis.plus.autoconfiguration.ro;
2+
3+
import lombok.Data;
4+
import lombok.EqualsAndHashCode;
5+
import lombok.experimental.Accessors;
6+
7+
import java.io.Serializable;
8+
9+
/**
10+
* Created by hocgin on 2021/11/29
11+
12+
* 滚动翻页
13+
*
14+
* @author hocgin
15+
*/
16+
@Data
17+
@Accessors(chain = true)
18+
@EqualsAndHashCode(callSuper = true)
19+
public class ScrollRo extends BasicRo {
20+
private Serializable nextId;
21+
private Integer size = 20;
22+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
package in.hocg.boot.mybatis.plus.autoconfiguration.vo;
2+
3+
import lombok.Data;
4+
import lombok.experimental.Accessors;
5+
6+
import java.io.Serializable;
7+
import java.util.Collections;
8+
import java.util.List;
9+
10+
/**
11+
* Created by hocgin on 2021/11/29
12+
13+
*
14+
* @author hocgin
15+
*/
16+
@Data
17+
@Accessors(chain = true)
18+
public class IScroll<T> implements Serializable {
19+
/**
20+
* 是否有下一页
21+
*/
22+
private Boolean hasMore = false;
23+
/**
24+
* 上一页的最后ID(> ID)
25+
*/
26+
private Serializable nextId;
27+
/**
28+
* 数据
29+
*/
30+
private List<T> records = Collections.emptyList();
31+
}

spring-boot-sso/sso-client-spring-boot-autoconfigure/src/main/java/in/hocg/boot/sso/client/autoconfigure/core/servlet/ServletSsoClientConfiguration.java

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
package in.hocg.boot.sso.client.autoconfigure.core.servlet;
22

3+
import cn.hutool.core.collection.CollUtil;
4+
import cn.hutool.core.util.ArrayUtil;
5+
import cn.hutool.core.util.StrUtil;
36
import cn.hutool.json.JSONUtil;
47
import in.hocg.boot.sso.client.autoconfigure.core.AuthenticationResult;
58
import in.hocg.boot.sso.client.autoconfigure.properties.SsoClientProperties;
@@ -30,6 +33,8 @@
3033
import java.io.IOException;
3134
import java.io.PrintWriter;
3235
import java.nio.charset.StandardCharsets;
36+
import java.util.List;
37+
import java.util.Map;
3338

3439
/**
3540
* Created by hocgin on 2020/9/2
@@ -50,15 +55,45 @@ protected void configure(HttpSecurity http) throws Exception {
5055
String[] ignoreUrls = properties.getIgnoreUrls().toArray(new String[]{});
5156
String[] denyUrls = properties.getDenyUrls().toArray(new String[]{});
5257
String[] authenticatedUrls = properties.getAuthenticatedUrls().toArray(new String[]{});
58+
Map<String, List<String>> hasAnyRole = properties.getHasAnyRole();
59+
Map<String, List<String>> hasAnyAuthority = properties.getHasAnyAuthority();
60+
Map<String, String> hasIpAddress = properties.getHasIpAddress();
5361
{
5462
ExpressionUrlAuthorizationConfigurer<HttpSecurity>.ExpressionInterceptUrlRegistry expressionInterceptUrlRegistry =
5563
http.authorizeRequests();
64+
65+
// 如果配置禁止访问
5666
if (denyUrls.length > 0) {
5767
expressionInterceptUrlRegistry.antMatchers(denyUrls).denyAll();
5868
}
69+
70+
// 如果配置需登陆
5971
if (authenticatedUrls.length > 0) {
6072
expressionInterceptUrlRegistry.antMatchers(authenticatedUrls).authenticated();
6173
}
74+
75+
// 如果配置角色
76+
if (CollUtil.isNotEmpty(hasAnyRole)) {
77+
hasAnyRole.entrySet().stream()
78+
.filter(entry -> StrUtil.isNotBlank(entry.getKey()) && CollUtil.isNotEmpty(entry.getValue()))
79+
.forEach(entry -> expressionInterceptUrlRegistry.antMatchers(entry.getKey()).hasAnyRole(ArrayUtil.toArray(entry.getValue(), String.class)));
80+
}
81+
82+
// 如果配置权限
83+
if (CollUtil.isNotEmpty(hasAnyAuthority)) {
84+
hasAnyRole.entrySet().stream()
85+
.filter(entry -> StrUtil.isNotBlank(entry.getKey()) && CollUtil.isNotEmpty(entry.getValue()))
86+
.forEach(entry -> expressionInterceptUrlRegistry.antMatchers(entry.getKey()).hasAnyAuthority(ArrayUtil.toArray(entry.getValue(), String.class)));
87+
}
88+
89+
// 如果配置IP白名单
90+
if (CollUtil.isNotEmpty(hasIpAddress)) {
91+
hasIpAddress.entrySet().stream()
92+
.filter(entry -> StrUtil.isNotBlank(entry.getKey()) && StrUtil.isNotBlank(entry.getValue()))
93+
.forEach(entry -> expressionInterceptUrlRegistry.antMatchers(entry.getKey()).hasIpAddress(entry.getValue()));
94+
}
95+
96+
// 如果配置忽略
6297
if (ignoreUrls.length > 0) {
6398
expressionInterceptUrlRegistry.antMatchers(ignoreUrls).permitAll();
6499
}

spring-boot-sso/sso-client-spring-boot-autoconfigure/src/main/java/in/hocg/boot/sso/client/autoconfigure/properties/SsoClientProperties.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
package in.hocg.boot.sso.client.autoconfigure.properties;
22

33

4+
import com.google.common.collect.Maps;
45
import lombok.Data;
56
import lombok.experimental.Accessors;
67
import org.springframework.boot.context.properties.ConfigurationProperties;
78

89
import java.util.Collections;
910
import java.util.List;
11+
import java.util.Map;
1012

1113
/**
1214
* Created by hocgin on 2019/6/12.
@@ -33,4 +35,16 @@ public class SsoClientProperties {
3335
* 需认证(支持表达式)
3436
*/
3537
private List<String> authenticatedUrls = Collections.emptyList();
38+
/**
39+
* 需要任意角色(支持表达式)
40+
*/
41+
private Map<String, List<String>> hasAnyRole = Maps.newHashMap();
42+
/**
43+
* 需要任意权限(支持表达式)
44+
*/
45+
private Map<String, List<String>> hasAnyAuthority = Maps.newHashMap();
46+
/**
47+
* IP 白名单(支持表达式)
48+
*/
49+
private Map<String, String> hasIpAddress = Maps.newHashMap();
3650
}

spring-boot-web/web-core/src/main/java/in/hocg/boot/web/exception/ServiceException.java

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
import cn.hutool.http.HttpStatus;
55
import lombok.Getter;
66

7+
import java.util.function.Supplier;
8+
79
/**
810
* Created by hocgin on 2019-09-24.
911
@@ -19,15 +21,19 @@ protected ServiceException(int code, String message) {
1921
this.code = code;
2022
}
2123

24+
public static Supplier<ServiceException> supplier(CharSequence template, Object... args) {
25+
return () -> ServiceException.wrap(StrUtil.format(template, args));
26+
}
27+
2228
public static ServiceException wrap(Exception e) {
2329
return wrap(e.getMessage());
2430
}
2531

26-
public static ServiceException wrap(String message, Object... args) {
32+
public static ServiceException wrap(CharSequence message, Object... args) {
2733
return wrap(HttpStatus.HTTP_INTERNAL_ERROR, message, args);
2834
}
2935

30-
public static ServiceException wrap(int code, String message, Object... args) {
36+
public static ServiceException wrap(int code, CharSequence message, Object... args) {
3137
return new ServiceException(code, StrUtil.format(message, args));
3238
}
3339

0 commit comments

Comments
 (0)