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

The following examples show how to use org.camunda.bpm.engine.identity.User#getId() . 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: RepositoryByteArrayTest.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
@Test
public void testUserPictureBinary() {
  // when
  Date fixedDate = new Date();
  ClockUtil.setCurrentTime(fixedDate);
  User user = identityService.newUser(USER_ID);
  identityService.saveUser(user);
  String userId = user.getId();

  Picture picture = new Picture("niceface".getBytes(), "image/string");
  identityService.setUserPicture(userId, picture);
  String userInfo = identityService.getUserInfo(USER_ID, "picture");

  ByteArrayEntity byteArrayEntity = configuration.getCommandExecutorTxRequired()
      .execute(new GetByteArrayCommand(userInfo));

  // then
  assertNotNull(byteArrayEntity);
  assertEquals(fixedDate.toString(), byteArrayEntity.getCreateTime().toString());
  assertEquals(REPOSITORY.getValue(), byteArrayEntity.getType());
}
 
Example 2
Source File: DefaultAuthorizationProvider.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
public AuthorizationEntity[] newUser(User user) {
  // create an authorization which gives the user all permissions on himself:
  String userId = user.getId();

  ensureValidIndividualResourceId("Cannot create default authorization for user " + userId,
      userId);
  AuthorizationEntity resourceOwnerAuthorization = createGrantAuthorization(userId, null, USER, userId, ALL);

  return new AuthorizationEntity[]{ resourceOwnerAuthorization };
}
 
Example 3
Source File: IdentityServiceTest.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
@Test
public void testUserPicture() {
  // First, create a new user
  User user = identityService.newUser("johndoe");
  identityService.saveUser(user);
  String userId = user.getId();

  Picture picture = new Picture("niceface".getBytes(), "image/string");
  identityService.setUserPicture(userId, picture);

  picture = identityService.getUserPicture(userId);

  // Fetch and update the user
  user = identityService.createUserQuery().userId("johndoe").singleResult();
  assertTrue("byte arrays differ", Arrays.equals("niceface".getBytes(), picture.getBytes()));
  assertEquals("image/string", picture.getMimeType());

  identityService.deleteUserPicture("johndoe");
  // this is ignored
  identityService.deleteUserPicture("someone-else-we-dont-know");

  // picture does not exist
  picture = identityService.getUserPicture("johndoe");
  assertNull(picture);

  // add new picture
  picture = new Picture("niceface".getBytes(), "image/string");
  identityService.setUserPicture(userId, picture);

  // makes the picture go away
  identityService.deleteUser(user.getId());
}
 
Example 4
Source File: IdentityServiceAuthorizationsTest.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
public void testTenantAuthorizationAfterDeleteUser() {
  // given jonny2 who is allowed to do user operations
  User jonny = identityService.newUser(jonny2);
  identityService.saveUser(jonny);

  grantPermissions();

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

  // create user
  User jonny1 = identityService.newUser("jonny1");
  identityService.saveUser(jonny1);
  String jonny1Id = jonny1.getId();

  // and tenant
  String tenant1 = "tenant1";
  Tenant tenant = identityService.newTenant(tenant1);
  identityService.saveTenant(tenant);
  identityService.createTenantUserMembership(tenant1, jonny1Id);

  // assume
  TenantQuery query = identityService.createTenantQuery().userMember(jonny1Id);
  assertThat(query.count(), is(1L));

  // when
  identityService.deleteUser(jonny1Id);

  // turn off authorization
  processEngineConfiguration.setAuthorizationEnabled(false);

  // then
  assertThat(query.count(), is(0L));
  assertThat(authorizationService.createAuthorizationQuery().resourceType(TENANT).userIdIn(jonny1Id).count(), is(0L));
}
 
Example 5
Source File: UserProfileDto.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
public static UserProfileDto fromUser(User user) {
  UserProfileDto result = new UserProfileDto();
  result.id = user.getId();
  result.firstName = user.getFirstName();
  result.lastName = user.getLastName();
  result.email = user.getEmail();
  return result;
}
 
Example 6
Source File: HalUser.java    From camunda-bpm-platform with Apache License 2.0 3 votes vote down vote up
public static HalUser fromUser(User user) {

    HalUser halUser = new HalUser();

    halUser.id = user.getId();
    halUser.firstName = user.getFirstName();
    halUser.lastName = user.getLastName();
    halUser.email = user.getEmail();

    halUser.linker.createLink(REL_SELF, user.getId());

    return halUser;

  }