Java Code Examples for org.activiti.engine.identity.User#setPassword()

The following examples show how to use org.activiti.engine.identity.User#setPassword() . 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: IdentityController.java    From activiti-in-action-codes with Apache License 2.0 6 votes vote down vote up
/**
 * 保存User
 *
 * @param redirectAttributes
 * @return
 */
@RequestMapping(value = "user/save", method = RequestMethod.POST)
public String saveUser(@RequestParam("userId") String userId,
                       @RequestParam("firstName") String firstName,
                       @RequestParam("lastName") String lastName,
                       @RequestParam(value = "password", required = false) String password,
                       @RequestParam(value = "email", required = false) String email,
                       RedirectAttributes redirectAttributes) {
    User user = identityService.createUserQuery().userId(userId).singleResult();
    if (user == null) {
        user = identityService.newUser(userId);
    }
    user.setFirstName(firstName);
    user.setLastName(lastName);
    user.setEmail(email);
    if (StringUtils.isNotBlank(password)) {
        user.setPassword(password);
    }
    identityService.saveUser(user);
    redirectAttributes.addFlashAttribute("message", "成功添加用户[" + firstName + " " + lastName + "]");
    return "redirect:/chapter14/identity/user/list";
}
 
Example 2
Source File: IdentityController.java    From activiti-in-action-codes with Apache License 2.0 6 votes vote down vote up
/**
 * 保存User
 *
 * @param redirectAttributes
 * @return
 */
@RequestMapping(value = "user/save", method = RequestMethod.POST)
public String saveUser(@RequestParam("userId") String userId,
                       @RequestParam("firstName") String firstName,
                       @RequestParam("lastName") String lastName,
                       @RequestParam(value = "password", required = false) String password,
                       @RequestParam(value = "email", required = false) String email,
                       RedirectAttributes redirectAttributes) {
    User user = identityService.createUserQuery().userId(userId).singleResult();
    if (user == null) {
        user = identityService.newUser(userId);
    }
    user.setFirstName(firstName);
    user.setLastName(lastName);
    user.setEmail(email);
    if (StringUtils.isNotBlank(password)) {
        user.setPassword(password);
    }
    identityService.saveUser(user);
    redirectAttributes.addFlashAttribute("message", "成功添加用户[" + firstName + " " + lastName + "]");
    return "redirect:/chapter14/identity/user/list";
}
 
Example 3
Source File: IdmUsersResource.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
@ResponseStatus(value = HttpStatus.OK)
@RequestMapping(value = "/rest/admin/users", method = RequestMethod.PUT)
public void bulkUpdateUserDetails(@RequestBody UpdateUsersRepresentation updateUsersRepresentation) {
  validateAdminRole();
  
  // Password update
  if (updateUsersRepresentation.getPassword() != null) {
    for (String userId : updateUsersRepresentation.getUsers()) {
      User user = identityService.createUserQuery().userId(userId).singleResult();
      if (user != null) {
        user.setPassword(updateUsersRepresentation.getPassword());
        identityService.saveUser(user);
      }
    }
  }
}
 
Example 4
Source File: IdmUsersResource.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
@RequestMapping(value = "/rest/admin/users", method = RequestMethod.POST)
public User createNewUser(@RequestBody CreateUserRepresentation userRepresentation) {
  validateAdminRole();
  
  if(StringUtils.isBlank(userRepresentation.getId()) ||
      StringUtils.isBlank(userRepresentation.getPassword()) || 
      StringUtils.isBlank(userRepresentation.getFirstName())) {
      throw new BadRequestException("Id, password and first name are required");
  }
  
  if (userRepresentation.getEmail() != null && identityService.createUserQuery().userEmail(userRepresentation.getEmail()).count() > 0) {
    throw new ConflictingRequestException("User already registered", "ACCOUNT.SIGNUP.ERROR.ALREADY-REGISTERED");
  } 
  
  User user = identityService.newUser(userRepresentation.getId() != null ? userRepresentation.getId() : userRepresentation.getEmail());
  user.setFirstName(userRepresentation.getFirstName());
  user.setLastName(userRepresentation.getLastName());
  user.setEmail(userRepresentation.getEmail());
  user.setPassword(userRepresentation.getPassword());
  identityService.saveUser(user);
  
  return user;
}
 
Example 5
Source File: IdentityController.java    From activiti-in-action-codes with Apache License 2.0 6 votes vote down vote up
/**
 * 保存User
 *
 * @param redirectAttributes
 * @return
 */
@RequestMapping(value = "user/save", method = RequestMethod.POST)
public String saveUser(@RequestParam("userId") String userId,
                       @RequestParam("firstName") String firstName,
                       @RequestParam("lastName") String lastName,
                       @RequestParam(value = "password", required = false) String password,
                       @RequestParam(value = "email", required = false) String email,
                       RedirectAttributes redirectAttributes) {
    User user = identityService.createUserQuery().userId(userId).singleResult();
    if (user == null) {
        user = identityService.newUser(userId);
    }
    user.setFirstName(firstName);
    user.setLastName(lastName);
    user.setEmail(email);
    if (StringUtils.isNotBlank(password)) {
        user.setPassword(password);
    }
    identityService.saveUser(user);
    redirectAttributes.addFlashAttribute("message", "成功添加用户[" + firstName + " " + lastName + "]");
    return "redirect:/chapter14/identity/user/list";
}
 
Example 6
Source File: CreateUserAndMembershipTestDelegate.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
@Override
public void execute(DelegateExecution execution) {

  IdentityService identityService = Context.getProcessEngineConfiguration().getIdentityService();

  String username = "Kermit";
  User user = identityService.newUser(username);
  user.setPassword("123");
  user.setFirstName("Manually");
  user.setLastName("created");
  identityService.saveUser(user);

  // Add admin group
  Group group = identityService.newGroup("admin");
  identityService.saveGroup(group);

  identityService.createMembership(username, "admin");
}
 
Example 7
Source File: IdentityTest.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
public void testAuthentication() {
  User user = identityService.newUser("johndoe");
  user.setPassword("xxx");
  identityService.saveUser(user);

  assertTrue(identityService.checkPassword("johndoe", "xxx"));
  assertFalse(identityService.checkPassword("johndoe", "invalid pwd"));

  identityService.deleteUser("johndoe");
}
 
Example 8
Source File: SignUpController.java    From Spring-MVC-Blueprints with MIT License 5 votes vote down vote up
@RequestMapping(method=RequestMethod.POST)
public RedirectView submitForm(Model model, @ModelAttribute LoginForm signupForm, BindingResult bindingResult){
	model.addAttribute("signupForm", signupForm);
	RedirectView redirectView = new RedirectView();
	redirectView.setContextRelative(true);
	
	if(bindingResult.hasErrors()) {
		signupForm = new LoginForm();
		redirectView.setUrl("/ocs/signup");
		references(model);
		model.addAttribute("signupForm", signupForm);
	} else{
		loginService.addAccount(signupForm);
		IdentityService identityService = processEngine.getIdentityService();
	    User user = identityService.newUser(signupForm.getUsername());
	    user.setPassword(signupForm.getPassword());
	    identityService.saveUser(user);
	    
	    try{
	    	identityService.saveGroup(identityService.newGroup("payor"));
			identityService.saveGroup(identityService.newGroup("shipper"));
			identityService.saveGroup(identityService.newGroup("shopper"));
			identityService.saveGroup(identityService.newGroup("buyer"));
	    }catch(Exception e){
	    	System.out.println("Groups already exists....");
	    }
	   
	    identityService.createMembership(signupForm.getUsername(), "shopper");
	    identityService.createMembership(signupForm.getUsername(), "buyer");
	    identityService.createMembership(signupForm.getUsername(), "payor");
	    identityService.createMembership(signupForm.getUsername(), "shipper");
	      		
		redirectView.setUrl("/ocs/login");
		
	}
	return redirectView;
}
 
Example 9
Source File: IdentityTest.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
public void testAuthentication() {
  User user = identityService.newUser("johndoe");
  user.setPassword("xxx");
  identityService.saveUser(user);

  assertTrue(identityService.checkPassword("johndoe", "xxx"));
  assertFalse(identityService.checkPassword("johndoe", "invalid pwd"));

  identityService.deleteUser("johndoe");
}
 
Example 10
Source File: AccountController.java    From maven-framework-project with MIT License 5 votes vote down vote up
/**
 * 执行用户登录
 * @param username接受表单提交过来的用户名
 * @param password接受表单提交过来的密码
 * @param request
 * @param response
 * @return
 */
@RequestMapping(value="/loginin",method={RequestMethod.POST,RequestMethod.GET})
public String loginin(@RequestParam("username")String username,@RequestParam("password")String password,HttpServletRequest request, HttpServletResponse response,RedirectAttributes redirectAttributes){
	String forword="";
	if((username!=null&&username.length()>0)&&(password!=null&&password.length()>0)){
		boolean b = accountService.checkPassword(username, password);
		if(b){
			User user = activitiWorkFlowService.getUserInfo(username);
			user.setId(username);
			user.setPassword(password);
			
			//查询用户所在的组
			
			List<Group> listGroup = identityService.createGroupQuery().groupMember(username).list();
			
			request.getSession().setAttribute("loginuser", user);
			request.getSession().setAttribute("listGroup", listGroup);
			redirectAttributes.addFlashAttribute("message", "登录成功!");
			forword="/main";//main.jsp
		}else{
			redirectAttributes.addFlashAttribute("message", "用户名或密码错误!");
			forword="/login";//login.jsp
		}
	}else{
		forword="/login";//login.jsp
		redirectAttributes.addFlashAttribute("message", "用户名或密码不能为空!");
	}
	return "redirect:"+forword;
}
 
Example 11
Source File: SerializableVariablesDiabledTest.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
@Before
public void setupServer() {
	if (serverUrlPrefix == null) {
		TestServer testServer = TestServerUtil.createAndStartServer(ObjectVariableSerializationDisabledApplicationConfiguration.class);
		serverUrlPrefix = testServer.getServerUrlPrefix();
		
		this.repositoryService = testServer.getApplicationContext().getBean(RepositoryService.class);
		this.runtimeService = testServer.getApplicationContext().getBean(RuntimeService.class);
		this.identityService = testServer.getApplicationContext().getBean(IdentityService.class);
		this.taskService = testServer.getApplicationContext().getBean(TaskService.class);
		
    User user = identityService.newUser("kermit");
    user.setFirstName("Kermit");
    user.setLastName("the Frog");
    user.setPassword("kermit");
    identityService.saveUser(user);
    
    Group group = identityService.newGroup("admin");
    group.setName("Administrators");
    identityService.saveGroup(group);
    
    identityService.createMembership(user.getId(), group.getId());
    
    this.testUserId = user.getId();
    this.testGroupId = group.getId();
	}
}
 
Example 12
Source File: BaseSpringRestTestCase.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
protected void createUsers() {
  User user = identityService.newUser("kermit");
  user.setFirstName("Kermit");
  user.setLastName("the Frog");
  user.setPassword("kermit");
  identityService.saveUser(user);

  Group group = identityService.newGroup("admin");
  group.setName("Administrators");
  identityService.saveGroup(group);

  identityService.createMembership(user.getId(), group.getId());
}
 
Example 13
Source File: BaseJPARestTestCase.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
protected void createUsers() {
  User user = identityService.newUser("kermit");
  user.setFirstName("Kermit");
  user.setLastName("the Frog");
  user.setPassword("kermit");
  identityService.saveUser(user);

  Group group = identityService.newGroup("admin");
  group.setName("Administrators");
  identityService.saveGroup(group);

  identityService.createMembership(user.getId(), group.getId());
}
 
Example 14
Source File: UserCollectionResource.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
@ApiOperation(value = "Create a user", tags = {"Users"})
@ApiResponses(value = {
    @ApiResponse(code = 201, message = "Indicates the user was created."),
    @ApiResponse(code = 400, message = "Indicates the id of the user was missing.")
})
@RequestMapping(value = "/identity/users", method = RequestMethod.POST, produces = "application/json")
public UserResponse createUser(@RequestBody UserRequest userRequest, HttpServletRequest request, HttpServletResponse response) {
  if (userRequest.getId() == null) {
    throw new ActivitiIllegalArgumentException("Id cannot be null.");
  }

  // Check if a user with the given ID already exists so we return a
  // CONFLICT
  if (identityService.createUserQuery().userId(userRequest.getId()).count() > 0) {
    throw new ActivitiConflictException("A user with id '" + userRequest.getId() + "' already exists.");
  }

  User created = identityService.newUser(userRequest.getId());
  created.setEmail(userRequest.getEmail());
  created.setFirstName(userRequest.getFirstName());
  created.setLastName(userRequest.getLastName());
  created.setPassword(userRequest.getPassword());
  identityService.saveUser(created);

  response.setStatus(HttpStatus.CREATED.value());

  return restResponseFactory.createUserResponse(created, true);
}
 
Example 15
Source File: UserResource.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
@ApiOperation(value = "Update a user", tags = {"Users"},
    notes="All request values are optional. "
        + "For example, you can only include the firstName attribute in the request body JSON-object, only updating the firstName of the user, leaving all other fields unaffected. "
        + "When an attribute is explicitly included and is set to null, the user-value will be updated to null. "
        + "Example: {\"firstName\" : null} will clear the firstName of the user).")
@ApiResponses(value = {
    @ApiResponse(code = 200, message = "Indicates the user was updated."),
    @ApiResponse(code = 404, message = "Indicates the requested user was not found."),
    @ApiResponse(code = 409, message = "Indicates the requested user was updated simultaneously.")
})
@RequestMapping(value = "/identity/users/{userId}", method = RequestMethod.PUT, produces = "application/json")
public UserResponse updateUser(@ApiParam(name = "userId") @PathVariable String userId, @RequestBody UserRequest userRequest, HttpServletRequest request) {
  User user = getUserFromRequest(userId);
  if (userRequest.isEmailChanged()) {
    user.setEmail(userRequest.getEmail());
  }
  if (userRequest.isFirstNameChanged()) {
    user.setFirstName(userRequest.getFirstName());
  }
  if (userRequest.isLastNameChanged()) {
    user.setLastName(userRequest.getLastName());
  }
  if (userRequest.isPasswordChanged()) {
    user.setPassword(userRequest.getPassword());
  }

  identityService.saveUser(user);

  return restResponseFactory.createUserResponse(user, false);
}
 
Example 16
Source File: IdmProfileResource.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
@ResponseStatus(value = HttpStatus.OK)
@RequestMapping(value = "/profile-password", method = RequestMethod.POST, produces = "application/json")
public void changePassword(@RequestBody ChangePasswordRepresentation changePasswordRepresentation) {
  User user = identityService.createUserQuery().userId(SecurityUtils.getCurrentUserId()).singleResult();
  if (!user.getPassword().equals(changePasswordRepresentation.getOriginalPassword())) {
    throw new NotFoundException();
  }
  user.setPassword(changePasswordRepresentation.getNewPassword());
  identityService.saveUser(user);
}
 
Example 17
Source File: Bootstrapper.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
protected User initializeSuperUser() {
  String adminPassword = env.getRequiredProperty("admin.password");
  String adminLastname = env.getRequiredProperty("admin.lastname");
  String adminEmail = env.getRequiredProperty("admin.email");

  User admin = identityService.newUser(adminEmail);
  admin.setLastName(adminLastname);
  admin.setEmail(adminEmail);
  admin.setPassword(adminPassword);
  identityService.saveUser(admin);
  return admin;
}
 
Example 18
Source File: Application.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
@Bean
InitializingBean usersAndGroupsInitializer(final IdentityService identityService) {

    return new InitializingBean() {
        @Override
        public void afterPropertiesSet() throws Exception {

            // install groups & users
            Group group = identityService.newGroup("user");
            group.setName("users");
            group.setType("security-role");
            identityService.saveGroup(group);

            User joram = identityService.newUser("jbarrez");
            joram.setFirstName("Joram");
            joram.setLastName("Barrez");
            joram.setPassword("password");
            identityService.saveUser(joram);

            User josh = identityService.newUser("jlong");
            josh.setFirstName("Josh");
            josh.setLastName("Long");
            josh.setPassword("password");
            identityService.saveUser(josh);

            identityService.createMembership("jbarrez", "user");
            identityService.createMembership("jlong", "user");
        }
    };
}
 
Example 19
Source File: SecurityAutoConfigurationTest.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
protected User user(String userName, String f, String l) {
    User u = identityService.newUser(userName);
    u.setFirstName(f);
    u.setLastName(l);
    u.setPassword("password");
    identityService.saveUser(u);
    return u;
}
 
Example 20
Source File: SpringIdentityServiceTest.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
@Override
public void notify(DelegateTask delegateTask) {

  User user = identityService.newUser("User1");
  user.setFirstName("User1");
  user.setLastName("Created");
  user.setEmail("[email protected]");
  user.setPassword("User1");
  identityService.saveUser(user);
}