Java Code Examples for org.camunda.bpm.engine.identity.Group#setName()

The following examples show how to use org.camunda.bpm.engine.identity.Group#setName() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CorsAuthenticationTest.java    From camunda-bpm-platform with Apache License 2.0 7 votes vote down vote up
@Test
public void shouldPassAuthenticatedCorsRequest() {
  // given
  // cross origin but allowed through wildcard
  String origin = "http://other.origin";

  HttpHeaders headers = new HttpHeaders();
  headers.add(HttpHeaders.ORIGIN, origin);

  Group group = new GroupEntity("groupId");
  
  // create group
  processEngine.getIdentityService().saveGroup(new GroupEntity("groupId"));

  group.setName("updatedGroupName");

  // when
  ResponseEntity<String> response = authTestRestTemplate.exchange(CONTEXT_PATH + "/group/" + group.getId(), HttpMethod.PUT, new HttpEntity<>(group, headers),
      String.class);

  // then
  assertThat(response.getStatusCode()).isEqualTo(HttpStatus.NO_CONTENT);
  assertThat(response.getHeaders().getAccessControlAllowOrigin()).contains("*");
}
 
Example 2
Source File: TestDbIdentityServiceProviderExtension.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
@Override
public boolean checkPassword(final String userId, final String password) {

  // Create and Save a User
  final User user = super.createNewUser(userId);
  user.setPassword(password);
  super.saveUser(user);

  // Create and Save a Group
  final String groupId = userId+"_group";
  final Group group = super.createNewGroup(groupId);
  group.setName(groupId);
  super.saveGroup(group);

  // Create the corresponding Membership
  super.createMembership(userId, groupId);

  return super.checkPassword(userId, password);
}
 
Example 3
Source File: IdentityServiceTest.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
@Test
public void testGroupOptimisticLockingException() {
  Group group = identityService.newGroup("group");
  identityService.saveGroup(group);

  Group group1 = identityService.createGroupQuery().singleResult();
  Group group2 = identityService.createGroupQuery().singleResult();

  group1.setName("name one");
  identityService.saveGroup(group1);

  thrown.expect(OptimisticLockingException.class);

  group2.setName("name two");
  identityService.saveGroup(group2);
}
 
Example 4
Source File: IdentityServiceWithJdbcSimpleProcessingTest.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
@Test
public void testGroupOptimisticLockingException() {
  Group group = identityService.newGroup("group");
  identityService.saveGroup(group);

  Group group1 = identityService.createGroupQuery().singleResult();
  Group group2 = identityService.createGroupQuery().singleResult();

  group1.setName("name one");
  identityService.saveGroup(group1);

  thrown.expect(OptimisticLockingException.class);

  group2.setName("name two");
  identityService.saveGroup(group2);
}
 
Example 5
Source File: IdentityServiceUserOperationLogTest.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
@Test
public void shouldLogGroupUpdate() {
  // given
  Group newGroup = identityService.newGroup(TEST_GROUP_ID);
  identityService.saveGroup(newGroup);
  assertEquals(0, query.count());

  // when
  newGroup.setName("testName");
  identityService.setAuthenticatedUserId("userId");
  identityService.saveGroup(newGroup);
  identityService.clearAuthentication();

  // then
  assertLog(UserOperationLogEntry.OPERATION_TYPE_UPDATE, EntityTypes.GROUP, null, TEST_GROUP_ID);
}
 
Example 6
Source File: CreateAdminUserConfiguration.java    From camunda-bpm-spring-boot-starter with Apache License 2.0 5 votes vote down vote up
@Override
public void postProcessEngineBuild(final ProcessEngine processEngine) {
  requireNonNull(adminUser);

  final IdentityService identityService = processEngine.getIdentityService();
  final AuthorizationService authorizationService = processEngine.getAuthorizationService();

  if (userAlreadyExists(identityService, adminUser)) {
    return;
  }

  createUser(identityService, adminUser);

  // create group
  if (identityService.createGroupQuery().groupId(CAMUNDA_ADMIN).count() == 0) {
    Group camundaAdminGroup = identityService.newGroup(CAMUNDA_ADMIN);
    camundaAdminGroup.setName("camunda BPM Administrators");
    camundaAdminGroup.setType(Groups.GROUP_TYPE_SYSTEM);
    identityService.saveGroup(camundaAdminGroup);
  }

  // create ADMIN authorizations on all built-in resources
  for (Resource resource : Resources.values()) {
    if (authorizationService.createAuthorizationQuery().groupIdIn(CAMUNDA_ADMIN).resourceType(resource).resourceId(ANY).count() == 0) {
      AuthorizationEntity userAdminAuth = new AuthorizationEntity(AUTH_TYPE_GRANT);
      userAdminAuth.setGroupId(CAMUNDA_ADMIN);
      userAdminAuth.setResource(resource);
      userAdminAuth.setResourceId(ANY);
      userAdminAuth.addPermission(ALL);
      authorizationService.saveAuthorization(userAdminAuth);
    }
  }

  identityService.createMembership(adminUser.getId(), CAMUNDA_ADMIN);
  LOG.creatingInitialAdminUser(adminUser);
}
 
Example 7
Source File: DemoDataGenerator.java    From camunda-bpm-elasticsearch with Apache License 2.0 5 votes vote down vote up
public void afterPropertiesSet() throws Exception {

    System.out.println("Generating demo data");

    scheduleInstanceStart();

    // ensure admin user exists
    IdentityService identityService = processEngine.getIdentityService();
    User user = identityService.createUserQuery().userId("demo").singleResult();
    if(user == null) {
      User newUser = identityService.newUser("demo");
      newUser.setPassword("demo");
      identityService.saveUser(newUser);
      System.out.println("Created used 'demo', password 'demo'");
      AuthorizationService authorizationService = processEngine.getAuthorizationService();

      // create group
      if(identityService.createGroupQuery().groupId(Groups.CAMUNDA_ADMIN).count() == 0) {
        Group camundaAdminGroup = identityService.newGroup(Groups.CAMUNDA_ADMIN);
        camundaAdminGroup.setName("camunda BPM Administrators");
        camundaAdminGroup.setType(Groups.GROUP_TYPE_SYSTEM);
        identityService.saveGroup(camundaAdminGroup);
      }

      // create ADMIN authorizations on all built-in resources
      for (Resource resource : Resources.values()) {
        if(authorizationService.createAuthorizationQuery().groupIdIn(Groups.CAMUNDA_ADMIN).resourceType(resource).resourceId(ANY).count() == 0) {
          AuthorizationEntity userAdminAuth = new AuthorizationEntity(AUTH_TYPE_GRANT);
          userAdminAuth.setGroupId(Groups.CAMUNDA_ADMIN);
          userAdminAuth.setResource(resource);
          userAdminAuth.setResourceId(ANY);
          userAdminAuth.addPermission(ALL);
          authorizationService.saveAuthorization(userAdminAuth);
        }
      }

      processEngine.getIdentityService()
      .createMembership("demo", Groups.CAMUNDA_ADMIN);
    }
  }
 
Example 8
Source File: CreateAdminUserConfiguration.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
@Override
public void postProcessEngineBuild(final ProcessEngine processEngine) {
  requireNonNull(adminUser);

  final IdentityService identityService = processEngine.getIdentityService();
  final AuthorizationService authorizationService = processEngine.getAuthorizationService();

  if (userAlreadyExists(identityService, adminUser)) {
    return;
  }

  createUser(identityService, adminUser);

  // create group
  if (identityService.createGroupQuery().groupId(CAMUNDA_ADMIN).count() == 0) {
    Group camundaAdminGroup = identityService.newGroup(CAMUNDA_ADMIN);
    camundaAdminGroup.setName("camunda BPM Administrators");
    camundaAdminGroup.setType(Groups.GROUP_TYPE_SYSTEM);
    identityService.saveGroup(camundaAdminGroup);
  }

  // create ADMIN authorizations on all built-in resources
  for (Resource resource : Resources.values()) {
    if (authorizationService.createAuthorizationQuery().groupIdIn(CAMUNDA_ADMIN).resourceType(resource).resourceId(ANY).count() == 0) {
      AuthorizationEntity userAdminAuth = new AuthorizationEntity(AUTH_TYPE_GRANT);
      userAdminAuth.setGroupId(CAMUNDA_ADMIN);
      userAdminAuth.setResource(resource);
      userAdminAuth.setResourceId(ANY);
      userAdminAuth.addPermission(ALL);
      authorizationService.saveAuthorization(userAdminAuth);
    }
  }

  identityService.createMembership(adminUser.getId(), CAMUNDA_ADMIN);
  LOG.creatingInitialAdminUser(adminUser);
}
 
Example 9
Source File: GroupQueryTest.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
private Group createGroup(String id, String name, String type) {
  Group group = identityService.newGroup(id);
  group.setName(name);
  group.setType(type);
  identityService.saveGroup(group);
  return group;
}
 
Example 10
Source File: IdentityServiceTest.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
@Test
public void testUpdateGroup() {
  Group group = identityService.newGroup("sales");
  group.setName("Sales");
  identityService.saveGroup(group);

  group = identityService.createGroupQuery().groupId("sales").singleResult();
  group.setName("Updated");
  identityService.saveGroup(group);

  group = identityService.createGroupQuery().groupId("sales").singleResult();
  assertEquals("Updated", group.getName());

  identityService.deleteGroup(group.getId());
}
 
Example 11
Source File: IdentityServiceTest.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
@Test
public void testGroup() {
  Group group = identityService.newGroup("sales");
  group.setName("Sales division");
  identityService.saveGroup(group);

  group = identityService.createGroupQuery().groupId("sales").singleResult();
  assertEquals("sales", group.getId());
  assertEquals("Sales division", group.getName());

  identityService.deleteGroup("sales");
}
 
Example 12
Source File: IdentityServiceAuthorizationsTest.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
public void testGroupUpdateAuthorizations() {

    // crate group while still in god-mode:
    Group group1 = identityService.newGroup("group1");
    identityService.saveGroup(group1);

    // create global auth
    Authorization basePerms = authorizationService.createNewAuthorization(AUTH_TYPE_GLOBAL);
    basePerms.setResource(GROUP);
    basePerms.setResourceId(ANY);
    basePerms.addPermission(ALL);
    basePerms.removePermission(UPDATE); // revoke update
    authorizationService.saveAuthorization(basePerms);

    // turn on authorization
    processEngineConfiguration.setAuthorizationEnabled(true);
    identityService.setAuthenticatedUserId(jonny2);

    // fetch user:
    group1 = identityService.createGroupQuery().singleResult();
    group1.setName("Group 1");

    try {
      identityService.saveGroup(group1);
      fail("exception expected");

    } catch (AuthorizationException e) {
      assertEquals(1, e.getMissingAuthorizations().size());
      MissingAuthorization info = e.getMissingAuthorizations().get(0);
      assertEquals(jonny2, e.getUserId());
      assertExceptionInfo(UPDATE.getName(), GROUP.resourceName(), "group1", info);
    }

    // but I can create a new group:
    Group group2 = identityService.newGroup("group2");
    identityService.saveGroup(group2);

  }
 
Example 13
Source File: Application.java    From camunda-spring-boot-amqp-microservice-cloud-example with Apache License 2.0 4 votes vote down vote up
public static void createDefaultUser(ProcessEngine engine) {
  // and add default user to Camunda to be ready-to-go
  if (engine.getIdentityService().createUserQuery().userId("demo").count() == 0) {
    User user = engine.getIdentityService().newUser("demo");
    user.setFirstName("Demo");
    user.setLastName("Demo");
    user.setPassword("demo");
    user.setEmail("[email protected]");
    engine.getIdentityService().saveUser(user);

    Group group = engine.getIdentityService().newGroup(Groups.CAMUNDA_ADMIN);
    group.setName("Administrators");
    group.setType(Groups.GROUP_TYPE_SYSTEM);
    engine.getIdentityService().saveGroup(group);

    for (Resource resource : Resources.values()) {
      Authorization auth = engine.getAuthorizationService().createNewAuthorization(AUTH_TYPE_GRANT);
      auth.setGroupId(Groups.CAMUNDA_ADMIN);
      auth.addPermission(ALL);
      auth.setResourceId(ANY);
      auth.setResource(resource);
      engine.getAuthorizationService().saveAuthorization(auth);
    }

    engine.getIdentityService().createMembership("demo", Groups.CAMUNDA_ADMIN);
  }

  // create default "all tasks" filter
  if (engine.getFilterService().createFilterQuery().filterName("Alle").count() == 0) {

    Map<String, Object> filterProperties = new HashMap<String, Object>();
    filterProperties.put("description", "Alle Aufgaben");
    filterProperties.put("priority", 10);

    Filter filter = engine.getFilterService().newTaskFilter() //
        .setName("Alle") //
        .setProperties(filterProperties)//
        .setOwner("demo")//
        .setQuery(engine.getTaskService().createTaskQuery());
    engine.getFilterService().saveFilter(filter);

    // and authorize demo user for it
    if (engine.getAuthorizationService().createAuthorizationQuery().resourceType(FILTER).resourceId(filter.getId()) //
        .userIdIn("demo").count() == 0) {
      Authorization managementGroupFilterRead = engine.getAuthorizationService().createNewAuthorization(Authorization.AUTH_TYPE_GRANT);
      managementGroupFilterRead.setResource(FILTER);
      managementGroupFilterRead.setResourceId(filter.getId());
      managementGroupFilterRead.addPermission(ALL);
      managementGroupFilterRead.setUserId("demo");
      engine.getAuthorizationService().saveAuthorization(managementGroupFilterRead);
    }

  }
}
 
Example 14
Source File: GroupDto.java    From camunda-bpm-platform with Apache License 2.0 4 votes vote down vote up
public void update(Group dbGroup) {
  dbGroup.setId(id);
  dbGroup.setName(name);
  dbGroup.setType(type);
}