View Javadoc
1   package cn.home1.oss.lib.security.api;
2   
3   import cn.home1.oss.lib.common.DiscoverableEnum;
4   
5   import org.springframework.security.core.GrantedAuthority;
6   
7   /**
8    * User should define enum which implements this interface.
9    * Created by zhanghaolun on 16/7/14.
10   */
11  public interface StaticPrivilege<T extends Enum<T> & StaticPrivilege<T>>
12      extends DiscoverableEnum<T>, GrantedAuthority {
13  
14    String PRIVILEGE_PREFIX = "PRIVILEGE_";
15  
16    static String toAuthority(final String resource, final String action) {
17      return PRIVILEGE_PREFIX + resource + "_" + action;
18    }
19  
20    String getAction();
21  
22    @Override
23    default String getAuthority() {
24      return toAuthority(getResource(), getAction());
25    }
26  
27    String getResource();
28  
29    @Override
30    default String getText() {
31      return this.getAuthority();
32    }
33  }