Package org.camunda.bpm.engine.authorization

Examples of org.camunda.bpm.engine.authorization.Authorization


  }
   
  public void testDeleteAuthorization() {
   
    // create global auth
    Authorization basePerms = authorizationService.createNewAuthorization(AUTH_TYPE_GLOBAL);
    basePerms.setResource(AUTHORIZATION);
    basePerms.setResourceId(ANY);
    basePerms.addPermission(ALL);
    basePerms.removePermission(DELETE); // revoke delete
    authorizationService.saveAuthorization(basePerms);
   
    // turn on authorization
    processEngineConfiguration.setAuthorizationEnabled(true);   
    identityService.setAuthenticatedUserId(jonny2);
       
    try {
      // try to delete authorization
      authorizationService.deleteAuthorization(basePerms.getId());
      fail("exception expected");
     
    } catch (AuthorizationException e) {
      assertEquals(DELETE.getName(), e.getViolatedPermissionName());
      assertEquals(jonny2, e.getUserId());
      assertEquals(AUTHORIZATION.resourceName(), e.getResourceType());
      assertEquals(basePerms.getId(), e.getResourceId());
    }
  }
View Full Code Here


  }

  public void testUserUpdateAuthorizations() {
   
    // create global auth
    Authorization basePerms = authorizationService.createNewAuthorization(AUTH_TYPE_GLOBAL);
    basePerms.setResource(AUTHORIZATION);
    basePerms.setResourceId(ANY);
    basePerms.addPermission(ALL);
    basePerms.removePermission(UPDATE); // revoke update
    authorizationService.saveAuthorization(basePerms);
   
    // turn on authorization
    processEngineConfiguration.setAuthorizationEnabled(true);   
    identityService.setAuthenticatedUserId(jonny2);
     
    // fetch authhorization
    basePerms = authorizationService.createAuthorizationQuery().singleResult();
    // make some change to the perms
    basePerms.addPermission(ALL);
   
    try {
      authorizationService.saveAuthorization(basePerms);
      fail("exception expected");
     
    } catch (AuthorizationException e) {
      assertEquals(UPDATE.getName(), e.getViolatedPermissionName());
      assertEquals(jonny2, e.getUserId());
      assertEquals(AUTHORIZATION.resourceName(), e.getResourceType());
      assertEquals(basePerms.getId(), e.getResourceId());
    }

    // but we can create a new auth   
    Authorization newAuth = authorizationService.createNewAuthorization(AUTH_TYPE_GRANT);
    newAuth.setUserId("jonny2");
    newAuth.setResource(AUTHORIZATION);
    newAuth.setResourceId(ANY);
    newAuth.addPermission(ALL);
    authorizationService.saveAuthorization(newAuth);
   
  }
View Full Code Here

    // we are jonny2
    String authUserId = "jonny2";
    identityService.setAuthenticatedUserId(authUserId);
   
    // create new auth wich revokes read access on auth
    Authorization basePerms = authorizationService.createNewAuthorization(AUTH_TYPE_GLOBAL);
    basePerms.setResource(AUTHORIZATION);   
    basePerms.setResourceId(ANY);
    authorizationService.saveAuthorization(basePerms);
   
    // I can see it
    assertEquals(1, authorizationService.createAuthorizationQuery().count());
View Full Code Here

  }

  public AuthorizationDto createAuthorization(UriInfo context, AuthorizationCreateDto dto) {
    final AuthorizationService authorizationService = processEngine.getAuthorizationService();

    Authorization newAuthorization = authorizationService.createNewAuthorization(dto.getType());
    AuthorizationCreateDto.update(dto, newAuthorization);

    newAuthorization = authorizationService.saveAuthorization(newAuthorization);

    return getAuthorization(newAuthorization.getId()).getAuthorization(context);
  }
View Full Code Here

    list.add(createMockUser());
    return list;
  }

  public static Authorization createMockGlobalAuthorization() {
    Authorization mockAuthorization = mock(Authorization.class);

    when(mockAuthorization.getId()).thenReturn(EXAMPLE_AUTHORIZATION_ID);
    when(mockAuthorization.getAuthorizationType()).thenReturn(Authorization.AUTH_TYPE_GLOBAL);
    when(mockAuthorization.getUserId()).thenReturn(Authorization.ANY);

    when(mockAuthorization.getResourceType()).thenReturn(EXAMPLE_RESOURCE_TYPE_ID);
    when(mockAuthorization.getResourceId()).thenReturn(EXAMPLE_RESOURCE_ID);
    when(mockAuthorization.getPermissions(Permissions.values())).thenReturn(EXAMPLE_GRANT_PERMISSION_VALUES);

    return mockAuthorization;
  }
View Full Code Here

    return mockAuthorization;
  }

  public static Authorization createMockGrantAuthorization() {
    Authorization mockAuthorization = mock(Authorization.class);

    when(mockAuthorization.getId()).thenReturn(EXAMPLE_AUTHORIZATION_ID);
    when(mockAuthorization.getAuthorizationType()).thenReturn(Authorization.AUTH_TYPE_GRANT);
    when(mockAuthorization.getUserId()).thenReturn(EXAMPLE_USER_ID);

    when(mockAuthorization.getResourceType()).thenReturn(EXAMPLE_RESOURCE_TYPE_ID);
    when(mockAuthorization.getResourceId()).thenReturn(EXAMPLE_RESOURCE_ID);
    when(mockAuthorization.getPermissions(Permissions.values())).thenReturn(EXAMPLE_GRANT_PERMISSION_VALUES);

    return mockAuthorization;
  }
View Full Code Here

    return mockAuthorization;
  }

  public static Authorization createMockRevokeAuthorization() {
    Authorization mockAuthorization = mock(Authorization.class);

    when(mockAuthorization.getId()).thenReturn(EXAMPLE_AUTHORIZATION_ID);
    when(mockAuthorization.getAuthorizationType()).thenReturn(Authorization.AUTH_TYPE_REVOKE);
    when(mockAuthorization.getUserId()).thenReturn(EXAMPLE_USER_ID);

    when(mockAuthorization.getResourceType()).thenReturn(EXAMPLE_RESOURCE_TYPE_ID);
    when(mockAuthorization.getResourceId()).thenReturn(EXAMPLE_RESOURCE_ID);
    when(mockAuthorization.getPermissions(Permissions.values())).thenReturn(EXAMPLE_REVOKE_PERMISSION_VALUES);

    return mockAuthorization;
  }
View Full Code Here

    String content = response.asString();
    List<String> instances = from(content).getList("");
    Assert.assertEquals("There should be one authorization returned.", 1, instances.size());
    Assert.assertNotNull("The returned authorization should not be null.", instances.get(0));

    Authorization mockAuthorization = mockAuthorizations.get(0);

    Assert.assertEquals(mockAuthorization.getId(), from(content).getString("[0].id"));
    Assert.assertEquals(mockAuthorization.getAuthorizationType(), from(content).getInt("[0].type"));
    Assert.assertEquals(Permissions.READ.getName(), from(content).getString("[0].permissions[0]"));
    Assert.assertEquals(Permissions.UPDATE.getName(), from(content).getString("[0].permissions[1]"));
    Assert.assertEquals(mockAuthorization.getUserId(), from(content).getString("[0].userId"));
    Assert.assertEquals(mockAuthorization.getGroupId(), from(content).getString("[0].groupId"));
    Assert.assertEquals(mockAuthorization.getResourceType(), from(content).getInt("[0].resourceType"));
    Assert.assertEquals(mockAuthorization.getResourceId(), from(content).getString("[0].resourceId"));

  }
View Full Code Here

TOP

Related Classes of org.camunda.bpm.engine.authorization.Authorization

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.