Skip to content

Commit d389d05

Browse files
committed
优化权限提示
1 parent 23d03dd commit d389d05

File tree

3 files changed

+16
-2
lines changed

3 files changed

+16
-2
lines changed

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package org.hswebframework.web.authorization.define;
22

33

4+
import java.util.StringJoiner;
5+
46
/**
57
* 权限控制定义,定义权限控制的方式
68
*
@@ -18,4 +20,13 @@ public interface AuthorizeDefinition {
1820
Phased getPhased();
1921

2022
boolean isEmpty();
23+
24+
default String getDescription() {
25+
ResourcesDefinition res = getResources();
26+
StringJoiner joiner = new StringJoiner(";");
27+
for (ResourceDefinition resource : res.getResources()) {
28+
joiner.add(resource.getId() + ":" + String.join(",", resource.getActionIds()));
29+
}
30+
return joiner.toString();
31+
}
2132
}

hsweb-authorization/hsweb-authorization-api/src/main/java/org/hswebframework/web/authorization/exception/AccessDenyException.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,11 @@ public AccessDenyException(String message) {
2626
super(message);
2727
}
2828

29+
public AccessDenyException(String message, String code) {
30+
this(message, code, null);
31+
}
2932
public AccessDenyException(String message, Throwable cause) {
30-
this(message,"access_denied", cause);
33+
this(message, "access_denied", cause);
3134
}
3235

3336
public AccessDenyException(String message, String code, Throwable cause) {

hsweb-authorization/hsweb-authorization-basic/src/main/java/org/hswebframework/web/authorization/basic/handler/DefaultAuthorizingHandler.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ protected void handleRBAC(Authentication authentication, AuthorizeDefinition def
106106
ResourcesDefinition resources = definition.getResources();
107107

108108
if (!resources.hasPermission(authentication.getPermissions())) {
109-
throw new AccessDenyException();
109+
throw new AccessDenyException(definition.getMessage(),definition.getDescription());
110110
}
111111
}
112112
}

0 commit comments

Comments
 (0)