Java Code Examples for org.camunda.bpm.engine.identity.User#setFirstName()

The following examples show how to use org.camunda.bpm.engine.identity.User#setFirstName() . 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: IdentityServiceTest.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
@Test
public void testUpdateUser() {
  // First, create a new user
  User user = identityService.newUser("johndoe");
  user.setFirstName("John");
  user.setLastName("Doe");
  user.setEmail("[email protected]");
  user.setPassword("s3cret");
  identityService.saveUser(user);

  // Fetch and update the user
  user = identityService.createUserQuery().userId("johndoe").singleResult();
  user.setEmail("[email protected]");
  user.setFirstName("Jane");
  user.setLastName("Donnel");
  identityService.saveUser(user);

  user = identityService.createUserQuery().userId("johndoe").singleResult();
  assertEquals("Jane", user.getFirstName());
  assertEquals("Donnel", user.getLastName());
  assertEquals("[email protected]", user.getEmail());
  assertTrue(identityService.checkPassword("johndoe", "s3cret"));

  identityService.deleteUser(user.getId());
}
 
Example 2
Source File: IdentityServiceTest.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
@Test
public void testUserOptimisticLockingException() {
  User user = identityService.newUser("kermit");
  identityService.saveUser(user);

  User user1 = identityService.createUserQuery().singleResult();
  User user2 = identityService.createUserQuery().singleResult();

  user1.setFirstName("name one");
  identityService.saveUser(user1);

  thrown.expect(OptimisticLockingException.class);

  user2.setFirstName("name two");
  identityService.saveUser(user2);
}
 
Example 3
Source File: IdentityServiceTest.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
@Test
public void testUser() {
  User user = identityService.newUser("johndoe");
  user.setFirstName("John");
  user.setLastName("Doe");
  user.setEmail("[email protected]");
  identityService.saveUser(user);

  user = identityService.createUserQuery().userId("johndoe").singleResult();
  assertEquals("johndoe", user.getId());
  assertEquals("John", user.getFirstName());
  assertEquals("Doe", user.getLastName());
  assertEquals("[email protected]", user.getEmail());

  identityService.deleteUser("johndoe");
}
 
Example 4
Source File: IdentityServiceWithJdbcSimpleProcessingTest.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
@Test
public void testUserOptimisticLockingException() {
  User user = identityService.newUser("kermit");
  identityService.saveUser(user);

  User user1 = identityService.createUserQuery().singleResult();
  User user2 = identityService.createUserQuery().singleResult();

  user1.setFirstName("name one");
  identityService.saveUser(user1);

  thrown.expect(OptimisticLockingException.class);

  user2.setFirstName("name two");
  identityService.saveUser(user2);
}
 
Example 5
Source File: DefaultUserLifecycleBean.java    From Showcase with Apache License 2.0 5 votes vote down vote up
private User createDefaultUser(String username, String password) {
    User user = identityService.newUser(username);
    user.setPassword(password);
    user.setFirstName("Educama");
    user.setLastName("User");
    identityService.saveUser(user);

    return user;
}
 
Example 6
Source File: UserQueryTest.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
private User createUser(String id, String firstName, String lastName, String email) {
  User user = identityService.newUser(id);
  user.setFirstName(firstName);
  user.setLastName(lastName);
  user.setEmail(email);
  identityService.saveUser(user);
  return user;
}
 
Example 7
Source File: IdentityServiceAuthorizationsTest.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
public void testUserUpdateAuthorizations() {

    // crate user while still in god-mode:
    User jonny1 = identityService.newUser("jonny1");
    identityService.saveUser(jonny1);

    // create global auth
    Authorization basePerms = authorizationService.createNewAuthorization(AUTH_TYPE_GLOBAL);
    basePerms.setResource(USER);
    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:
    jonny1 = identityService.createUserQuery().singleResult();
    jonny1.setFirstName("Jonny");

    try {
      identityService.saveUser(jonny1);
      fail("exception expected");

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

    // but I can create a new user:
    User jonny3 = identityService.newUser("jonny3");
    identityService.saveUser(jonny3);

  }
 
Example 8
Source File: DefaultPasswordPolicyTest.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
@Test
public void shouldUpdateUserDetailsWithoutPolicyCheck() {
  // given
  // first, create a new user
  User user = identityService.newUser("johndoe");
  user.setFirstName("John");
  user.setLastName("Doe");
  user.setEmail("[email protected]");
  user.setPassword("Passw0rds!");
  identityService.saveUser(user);

  // when
  // fetch and update the user
  user = identityService.createUserQuery().userId("johndoe").singleResult();
  user.setEmail("[email protected]");
  user.setFirstName("Jane");
  user.setLastName("Donnel");
  identityService.saveUser(user);

  // then
  user = identityService.createUserQuery().userId("johndoe").singleResult();
  assertThat(user.getFirstName(), is("Jane"));
  assertThat(user.getLastName(), is("Donnel"));
  assertThat(user.getEmail(), is("[email protected]"));
  assertThat(identityService.checkPassword("johndoe", "Passw0rds!"), is(true));

  identityService.deleteUser(user.getId());
}
 
Example 9
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 10
Source File: UserProfileDto.java    From camunda-bpm-platform with Apache License 2.0 4 votes vote down vote up
public void update(User dbUser) {  
  dbUser.setId(getId());
  dbUser.setFirstName(getFirstName());
  dbUser.setLastName(getLastName());
  dbUser.setEmail(getEmail());
}