Skip to content

Commit 0c29f53

Browse files
committed
refactor: 优化权限初始化
1 parent f1fb227 commit 0c29f53

File tree

4 files changed

+25
-17
lines changed

4 files changed

+25
-17
lines changed

changes.sh

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,11 @@ while read file; do
77
if [ -f "$dir/pom.xml" ]; then echo "$dir"; break; fi
88
dir=$(dirname "$dir")
99
done
10-
done | sort -u | tr '\n' ',' | sed 's/,$//'
10+
done | sort -u | tr '\n' ',' | sed 's/,$//'
11+
12+
# 如果为空,则使用默认值 '.'
13+
if [ -z "$modules" ]; then
14+
echo "."
15+
else
16+
echo "$modules"
17+
fi

hsweb-authorization/hsweb-authorization-api/src/main/java/org/hswebframework/web/authorization/define/ResourcesDefinition.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,14 @@
99
import org.hswebframework.web.authorization.annotation.Logical;
1010

1111
import java.util.*;
12-
import java.util.function.Function;
12+
import java.util.concurrent.ConcurrentHashMap;
1313
import java.util.stream.Collectors;
1414

1515
@Getter
1616
@Setter
1717
public class ResourcesDefinition {
1818

19-
private Set<ResourceDefinition> resources = new HashSet<>();
19+
private final Set<ResourceDefinition> resources = ConcurrentHashMap.newKeySet();
2020

2121
private Logical logical = Logical.DEFAULT;
2222

hsweb-authorization/hsweb-authorization-basic/src/main/java/org/hswebframework/web/authorization/basic/aop/AopAuthorizingController.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
import org.springframework.beans.factory.annotation.Autowired;
1818
import org.springframework.boot.CommandLineRunner;
1919
import org.springframework.context.ApplicationEventPublisher;
20-
import org.springframework.core.ReactiveAdapterRegistry;
20+
import org.springframework.core.Ordered;
2121
import org.springframework.stereotype.Controller;
2222
import org.springframework.web.bind.annotation.RequestMapping;
2323
import org.springframework.web.bind.annotation.RestController;
@@ -26,9 +26,6 @@
2626

2727
import java.lang.reflect.Method;
2828
import java.util.List;
29-
import java.util.concurrent.Callable;
30-
import java.util.function.Consumer;
31-
import java.util.function.Function;
3229
import java.util.function.Supplier;
3330
import java.util.stream.Collectors;
3431

@@ -38,7 +35,7 @@
3835
*/
3936
@Slf4j
4037
@SuppressWarnings("all")
41-
public class AopAuthorizingController extends StaticMethodMatcherPointcutAdvisor implements CommandLineRunner, MethodInterceptor {
38+
public class AopAuthorizingController extends StaticMethodMatcherPointcutAdvisor implements CommandLineRunner, MethodInterceptor, Ordered {
4239

4340
private static final long serialVersionUID = 1154190623020670672L;
4441

@@ -214,5 +211,8 @@ public void run(String... args) throws Exception {
214211
}
215212
}
216213

217-
214+
@Override
215+
public int getOrder() {
216+
return Ordered.HIGHEST_PRECEDENCE;
217+
}
218218
}

hsweb-system/hsweb-system-authorization/hsweb-system-authorization-default/src/main/java/org/hswebframework/web/system/authorization/defaults/service/PermissionSynchronization.java

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020

2121
import javax.persistence.Column;
2222
import java.util.*;
23+
import java.util.concurrent.ConcurrentHashMap;
2324
import java.util.function.Function;
2425
import java.util.stream.Collectors;
2526

@@ -95,14 +96,14 @@ public void run(String... args) throws Exception {
9596
permissionRepository
9697
.createQuery()
9798
.fetch()
98-
.collect(Collectors.toMap(PermissionEntity::getId, Function.identity()))
99-
.flatMap(group -> Flux.fromIterable(definition.getResources())
100-
.map(d -> PermissionSynchronization.convert(group, d, entityFieldsMapping))
101-
.as(permissionRepository::save))
102-
.doOnError(err -> log.warn("sync permission error", err))
103-
.subscribe(l -> {
104-
log.info("sync permission success:{}", l);
105-
});
99+
.collectMap(PermissionEntity::getId, Function.identity(), ConcurrentHashMap::new)
100+
.flatMap(group -> Flux
101+
.fromIterable(definition.getResources())
102+
.map(d -> PermissionSynchronization.convert(group, d, entityFieldsMapping))
103+
.as(permissionRepository::save))
104+
.subscribe(
105+
l -> log.info("sync permission success:{}", l),
106+
err -> log.warn("sync permission error", err));
106107

107108
}
108109
}

0 commit comments

Comments
 (0)