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

The following examples show how to use org.activiti.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: IdentityServiceTest.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
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());
  
  //interface defintion states that setting picture to null should delete it
  identityService.setUserPicture(userId, null);
  assertNull("it should be possible to nullify user picture",identityService.getUserPicture(userId));    
  user = identityService.createUserQuery().userId("johndoe").singleResult();
  assertNull("it should be possible to delete user picture",identityService.getUserPicture(userId));

  identityService.deleteUser(user.getId());
}
 
Example 2
Source File: UserInfoResource.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
@ApiOperation(value = "Get a user’s info", tags = {"Users"})
@ApiResponses(value = {
    @ApiResponse(code = 200, message = "Indicates the user was found and the user has info for the given key."),
    @ApiResponse(code = 404, message = "Indicates the requested user was not found or the user doesn’t have info for the given key. Status description contains additional information about the error.")
})
@RequestMapping(value = "/identity/users/{userId}/info/{key}", method = RequestMethod.GET, produces = "application/json")
public UserInfoResponse getUserInfo(@ApiParam(name = "userId", value="The id of the user to get the info for.") @PathVariable("userId") String userId,@ApiParam(name = "key", value="The key of the user info to get.") @PathVariable("key") String key, HttpServletRequest request) {
  User user = getUserFromRequest(userId);

  String existingValue = identityService.getUserInfo(user.getId(), key);
  if (existingValue == null) {
    throw new ActivitiObjectNotFoundException("User info with key '" + key + "' does not exists for user '" + user.getId() + "'.", null);
  }

  return restResponseFactory.createUserInfoResponse(key, existingValue, user.getId());
}
 
Example 3
Source File: IdentityServiceTest.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
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());
  
  //interface defintion states that setting picture to null should delete it
  identityService.setUserPicture(userId, null);
  assertNull("it should be possible to nullify user picture",identityService.getUserPicture(userId));    
  user = identityService.createUserQuery().userId("johndoe").singleResult();
  assertNull("it should be possible to delete user picture",identityService.getUserPicture(userId));

  identityService.deleteUser(user.getId());
}
 
Example 4
Source File: TraceProcessController.java    From activiti-in-action-codes with Apache License 2.0 6 votes vote down vote up
/**
 * 获取当前节点信息
 *
 * @return
 */
private void setCurrentTaskInfo(String executionId, String activityId, Map<String, Object> vars) {
    Task currentTask = taskService.createTaskQuery().executionId(executionId)
            .taskDefinitionKey(activityId).singleResult();
    logger.debug("current task for processInstance: {}", ToStringBuilder.reflectionToString(currentTask));

    if (currentTask == null) return;

    String assignee = currentTask.getAssignee();
    if (assignee != null) {
        User assigneeUser = identityService.createUserQuery().userId(assignee).singleResult();
        String userInfo = assigneeUser.getFirstName() + " " + assigneeUser.getLastName() + "/" + assigneeUser.getId();
        vars.put("当前处理人", userInfo);
        vars.put("创建时间", new SimpleDateFormat("yyyy-MM-dd hh:mm:ss").format(currentTask.getCreateTime()));
    } else {
        vars.put("任务状态", "未签收");
    }

}
 
Example 5
Source File: TraceProcessController.java    From activiti-in-action-codes with Apache License 2.0 6 votes vote down vote up
/**
 * 获取当前节点信息
 *
 * @return
 */
private void setCurrentTaskInfo(String executionId, String activityId, Map<String, Object> vars) {
    Task currentTask = taskService.createTaskQuery().executionId(executionId)
            .taskDefinitionKey(activityId).singleResult();
    logger.debug("current task for processInstance: {}", ToStringBuilder.reflectionToString(currentTask));

    if (currentTask == null) return;

    String assignee = currentTask.getAssignee();
    if (assignee != null) {
        User assigneeUser = identityService.createUserQuery().userId(assignee).singleResult();
        String userInfo = assigneeUser.getFirstName() + " " + assigneeUser.getLastName() + "/" + assigneeUser.getId();
        vars.put("当前处理人", userInfo);
        vars.put("创建时间", new SimpleDateFormat("yyyy-MM-dd hh:mm:ss").format(currentTask.getCreateTime()));
    } else {
        vars.put("任务状态", "未签收");
    }

}
 
Example 6
Source File: TraceProcessController.java    From activiti-in-action-codes with Apache License 2.0 6 votes vote down vote up
/**
 * 获取当前节点信息
 *
 * @return
 */
private void setCurrentTaskInfo(String executionId, String activityId, Map<String, Object> vars) {
    Task currentTask = taskService.createTaskQuery().executionId(executionId)
            .taskDefinitionKey(activityId).singleResult();
    logger.debug("current task for processInstance: {}", ToStringBuilder.reflectionToString(currentTask));

    if (currentTask == null) return;

    String assignee = currentTask.getAssignee();
    if (assignee != null) {
        User assigneeUser = identityService.createUserQuery().userId(assignee).singleResult();
        String userInfo = assigneeUser.getFirstName() + " " + assigneeUser.getLastName() + "/" + assigneeUser.getId();
        vars.put("当前处理人", userInfo);
        vars.put("创建时间", new SimpleDateFormat("yyyy-MM-dd hh:mm:ss").format(currentTask.getCreateTime()));
    } else {
        vars.put("任务状态", "未签收");
    }

}
 
Example 7
Source File: TraceProcessController.java    From activiti-in-action-codes with Apache License 2.0 6 votes vote down vote up
/**
 * 获取当前节点信息
 *
 * @return
 */
private void setCurrentTaskInfo(String executionId, String activityId, Map<String, Object> vars) {
    Task currentTask = taskService.createTaskQuery().executionId(executionId)
            .taskDefinitionKey(activityId).singleResult();
    logger.debug("current task for processInstance: {}", ToStringBuilder.reflectionToString(currentTask));

    if (currentTask == null) return;

    String assignee = currentTask.getAssignee();
    if (assignee != null) {
        User assigneeUser = identityService.createUserQuery().userId(assignee).singleResult();
        String userInfo = assigneeUser.getFirstName() + " " + assigneeUser.getLastName() + "/" + assigneeUser.getId();
        vars.put("当前处理人", userInfo);
        vars.put("创建时间", new SimpleDateFormat("yyyy-MM-dd hh:mm:ss").format(currentTask.getCreateTime()));
    } else {
        vars.put("任务状态", "未签收");
    }

}
 
Example 8
Source File: TraceProcessController.java    From activiti-in-action-codes with Apache License 2.0 6 votes vote down vote up
/**
 * 获取当前节点信息
 *
 * @return
 */
private void setCurrentTaskInfo(String executionId, String activityId, Map<String, Object> vars) {
    Task currentTask = taskService.createTaskQuery().executionId(executionId)
            .taskDefinitionKey(activityId).singleResult();
    logger.debug("current task for processInstance: {}", ToStringBuilder.reflectionToString(currentTask));

    if (currentTask == null) return;

    String assignee = currentTask.getAssignee();
    if (assignee != null) {
        User assigneeUser = identityService.createUserQuery().userId(assignee).singleResult();
        String userInfo = assigneeUser.getFirstName() + " " + assigneeUser.getLastName() + "/" + assigneeUser.getId();
        vars.put("当前处理人", userInfo);
        vars.put("创建时间", new SimpleDateFormat("yyyy-MM-dd hh:mm:ss").format(currentTask.getCreateTime()));
    } else {
        vars.put("任务状态", "未签收");
    }

}
 
Example 9
Source File: IdentityServiceUserDetailsService.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
@Override
public UserDetails loadUserByUsername(String userId)
        throws UsernameNotFoundException {
    User user = null;
    try {
        user = this.identityService.createUserQuery()
                .userId(userId)
                .singleResult();
    } catch (ActivitiException ex) {
        // don't care
    }

    if (null == user) {
        throw new UsernameNotFoundException(
                String.format("user (%s) could not be found", userId));
    }

    // if the results not null then its active...
    boolean active = true;

    // get the granted authorities
    List<GrantedAuthority> grantedAuthorityList = new ArrayList<GrantedAuthority>();
    List<Group> groupsForUser = identityService
            .createGroupQuery()
            .groupMember(user.getId())
            .list();

    for (Group g : groupsForUser) {
        grantedAuthorityList.add(new GroupGrantedAuthority(g));
    }

    return new org.springframework.security.core.userdetails.User(
            user.getId(),
            user.getPassword() ,
            active, active, active, active,
            grantedAuthorityList);
}
 
Example 10
Source File: SecurityUtils.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
/**
 * Get the login of the current user.
 */
public static String getCurrentUserId() {
  User user = getCurrentUserObject();
  if (user != null) {
    return user.getId();
  }
  return null;
}
 
Example 11
Source File: UserPictureResource.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
@ApiOperation(value = "Get a user’s picture", tags = {"Users"},
    notes = "The response body contains the raw picture data, representing the user’s picture. The Content-type of the response corresponds to the mimeType that was set when creating the picture.")
@ApiResponses(value = {
    @ApiResponse(code = 200, message = "Indicates the user was found and has a picture, which is returned in the body."),
    @ApiResponse(code = 404, message = "Indicates the requested user was not found or the user does not have a profile picture. Status-description contains additional information about the error.")
})
@RequestMapping(value = "/identity/users/{userId}/picture", method = RequestMethod.GET)
public ResponseEntity<byte[]> getUserPicture(@ApiParam(name = "userId", value="The id of the user to get the picture for.") @PathVariable String userId, HttpServletRequest request, HttpServletResponse response) {
  User user = getUserFromRequest(userId);
  Picture userPicture = identityService.getUserPicture(user.getId());

  if (userPicture == null) {
    throw new ActivitiObjectNotFoundException("The user with id '" + user.getId() + "' does not have a picture.", Picture.class);
  }


  HttpHeaders responseHeaders = new HttpHeaders();
  if (userPicture.getMimeType() != null) {
    responseHeaders.set("Content-Type", userPicture.getMimeType());
  } else {
    responseHeaders.set("Content-Type", "image/jpeg");
  }

  try {
    return new ResponseEntity<byte[]>(IOUtils.toByteArray(userPicture.getInputStream()), responseHeaders, HttpStatus.OK);
  } catch (Exception e) {
    throw new ActivitiException("Error exporting picture: " + e.getMessage(), e);
  }
}
 
Example 12
Source File: UserInfoResource.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
protected String getValidKeyFromRequest(User user, String key) {
  String existingValue = identityService.getUserInfo(user.getId(), key);
  if (existingValue == null) {
    throw new ActivitiObjectNotFoundException("User info with key '" + key + "' does not exists for user '" + user.getId() + "'.", null);
  }

  return key;
}
 
Example 13
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 14
Source File: ActivitiAuthenticationProvider.java    From maven-framework-project with MIT License 5 votes vote down vote up
@Override
@Transactional(readOnly = true)
protected UserDetails retrieveUser(String username, UsernamePasswordAuthenticationToken authentication) throws AuthenticationException {
    log.trace("retrieveUser()");
    log.debug("retrieving user: " + username);
    User user;
    try {
        user = this.read(username);
        if (user == null) {
            throw new Exception();
        }
    } catch (Exception e) {
        throw new UsernameNotFoundException("User " + username + " cannot be found");
    }

    String userName = user.getId();
    String pw = user.getPassword();
    List<Group> groups = this.identityService.createGroupQuery().groupMember(userName).groupType("security-role").list();
    List<String> groupStr = Lists.newArrayList();
    for (Group g : groups) {
        groupStr.add(g.getId());
    }
    Collection<GrantedAuthority> auths = AuthorityUtils.commaSeparatedStringToAuthorityList(Joiner.on(",").skipNulls().join(groupStr));
    boolean enabled = groupStr.contains("user");

    UserDetails userDetails = new org.springframework.security.core.userdetails.User(userName, pw, enabled, true, true, true, auths);
    log.debug("returning new userDetails: " + userDetails);
    return userDetails;
}