【@RequiresPermissions】@RequiresPermissions許可權和其原始碼
一、原始碼:
@RequiresPermissions("operation:view")
@RequestMapping(value="{id}",method = RequestMethod.GET)
public Result<SysOperation> findById(@PathVariable Long id) throws Exception {
SysOperation sysOperation = operationService.selectById(id);
return new ResultBuilder<SysOperation>().data(sysOperation).build();
}
①@RequestPermissions()表示許可權;
②@RequestMapping(value="{id}",method=RequestMethod.GET)表示瀏覽器對映的地址為value所對應的值"{id}",而method是請求的方式,此處是selectById查詢,所以用GET沒有問題,也不怕暴露安全資訊;
③Result<SysOperation>是SysOperation類的泛型;
④@PathVariable將request裡的引數的值繫結到controller方法中;
@PathVariable的外文技術貼:http://docs.spring.io/spring/docs/current/spring-framework-reference/html/mvc.html
二、RequestPermissions原始碼:
package org.apache.shiro.authz.annotation;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
@Target({ElementType.TYPE, ElementType.METHOD})
@Retention(RetentionPolicy.RUNTIME)
public @interface RequiresPermissions {
String[ ] value();
Logical logical() default Logical.AND;
}
①Apache Shiro是一個強大且易用的Java安全框架,執行身份驗證、授權、密碼學和會話管理。
②Retention()是存在時間,持續期;
③@interface { }是自定義一個註解的寫法;
④public @interfaceRequiresPermissions{ }定義了一個公共的,介面,名叫RequiresPermissions;
RequiresPermissions裡面有兩句話:
String[ ] value();
Logical logical() default Logical.AND;
看不懂,請大神指教;