Browse Source

增加说明

zhouhao 8 years ago
parent
commit
a91d1d8188

+ 3 - 0
hsweb-examples/README.md

@@ -0,0 +1,3 @@
+#系统演示模块
+
+1. [hsweb-examples-simple](hsweb-examples-simple)基本演示

+ 28 - 0
hsweb-examples/hsweb-examples-simple/README.md

@@ -0,0 +1,28 @@
+# 演示
+简单示例,无页面
+
+## 运行
+
+1. IDE
+导入项目后,运行: `org.hswebframework.web.example.simple.SpringBootExample.main`
+
+2. maven
+先安装 `hsweb-framework`
+```bash
+ /hsweb-framework $ mvn install
+ /hsweb-framework $ cd hsweb-examples/hsweb-examples-simple
+ /hsweb-examples-simple $ mvn spring-boot:run
+  
+```
+
+启动成功后,浏览器打开: [swagger-ui](http://localhost:8080/swagger-ui.html) 试试
+
+如果不想使用权限控制,请注释掉 pom.xml的
+```xml
+<dependency>
+    <groupId>org.hswebframework.web</groupId>
+    <artifactId>hsweb-authorization-shiro</artifactId>
+    <version>${project.version}</version>
+</dependency>
+
+```

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

@@ -1,8 +1,7 @@
 package org.hswebframework.web.example.simple;
 
-import io.swagger.annotations.*;
-import org.apache.shiro.authz.annotation.RequiresPermissions;
-import org.apache.shiro.authz.annotation.RequiresUser;
+import io.swagger.annotations.ApiOperation;
+import io.swagger.annotations.ApiResponse;
 import org.hswebframework.web.authorization.Authorization;
 import org.hswebframework.web.authorization.AuthorizationHolder;
 import org.hswebframework.web.authorization.Permission;
@@ -13,10 +12,10 @@ import org.hswebframework.web.commons.entity.Entity;
 import org.hswebframework.web.commons.entity.PagerResult;
 import org.hswebframework.web.commons.entity.param.QueryParamEntity;
 import org.hswebframework.web.controller.QueryController;
-import org.hswebframework.web.controller.authorization.UserController;
 import org.hswebframework.web.controller.message.ResponseMessage;
 import org.hswebframework.web.entity.authorization.SimpleUserEntity;
 import org.hswebframework.web.entity.authorization.UserEntity;
+import org.hswebframework.web.model.authorization.UserModel;
 import org.hswebframework.web.service.QueryByEntityService;
 import org.hswebframework.web.service.QueryService;
 import org.springframework.web.bind.annotation.*;
@@ -39,29 +38,30 @@ public class TestController implements QueryController<UserEntity, String, Query
         return ResponseMessage.ok(authorization);
     }
 
-    @GetMapping("/test")
-    @RequiresPermissions("test:*")
-    @ApiOperation("测试")
-    @ApiResponse(code = 200, message = "成功")
-    public ResponseMessage testShiro(Authorization authorization) {
-        return ResponseMessage.ok(authorization);
-    }
-
     @GetMapping("/testQuery")
-    @RequiresUser
+    @Authorize
     @RequiresDataAccess(permission = "test", action = Permission.ACTION_QUERY)
     @RequiresFieldAccess(permission = "test", action = Permission.ACTION_QUERY)
     @ApiOperation("测试查询")
-    public ResponseMessage testQuery(QueryParamEntity entity) {
+    public ResponseMessage<QueryParamEntity> testQuery(QueryParamEntity entity) {
+        /*
+        @RequiresFieldAccess 字段级别权限控制
+        entity.getExcludes() 自动填充不能访问的字段
+        */
+
+        /*
+        @RequiresDataAccess 数据级别权限控制
+        entity.terms 被嵌入查询条件
+        */
         return ResponseMessage.ok(entity);
     }
 
     @PutMapping("/testUpdate/{id}")
-    @RequiresUser
     @RequiresDataAccess(permission = "test", action = Permission.ACTION_UPDATE)
     @RequiresFieldAccess(permission = "test", action = Permission.ACTION_UPDATE)
-    public ResponseMessage testUpdate(@PathVariable String id, @RequestBody UserEntity entity) {
-        return ResponseMessage.ok(entity);
+    public ResponseMessage<UserModel> testUpdate(@PathVariable String id, @RequestBody UserModel model) {
+
+        return ResponseMessage.ok(model);
     }
 
     @Override

+ 1 - 1
hsweb-system/hsweb-system-authorization/README.md

@@ -4,4 +4,4 @@
 
 ## 授权
 [AuthorizationController](hsweb-system-authorization-controller/src/main/java/org/hswebframework/web/controller/authorization/AuthorizationController.java)
-仅进行基础授权,通过触发`AuthorizationListener`,进行自定义控制逻辑.详细方式见:[hsweb-authorization-api](../../hsweb-authorization/hsweb-authorization-api)
+仅进行基础授权,通过触发`AuthorizationListener`,进行自定义控制逻辑.详细方式见:[hsweb-authorization-api](../../hsweb-authorization/hsweb-authorization-api#listener)