Search in sources :

Example 46 with User

use of org.camunda.bpm.engine.identity.User in project camunda-bpm-platform by camunda.

the class WriteMultipleEntitiesInOneTransactionTest method testWriteMultipleEntitiesInOneTransaction.

public void testWriteMultipleEntitiesInOneTransaction() {
    // the identity service provider registered with the engine creates a user, a group, and a membership
    // in the following call:
    Assert.assertTrue(identityService.checkPassword("multipleEntities", "inOneStep"));
    User user = identityService.createUserQuery().userId("multipleEntities").singleResult();
    Assert.assertNotNull(user);
    Assert.assertEquals("multipleEntities", user.getId());
    Assert.assertEquals("{SHA}pfdzmt+49nwknTy7xhZd7ZW5suI=", user.getPassword());
    // It is expected, that the User is in exactly one Group
    List<Group> groups = this.identityService.createGroupQuery().groupMember("multipleEntities").list();
    Assert.assertEquals(1, groups.size());
    Group group = groups.get(0);
    Assert.assertEquals("multipleEntities_group", group.getId());
    // clean the Db
    identityService.deleteMembership("multipleEntities", "multipleEntities_group");
    identityService.deleteGroup("multipleEntities_group");
    identityService.deleteUser("multipleEntities");
}
Also used : Group(org.camunda.bpm.engine.identity.Group) User(org.camunda.bpm.engine.identity.User)

Example 47 with User

use of org.camunda.bpm.engine.identity.User in project camunda-bpm-platform by camunda.

the class PasswordHashingTest method useSeveralCustomEncryptors.

@Test
public void useSeveralCustomEncryptors() {
    // given three users with different hashed passwords
    processEngineConfiguration.setSaltGenerator(new MyConstantSaltGenerator("12345678910"));
    String userName1 = "Kermit";
    createUserWithEncryptor(userName1, new MyCustomPasswordEncryptor(PASSWORD, ALGORITHM_NAME));
    String userName2 = "Fozzie";
    String anotherAlgorithmName = "marvelousAlgorithm";
    createUserWithEncryptor(userName2, new MyCustomPasswordEncryptor(PASSWORD, anotherAlgorithmName));
    String userName3 = "Gonzo";
    createUserWithEncryptor(userName3, new ShaHashDigest());
    List<PasswordEncryptor> additionalEncryptorsForPasswordChecking = new LinkedList<PasswordEncryptor>();
    additionalEncryptorsForPasswordChecking.add(new MyCustomPasswordEncryptor(PASSWORD, ALGORITHM_NAME));
    additionalEncryptorsForPasswordChecking.add(new MyCustomPasswordEncryptor(PASSWORD, anotherAlgorithmName));
    PasswordEncryptor defaultEncryptor = new ShaHashDigest();
    setEncryptors(defaultEncryptor, additionalEncryptorsForPasswordChecking);
    // when
    User user1 = identityService.createUserQuery().userId(userName1).singleResult();
    User user2 = identityService.createUserQuery().userId(userName2).singleResult();
    User user3 = identityService.createUserQuery().userId(userName3).singleResult();
    // then
    assertThat(user1.getPassword(), is("{" + ALGORITHM_NAME + "}xxx"));
    assertThat(user2.getPassword(), is("{" + anotherAlgorithmName + "}xxx"));
    assertThat(user3.getPassword(), is("{SHA}n3fE9/7XOmgD3BkeJlC+JLyb/Qg="));
}
Also used : User(org.camunda.bpm.engine.identity.User) LinkedList(java.util.LinkedList)

Example 48 with User

use of org.camunda.bpm.engine.identity.User in project camunda-bpm-platform by camunda.

the class PasswordHashingTest method ensurePasswordIsCorrectlyHashedWithSHA512.

@Test
public void ensurePasswordIsCorrectlyHashedWithSHA512() {
    // given
    processEngineConfiguration.setSaltGenerator(new MyConstantSaltGenerator("12345678910"));
    User user = identityService.newUser(USER_NAME);
    user.setPassword(PASSWORD);
    identityService.saveUser(user);
    // when
    user = identityService.createUserQuery().userId(USER_NAME).singleResult();
    // then
    // obtain the expected value on the command line like so: echo -n password12345678910 | openssl dgst -binary -sha512 | openssl base64
    assertThat(user.getPassword(), is("{SHA-512}sM1U4nCzoDbdUugvJ7dJ6rLc7t1ZPPsnAbUpTqi5nXCYp7PTZCHExuzjoxLLYoUK" + "Gd637jKqT8d9tpsZs3K5+g=="));
}
Also used : User(org.camunda.bpm.engine.identity.User)

Example 49 with User

use of org.camunda.bpm.engine.identity.User in project camunda-bpm-platform by camunda.

the class PasswordHashingTest method ensurePasswordIsCorrectlyHashedWithSHA1.

@Test
public void ensurePasswordIsCorrectlyHashedWithSHA1() {
    // given
    setDefaultEncryptor(new ShaHashDigest());
    processEngineConfiguration.setSaltGenerator(new MyConstantSaltGenerator("12345678910"));
    User user = identityService.newUser(USER_NAME);
    user.setPassword(PASSWORD);
    identityService.saveUser(user);
    // when
    user = identityService.createUserQuery().userId(USER_NAME).singleResult();
    // then
    // obtain the expected value on the command line like so: echo -n password12345678910 | openssl dgst -binary -sha1 | openssl base64
    assertThat(user.getPassword(), is("{SHA}n3fE9/7XOmgD3BkeJlC+JLyb/Qg="));
}
Also used : User(org.camunda.bpm.engine.identity.User)

Example 50 with User

use of org.camunda.bpm.engine.identity.User in project camunda-bpm-platform by camunda.

the class PasswordHashingTest method createUserWithEncryptor.

protected void createUserWithEncryptor(String userName, PasswordEncryptor encryptor) {
    setEncryptors(encryptor, Collections.<PasswordEncryptor>emptyList());
    User user = identityService.newUser(userName);
    user.setPassword(PASSWORD);
    identityService.saveUser(user);
}
Also used : User(org.camunda.bpm.engine.identity.User)

Aggregations

User (org.camunda.bpm.engine.identity.User)139 Test (org.junit.Test)67 Group (org.camunda.bpm.engine.identity.Group)29 UserQuery (org.camunda.bpm.engine.identity.UserQuery)24 Authorization (org.camunda.bpm.engine.authorization.Authorization)20 AuthorizationException (org.camunda.bpm.engine.AuthorizationException)12 MissingAuthorization (org.camunda.bpm.engine.authorization.MissingAuthorization)12 Matchers.anyString (org.mockito.Matchers.anyString)11 InvalidRequestException (org.camunda.bpm.engine.rest.exception.InvalidRequestException)10 ArrayList (java.util.ArrayList)9 IdentityService (org.camunda.bpm.engine.IdentityService)8 Tenant (org.camunda.bpm.engine.identity.Tenant)8 ProcessEngineException (org.camunda.bpm.engine.ProcessEngineException)6 Task (org.camunda.bpm.engine.task.Task)6 Date (java.util.Date)5 HashMap (java.util.HashMap)5 GroupQuery (org.camunda.bpm.engine.identity.GroupQuery)5 Authentication (org.camunda.bpm.engine.impl.identity.Authentication)5 UserCredentialsDto (org.camunda.bpm.engine.rest.dto.identity.UserCredentialsDto)5 UserDto (org.camunda.bpm.engine.rest.dto.identity.UserDto)5