org.camunda.bpm.engine.authorization.Authorization.setPermissions()方法的使用及代码示例

x33g5p2x  于2022-01-17 转载在 其他  
字(12.5k)|赞(0)|评价(0)|浏览(124)

本文整理了Java中org.camunda.bpm.engine.authorization.Authorization.setPermissions()方法的一些代码示例,展示了Authorization.setPermissions()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Authorization.setPermissions()方法的具体详情如下:
包路径:org.camunda.bpm.engine.authorization.Authorization
类名称:Authorization
方法名:setPermissions

Authorization.setPermissions介绍

[英]Sets the permissions to the provided value. Replaces all permissions. The effect of this method depends on the type of this authorization:

  • For #AUTH_TYPE_GLOBAL: all provided permissions are granted.
  • For #AUTH_TYPE_GRANT: all provided permissions are granted.
  • For #AUTH_TYPE_REVOKE: all provided permissions are revoked.
    [中]将权限设置为提供的值。替换所有权限。此方法的效果取决于此授权的类型:
    *对于#AUTH_TYPE_GLOBAL:授予所有提供的权限。
    *对于#AUTH_TYPE_GRANT#:授予所有提供的权限。
    *对于#AUTH_TYPE_REVOKE:所有提供的权限都将被吊销。

代码示例

代码示例来源:origin: camunda/camunda-bpm-platform

public Authorization instantiate(AuthorizationService authorizationService, Map<String, String> replacements) {
 Authorization authorization = authorizationService.createNewAuthorization(type);
 // TODO: group id is missing
 authorization.setResource(resource);
 if (replacements.containsKey(resourceId)) {
  authorization.setResourceId(replacements.get(resourceId));
 }
 else {
  authorization.setResourceId(resourceId);
 }
 authorization.setUserId(userId);
 authorization.setPermissions(permissions);
 return authorization;
}

代码示例来源:origin: camunda/camunda-bpm-platform

@Test
public void testCreateGrantAuthorization() {
 Authorization authorization = MockProvider.createMockGrantAuthorization();
 when(authorizationServiceMock.createNewAuthorization(Authorization.AUTH_TYPE_GRANT)).thenReturn(authorization);
 when(authorizationServiceMock.saveAuthorization(authorization)).thenReturn(authorization);
 AuthorizationQuery authorizationQuery = mock(AuthorizationQuery.class);
 when(authorizationServiceMock.createAuthorizationQuery()).thenReturn(authorizationQuery);
 when(authorizationQuery.authorizationId(MockProvider.EXAMPLE_AUTHORIZATION_ID)).thenReturn(authorizationQuery);
 when(authorizationQuery.singleResult()).thenReturn(authorization);
 AuthorizationDto dto = AuthorizationDto.fromAuthorization(authorization);
 given()
   .body(dto).contentType(ContentType.JSON)
 .then().expect()
   .statusCode(Status.OK.getStatusCode())
 .when()
   .post(AUTH_CREATE_PATH);
 verify(authorizationServiceMock).createNewAuthorization(Authorization.AUTH_TYPE_GRANT);
 verify(authorization, times(2)).setUserId(authorization.getUserId());
 verify(authorization, times(4)).setResourceType(authorization.getAuthorizationType());
 verify(authorization, times(2)).setResourceId(authorization.getResourceId());
 verify(authorization, times(2)).setPermissions(authorization.getPermissions(Permissions.values()));
 verify(authorizationServiceMock).saveAuthorization(authorization);
}

代码示例来源:origin: camunda/camunda-bpm-platform

@Test
public void testCreateRevokeAuthorization() {
 Authorization authorization = MockProvider.createMockRevokeAuthorization();
 when(authorizationServiceMock.createNewAuthorization(Authorization.AUTH_TYPE_REVOKE)).thenReturn(authorization);
 when(authorizationServiceMock.saveAuthorization(authorization)).thenReturn(authorization);
 AuthorizationQuery authorizationQuery = mock(AuthorizationQuery.class);
 when(authorizationServiceMock.createAuthorizationQuery()).thenReturn(authorizationQuery);
 when(authorizationQuery.authorizationId(MockProvider.EXAMPLE_AUTHORIZATION_ID)).thenReturn(authorizationQuery);
 when(authorizationQuery.singleResult()).thenReturn(authorization);
 AuthorizationDto dto = AuthorizationDto.fromAuthorization(authorization);
 given()
   .body(dto).contentType(ContentType.JSON)
 .then().expect()
   .statusCode(Status.OK.getStatusCode())
 .when()
   .post(AUTH_CREATE_PATH);
 verify(authorizationServiceMock).createNewAuthorization(Authorization.AUTH_TYPE_REVOKE);
 verify(authorization, times(2)).setUserId(authorization.getUserId());
 verify(authorization, times(4)).setResourceType(authorization.getAuthorizationType());
 verify(authorization, times(2)).setResourceId(authorization.getResourceId());
 verify(authorization, times(2)).setPermissions(authorization.getPermissions(Permissions.values()));
 verify(authorizationServiceMock).saveAuthorization(authorization);
}

代码示例来源:origin: camunda/camunda-bpm-platform

@Test
public void testCreateGlobalAuthorization() {
 Authorization authorization = MockProvider.createMockGlobalAuthorization();
 when(authorizationServiceMock.createNewAuthorization(Authorization.AUTH_TYPE_GLOBAL)).thenReturn(authorization);
 when(authorizationServiceMock.saveAuthorization(authorization)).thenReturn(authorization);
 AuthorizationQuery authorizationQuery = mock(AuthorizationQuery.class);
 when(authorizationServiceMock.createAuthorizationQuery()).thenReturn(authorizationQuery);
 when(authorizationQuery.authorizationId(MockProvider.EXAMPLE_AUTHORIZATION_ID)).thenReturn(authorizationQuery);
 when(authorizationQuery.singleResult()).thenReturn(authorization);
 AuthorizationDto dto = AuthorizationDto.fromAuthorization(authorization);
 given()
   .body(dto).contentType(ContentType.JSON)
 .then().expect()
   .statusCode(Status.OK.getStatusCode())
 .when()
   .post(AUTH_CREATE_PATH);
 verify(authorizationServiceMock).createNewAuthorization(Authorization.AUTH_TYPE_GLOBAL);
 verify(authorization).setUserId(Authorization.ANY);
 verify(authorization, times(4)).setResourceType(authorization.getAuthorizationType());
 verify(authorization, times(2)).setResourceId(authorization.getResourceId());
 verify(authorization, times(2)).setPermissions(authorization.getPermissions(Permissions.values()));
 verify(authorizationServiceMock).saveAuthorization(authorization);
}

代码示例来源:origin: camunda/camunda-bpm-platform

public static void update(AuthorizationCreateDto dto, Authorization dbAuthorization) {
 
 dbAuthorization.setGroupId(dto.getGroupId());
 dbAuthorization.setUserId(dto.getUserId());
 dbAuthorization.setResourceType(dto.getResourceType());
 dbAuthorization.setResourceId(dto.getResourceId());
 dbAuthorization.setPermissions(PermissionConverter.getPermissionsForNames(dto.getPermissions(), dto.getResourceType()));
 
}

代码示例来源:origin: camunda/camunda-bpm-platform

public static void update(AuthorizationCreateDto dto, Authorization dbAuthorization) {
 
 dbAuthorization.setGroupId(dto.getGroupId());
 dbAuthorization.setUserId(dto.getUserId());
 dbAuthorization.setResourceType(dto.getResourceType());
 dbAuthorization.setResourceId(dto.getResourceId());
 dbAuthorization.setPermissions(PermissionConverter.getPermissionsForNames(dto.getPermissions(), dto.getResourceType()));
 
}

代码示例来源:origin: camunda/camunda-bpm-platform

public static void update(AuthorizationDto dto, Authorization dbAuthorization) {
 dbAuthorization.setGroupId(dto.getGroupId());
 dbAuthorization.setUserId(dto.getUserId());
 dbAuthorization.setResourceId(dto.getResourceId());
 // update optional fields
 if(dto.getResourceType() != null) {
  dbAuthorization.setResourceType(dto.getResourceType());
 }
 if(dto.getPermissions() != null) {
  dbAuthorization.setPermissions(PermissionConverter.getPermissionsForNames(dto.getPermissions(), dto.getResourceType()));
 }
}

代码示例来源:origin: camunda/camunda-bpm-platform

public static void update(AuthorizationDto dto, Authorization dbAuthorization) {
 dbAuthorization.setGroupId(dto.getGroupId());
 dbAuthorization.setUserId(dto.getUserId());
 dbAuthorization.setResourceId(dto.getResourceId());
 // update optional fields
 if(dto.getResourceType() != null) {
  dbAuthorization.setResourceType(dto.getResourceType());
 }
 if(dto.getPermissions() != null) {
  dbAuthorization.setPermissions(PermissionConverter.getPermissionsForNames(dto.getPermissions(), dto.getResourceType()));
 }
}

代码示例来源:origin: camunda/camunda-bpm-platform

private void createAuthorizations(ProcessEngine processEngine1) {
 Authorization newAuthorization = processEngine1.getAuthorizationService().createNewAuthorization(Authorization.AUTH_TYPE_GLOBAL);
 newAuthorization.setResource(Resources.PROCESS_INSTANCE);
 newAuthorization.setResourceId("*");
 newAuthorization.setPermissions(new Permission[] { Permissions.CREATE });
 processEngine1.getAuthorizationService().saveAuthorization(newAuthorization);
 newAuthorization = processEngine1.getAuthorizationService().createNewAuthorization(Authorization.AUTH_TYPE_GLOBAL);
 newAuthorization.setResource(Resources.PROCESS_DEFINITION);
 newAuthorization.setResourceId("*");
 newAuthorization.setPermissions(new Permission[] { Permissions.CREATE_INSTANCE });
 processEngine1.getAuthorizationService().saveAuthorization(newAuthorization);
 newAuthorization = processEngine1.getAuthorizationService().createNewAuthorization(Authorization.AUTH_TYPE_GLOBAL);
 newAuthorization.setResource(Resources.TASK);
 newAuthorization.setResourceId("*");
 newAuthorization.setPermissions(new Permission[] { Permissions.READ, Permissions.TASK_WORK });
 processEngine1.getAuthorizationService().saveAuthorization(newAuthorization);
}

代码示例来源:origin: camunda/camunda-bpm-platform

public void testSaveAuthorizationSetPermissionsWithInvalidResource() throws Exception {
 // given
 Authorization authorization = authorizationService.createNewAuthorization(AUTH_TYPE_GRANT);
 authorization.setUserId("userId");
 authorization.setPermissions(new BatchPermissions[] { BatchPermissions.CREATE_BATCH_MIGRATE_PROCESS_INSTANCES });
 authorization.setResource(Resources.PROCESS_INSTANCE);
 authorization.setResourceId(ANY);
 processEngineConfiguration.setAuthorizationEnabled(true);
 try {
  // when
  authorizationService.saveAuthorization(authorization);
  fail("expected exception");
 } catch (BadUserRequestException e) {
  // then
  assertTrue(e.getMessage().contains("The resource type with id:'8' is not valid for 'CREATE_BATCH_MIGRATE_PROCESS_INSTANCES' permission."));
 }
 // given
 authorization = authorizationService.createNewAuthorization(AUTH_TYPE_GRANT);
 authorization.setUserId("userId");
 authorization.setPermissions(new Permissions[] { Permissions.CREATE, Permissions.ACCESS });
 authorization.setResource(Resources.PROCESS_INSTANCE);
 try {
  // when
  authorizationService.saveAuthorization(authorization);
  fail("expected exception");
 } catch (BadUserRequestException e) {
  // then
  assertTrue(e.getMessage().contains("The resource type with id:'8' is not valid for 'ACCESS' permission."));
 }
}

代码示例来源:origin: camunda/camunda-bpm-platform

public void testSaveAuthorizationSetPermissionsWithValidResource() throws Exception {
 // given
 Authorization authorization = authorizationService.createNewAuthorization(AUTH_TYPE_GRANT);
 authorization.setUserId("userId");
 authorization.addPermission(Permissions.ACCESS);
 // 'ACCESS' is not allowed for Batches
 // however, it will be reset by next line, so saveAuthorization will be successful
 authorization.setPermissions(
   new BatchPermissions[] { BatchPermissions.CREATE_BATCH_MIGRATE_PROCESS_INSTANCES, BatchPermissions.CREATE_BATCH_DELETE_DECISION_INSTANCES });
 authorization.setResource(Resources.BATCH);
 authorization.setResourceId(ANY);
 processEngineConfiguration.setAuthorizationEnabled(true);
 // when
 authorizationService.saveAuthorization(authorization);
 // then
 Authorization authorizationResult = authorizationService.createAuthorizationQuery().resourceType(Resources.BATCH).singleResult();
 assertNotNull(authorizationResult);
 assertTrue(authorizationResult.isPermissionGranted(BatchPermissions.CREATE_BATCH_MIGRATE_PROCESS_INSTANCES));
 assertTrue(authorizationResult.isPermissionGranted(BatchPermissions.CREATE_BATCH_DELETE_DECISION_INSTANCES));
}

代码示例来源:origin: org.camunda.bpm/camunda-engine

public Authorization instantiate(AuthorizationService authorizationService, Map<String, String> replacements) {
 Authorization authorization = authorizationService.createNewAuthorization(type);
 // TODO: group id is missing
 authorization.setResource(resource);
 if (replacements.containsKey(resourceId)) {
  authorization.setResourceId(replacements.get(resourceId));
 }
 else {
  authorization.setResourceId(resourceId);
 }
 authorization.setUserId(userId);
 authorization.setPermissions(permissions);
 return authorization;
}

代码示例来源:origin: org.camunda.bpm/camunda-engine-rest-jaxrs2

public static void update(AuthorizationCreateDto dto, Authorization dbAuthorization) {
 
 dbAuthorization.setGroupId(dto.getGroupId());
 dbAuthorization.setUserId(dto.getUserId());
 dbAuthorization.setResourceType(dto.getResourceType());
 dbAuthorization.setResourceId(dto.getResourceId());
 dbAuthorization.setPermissions(PermissionConverter.getPermissionsForNames(dto.getPermissions()));
 
}

代码示例来源:origin: org.camunda.bpm/camunda-engine-rest-jaxrs2

public static void update(AuthorizationDto dto, Authorization dbAuthorization) {
 dbAuthorization.setGroupId(dto.getGroupId());
 dbAuthorization.setUserId(dto.getUserId());
 dbAuthorization.setResourceId(dto.getResourceId());
 // update optional fields
 if(dto.getResourceType() != null) {
  dbAuthorization.setResourceType(dto.getResourceType());
 }
 if(dto.getPermissions() != null) {
  dbAuthorization.setPermissions(PermissionConverter.getPermissionsForNames(dto.getPermissions()));
 }
}

相关文章