Skip to content

Commit 46a17d5

Browse files
committed
优化api
1 parent 80bfaa9 commit 46a17d5

File tree

7 files changed

+13
-7
lines changed

7 files changed

+13
-7
lines changed

hsweb-authorization/hsweb-authorization-api/src/main/java/org/hswebframework/web/authorization/annotation/Authorize.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,8 @@
6363
/**
6464
* 验证是否为指定user
6565
*
66-
* @return user id array
67-
* @see User#getId()
66+
* @return username array
67+
* @see User#getUsername()
6868
*/
6969
String[] user() default {};
7070

hsweb-authorization/hsweb-authorization-shiro/src/main/java/org/hswebframework/web/authorization/shiro/boost/SimpleAuthorizeMethodInterceptor.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ public void assertAuthorized(Annotation a) throws AuthorizationException {
114114
Function<Predicate<String>, Boolean> func = logicalIsOr
115115
? authorizeConfig.user.stream()::anyMatch
116116
: authorizeConfig.user.stream()::allMatch;
117-
access = func.apply(authorization.getUser().getId()::equals);
117+
access = func.apply(authorization.getUser().getUsername()::equals);
118118
}
119119
if (!access) {
120120
throw new AuthorizationException(authorizeConfig.message);

hsweb-examples/hsweb-examples-simple/src/main/java/org/hswebframework/web/example/simple/SpringBootExample.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,13 +126,16 @@ public static void main(String[] args) {
126126

127127
@Override
128128
public void run(String... strings) throws Exception {
129+
//只能查询自己创建的数据
129130
DataAccessEntity accessEntity = new DataAccessEntity();
130131
accessEntity.setType(DataAccess.Type.OWN_CREATED.name());
131132
accessEntity.setAction(Permission.ACTION_QUERY);
132133

134+
//只能修改自己创建的数据
133135
DataAccessEntity updateAccessEntity = new DataAccessEntity();
134136
updateAccessEntity.setType(DataAccess.Type.OWN_CREATED.name());
135137
updateAccessEntity.setAction(Permission.ACTION_UPDATE);
138+
//脚本方式自定义控制
136139
// updateAccessEntity.setConfig(JSON.toJSONString(new SimpleScriptDataAccess("" +
137140
// "println(id);" +
138141
// "println(entity);" +

hsweb-examples/hsweb-examples-simple/src/main/java/org/hswebframework/web/example/simple/TestController.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package org.hswebframework.web.example.simple;
22

33
import io.swagger.annotations.ApiOperation;
4-
import io.swagger.annotations.ApiResponse;
54
import org.hswebframework.web.authorization.Authorization;
65
import org.hswebframework.web.authorization.AuthorizationHolder;
76
import org.hswebframework.web.authorization.Permission;
@@ -60,7 +59,6 @@ public ResponseMessage<QueryParamEntity> testQuery(QueryParamEntity entity) {
6059
@RequiresDataAccess(permission = "test", action = Permission.ACTION_UPDATE)
6160
@RequiresFieldAccess(permission = "test", action = Permission.ACTION_UPDATE)
6261
public ResponseMessage<UserModel> testUpdate(@PathVariable String id, @RequestBody UserModel model) {
63-
6462
return ResponseMessage.ok(model);
6563
}
6664

hsweb-starter/hsweb-spring-boot-starter/src/main/java/org/hswebframework/web/starter/convert/FastJsonHttpMessageConverter.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import com.alibaba.fastjson.JSON;
44
import com.alibaba.fastjson.JSONPObject;
5+
import com.alibaba.fastjson.parser.ParserConfig;
56
import com.alibaba.fastjson.serializer.PropertyPreFilter;
67
import com.alibaba.fastjson.serializer.SerializerFeature;
78
import com.alibaba.fastjson.serializer.SimplePropertyPreFilter;
@@ -29,6 +30,11 @@
2930

3031
public class FastJsonHttpMessageConverter extends AbstractHttpMessageConverter<Object> {
3132

33+
static {
34+
// TODO: 17-3-16 白名单应可配置
35+
ParserConfig.getGlobalInstance().addAccept("org.hswebframework.web.entity.");
36+
}
37+
3238
public final static Charset UTF8 = Charset.forName("UTF-8");
3339

3440
private Charset charset = UTF8;

hsweb-system/hsweb-system-authorization/hsweb-system-authorization-model/src/main/java/org/hswebframework/web/model/authorization/UserModel.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
public interface UserModel extends Model {
3030
void setName(String name);
3131

32-
@ApiModelProperty(value = "用户登录名", required = true, readOnly = true)
32+
@ApiModelProperty(value = "用户名", required = true, readOnly = true)
3333
String getUsername();
3434

3535
void setUsername(String username);

hsweb-system/hsweb-system-organizational/hsweb-system-organizational-entity/src/main/java/org/hswebframework/web/entity/organizational/DepartmentEntity.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
*/
1717
package org.hswebframework.web.entity.organizational;
1818

19-
import org.hswebframework.web.commons.entity.GenericEntity;
2019
import org.hswebframework.web.commons.entity.TreeSortSupportEntity;
2120

2221
/**

0 commit comments

Comments
 (0)