Java Code Examples for org.camunda.bpm.engine.IdentityService#saveUser()

The following examples show how to use org.camunda.bpm.engine.IdentityService#saveUser() . 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: UserRestServiceImpl.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
public void createUser(UserDto userDto) {
  final IdentityService identityService = getIdentityService();

  if(identityService.isReadOnly()) {
    throw new InvalidRequestException(Status.FORBIDDEN, "Identity service implementation is read-only.");
  }

  UserProfileDto profile = userDto.getProfile();
  if(profile == null || profile.getId() == null) {
    throw new InvalidRequestException(Status.BAD_REQUEST, "request object must provide profile information with valid id.");
  }

  User newUser = identityService.newUser(profile.getId());
  profile.update(newUser);

  if(userDto.getCredentials() != null) {
    newUser.setPassword(userDto.getCredentials().getPassword());
  }

  identityService.saveUser(newUser);

}
 
Example 2
Source File: DeployUserWithoutSaltForPasswordHashingScenario.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
@DescribesScenario("initUser")
@Times(1)
public static ScenarioSetup initUser() {
  return new ScenarioSetup() {
    public void execute(ProcessEngine engine, String scenarioName) {
      // given
      IdentityService identityService = engine.getIdentityService();
      User user = identityService.newUser(USER_NAME);
      user.setPassword(USER_PWD);

      // when
      identityService.saveUser(user);

    }
  };
}
 
Example 3
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 4
Source File: PurgeDatabaseTest.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
private void createAuthenticationData() {
  IdentityService identityService = engineRule.getIdentityService();
  Group group = identityService.newGroup("group");
  identityService.saveGroup(group);
  User user = identityService.newUser("user");
  User user2 = identityService.newUser("user2");
  identityService.saveUser(user);
  identityService.saveUser(user2);
  Tenant tenant = identityService.newTenant("tenant");
  identityService.saveTenant(tenant);
  Tenant tenant2 = identityService.newTenant("tenant2");
  identityService.saveTenant(tenant2);
  identityService.createMembership("user", "group");
  identityService.createTenantUserMembership("tenant", "user");
  identityService.createTenantUserMembership("tenant2", "user2");


  Resource resource1 = TestResource.RESOURCE1;
  // create global authorization which grants all permissions to all users (on resource1):
  AuthorizationService authorizationService = engineRule.getAuthorizationService();
  Authorization globalAuth = authorizationService.createNewAuthorization(AUTH_TYPE_GLOBAL);
  globalAuth.setResource(resource1);
  globalAuth.setResourceId(ANY);
  globalAuth.addPermission(TestPermissions.ALL);
  authorizationService.saveAuthorization(globalAuth);

  //grant user read auth on resource2
  Resource resource2 = TestResource.RESOURCE2;
  Authorization userGrant = authorizationService.createNewAuthorization(AUTH_TYPE_GRANT);
  userGrant.setUserId("user");
  userGrant.setResource(resource2);
  userGrant.setResourceId(ANY);
  userGrant.addPermission(TestPermissions.READ);
  authorizationService.saveAuthorization(userGrant);

  identityService.setAuthenticatedUserId("user");
}
 
Example 5
Source File: UserLockExpTimeScenario.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
@DescribesScenario("initUserLockExpirationTime")
@Times(1)
public static ScenarioSetup initUserLockExpirationTime() {
  return new ScenarioSetup() {
    @Override
    public void execute(ProcessEngine processEngine, String s) {

      final IdentityService identityService = processEngine.getIdentityService();

      User user = identityService.newUser(USER_ID);
      user.setPassword(PASSWORD);
      identityService.saveUser(user);

      ((ProcessEngineConfigurationImpl) processEngine.getProcessEngineConfiguration()).getCommandExecutorTxRequired().execute(new Command<Void>() {
        @Override
        public Void execute(CommandContext context) {
          IdentityInfoManager identityInfoManager = Context.getCommandContext()
            .getSession(IdentityInfoManager.class);

          UserEntity userEntity = (UserEntity) identityService.createUserQuery()
            .userId(USER_ID)
            .singleResult();

          identityInfoManager.updateUserLock(userEntity, 10, TIMESTAMP);
          return null;
        }
      });
    }
  };
}
 
Example 6
Source File: AuthorizationScenario.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
@DescribesScenario("startProcessInstance")
@Times(1)
public static ScenarioSetup startProcessInstance() {
  return new ScenarioSetup() {
    public void execute(ProcessEngine engine, String scenarioName) {
      IdentityService identityService = engine.getIdentityService();

      String userId = USER_ID + scenarioName;
      String groupid = GROUP_ID + scenarioName;
      // create an user
      User user = identityService.newUser(userId);
      identityService.saveUser(user);

      // create group
      Group group = identityService.newGroup(groupid);
      identityService.saveGroup(group);

      // create membership
      identityService.createMembership(userId, groupid);

      //create full authorization
      AuthorizationService authorizationService = engine.getAuthorizationService();

      //authorization for process definition
      Authorization authProcDef = createAuthorization(authorizationService, Permissions.ALL, Resources.PROCESS_DEFINITION, userId);
      engine.getAuthorizationService().saveAuthorization(authProcDef);

      //authorization for deployment
      Authorization authDeployment = createAuthorization(authorizationService, Permissions.ALL, Resources.DEPLOYMENT, userId);
      engine.getAuthorizationService().saveAuthorization(authDeployment);

      //authorization for process instance create
      Authorization authProcessInstance = createAuthorization(authorizationService, Permissions.CREATE, Resources.PROCESS_INSTANCE, userId);
      engine.getAuthorizationService().saveAuthorization(authProcessInstance);

      // start a process instance
      engine.getRuntimeService().startProcessInstanceByKey(PROCESS_DEF_KEY, scenarioName);
    }
  };
}
 
Example 7
Source File: CreateAdminUserConfiguration.java    From camunda-bpm-spring-boot-starter with Apache License 2.0 4 votes vote down vote up
static User createUser(final IdentityService identityService, final User adminUser) {
  User newUser = identityService.newUser(adminUser.getId());
  BeanUtils.copyProperties(adminUser, newUser);
  identityService.saveUser(newUser);
  return newUser;
}
 
Example 8
Source File: CreateAdminUserConfiguration.java    From camunda-bpm-platform with Apache License 2.0 4 votes vote down vote up
static User createUser(final IdentityService identityService, final User adminUser) {
  User newUser = identityService.newUser(adminUser.getId());
  BeanUtils.copyProperties(adminUser, newUser);
  identityService.saveUser(newUser);
  return newUser;
}