zoukankan      html  css  js  c++  java
  • camunda授权的一些简单操作

    /**
    * 授权操作
    */
    public class ZccAuthorizationService {
    AuthorizationService authorizationService;
    @Before
    public void init(){
    ProcessEngineConfiguration processEngineConfiguration = ProcessEngineConfiguration.createProcessEngineConfigurationFromResource("camunda.cfg.xml");
    ProcessEngine processEngine = processEngineConfiguration.buildProcessEngine();
    authorizationService = processEngine.getAuthorizationService();
    System.out.println("####");
    System.out.println("authorizationService:"+authorizationService);
    }
    @Test
    public void getIdentityService(){
    init();
    }

    /**
    * select distinct RES.* from ACT_RU_AUTHORIZATION RES WHERE RES.USER_ID_ in ( ? ) order by RES.ID_ asc LIMIT ? OFFSET ?
    * 也可以向操作用户那样添加一些查询条件
    */
    @Test
    public void createAuthorizationQuery(){
    List<Authorization> list = authorizationService.createAuthorizationQuery().userIdIn("zcc2").list();
    for (int i=0;i<list.size();i++){
    Authorization authorization = list.get(i);
    System.out.println(authorization.getId());
    System.out.println(authorization.getAuthorizationType());
    System.out.println(authorization.getResourceId());
    System.out.println(authorization.getGroupId());
    }


    }


    public void createAuthorization(String userId, String groupId, Resource resource, String resourceId, Permission[] permissions){
    Authorization authorization=authorizationService.createNewAuthorization(Authorization.AUTH_TYPE_GRANT);
    authorization.setUserId(userId);
    authorization.setGroupId(groupId);
    authorization.setResource(resource);
    authorization.setResourceId(resourceId);
    authorization.setPermissions(permissions);
    authorizationService.saveAuthorization(authorization);
    }

    public static class TestResource implements Resource{
    String reaourceName;int resrouceType;
    public TestResource(String reaourceName,int resrouceType) {
    this.reaourceName=reaourceName;
    this.resrouceType=resrouceType;

    }

    public String getReaourceName() {
    return reaourceName;
    }

    public void setReaourceName(String reaourceName) {
    this.reaourceName = reaourceName;
    }

    public int getResrouceType() {
    return resrouceType;
    }

    public void setResrouceType(int resrouceType) {
    this.resrouceType = resrouceType;
    }

    @Override
    public String resourceName() {
    return null;
    }

    @Override
    public int resourceType() {
    return 0;
    }
    }

    /**
    * Preparing: insert into ACT_RU_AUTHORIZATION ( ID_, TYPE_, GROUP_ID_, USER_ID_, RESOURCE_TYPE_, RESOURCE_ID_, PERMS_, REV_ ) values ( ?, ?, ?, ?, ?, ?, ?, 1 )
    * Parameters: 601(String), 1(Integer), null, zcc2(String), 0(Integer), 60(String), 2147483647(Integer)
    */
    @Test
    public void addAuthorization(){
    Resource resource1=new TestResource("resource1",100);
    Resource resource2=new TestResource("resource2",200);
    createAuthorization("zcc2",null,resource1,"60", new Permission[]{Permissions.ALL});
    }


    @Test
    public void addAuthorization2(){
    Authorization authorization=authorizationService.createNewAuthorization(Authorization.AUTH_TYPE_GRANT);
    authorization.setUserId("zcc3");
    authorization.setResource(Resources.APPLICATION);
    authorization.setResourceType(10);
    authorization.setResourceId("*");
    authorization.setPermissions(new Permission[]{Permissions.ALL});
    authorizationService.saveAuthorization(authorization);

    }

    /**
    * 授权访问用户
    */
    @Test
    public void addAuthorization3(){
    Authorization authorization=authorizationService.createNewAuthorization(Authorization.AUTH_TYPE_GRANT);
    authorization.setUserId("zcc3");
    authorization.setResource(Resources.USER);
    authorization.setResource(Resources.APPLICATION);
    authorization.setResourceType(1);
    authorization.setResourceId("*");
    authorization.setPermissions(new Permission[]{Permissions.CREATE,Permissions.UPDATE});
    authorizationService.saveAuthorization(authorization);

    }

    /**
    * 授权访问组
    */
    @Test
    public void addAuthorization4(){
    Authorization authorization=authorizationService.createNewAuthorization(Authorization.AUTH_TYPE_GRANT);
    authorization.setUserId("zcc3");
    authorization.setResource(Resources.GROUP);
    authorization.setResourceId("*");
    authorization.setPermissions(new Permission[]{Permissions.READ,Permissions.CREATE,Permissions.UPDATE});
    authorizationService.saveAuthorization(authorization);

    }

    /**
    * 授权访问租户
    */
    @Test
    public void addAuthorization5(){
    Authorization authorization=authorizationService.createNewAuthorization(Authorization.AUTH_TYPE_GRANT);
    authorization.setUserId("zcc3");
    authorization.setResource(Resources.TENANT);
    authorization.setResourceId("*");
    authorization.setPermissions(new Permission[]{Permissions.READ,Permissions.CREATE,Permissions.UPDATE});
    authorizationService.saveAuthorization(authorization);

    }

    }
  • 相关阅读:
    Gridview布局界面练习Base Adapter
    用Handler图片轮播练习
    登陆界面用户名,密码存储以及再次登陆自动填充用户名、密码
    登陆界面练习
    进度条练习
    上下文菜单项(contextMenu)----长按按钮弹出菜单项
    菜单项的练习
    Android ImageView的scaleType属性与adjustViewBounds属性
    android单选框和复选框(练习)
    QQ登陆模拟练习
  • 原文地址:https://www.cnblogs.com/yscec/p/11644451.html
Copyright © 2011-2022 走看看