Structure of the API
New features ProcessRuntime
-
Java code implementation
private static final Logger LOGGER = LoggerFactory.getLogger(Part8_ProcessRuntime.class); @Resource private ProcessRuntime processRuntime; @Resource private SecurityUtil securityUtil; /* Get the process instance */ @Test public void getProcessInstance(a) { securityUtil.logInAs("bajie"); Page<ProcessInstance> processInstancePage = processRuntime.processInstances(Pageable.of(0.100)); int totalItems = processInstancePage.getTotalItems(); LOGGER.info("Start process instance = {}", totalItems); List<ProcessInstance> content = processInstancePage.getContent(); for (ProcessInstance processInstance : content) { LOGGER.info("-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -"); LOGGER.info("id = {}", processInstance.getId()); LOGGER.info("Name = {}", processInstance.getName()); LOGGER.info("StartDate = {}", processInstance.getStartDate()); LOGGER.info("Status = {}", processInstance.getStatus()); LOGGER.info("ProcessDefinitionId = {}", processInstance.getProcessDefinitionId()); LOGGER.info("ProcessDefinitionKey = {}", processInstance.getProcessDefinitionKey()); }}/* Start the process instance */ @Test public void startProcessInstance(a) { securityUtil.logInAs("bajie"); ProcessInstance processInstance = processRuntime.start( ProcessPayloadBuilder.start() .withProcessDefinitionKey("defkey") .withName("First process instance name") .withBusinessKey("Custom key") .build() ); } Copy the code
-
The results
taskList.size()= 1
task.getId()= ae4bae6c-7a36-11eb-8698-80a589C981F4 task.getName()= Task.getassignee ()= bajie of the pRuntime task of BajieCopy the code
/* Delete the process instance */
@Test
public void delProcessInstance(a) {
processRuntime.delete(
ProcessPayloadBuilder
.delete()
.withProcessInstanceId("ae3f7967-7a36-11eb-8698-80a589c981f4")
.build()
);
}
Copy the code
/* Suspend the process instance */
@Test
public void suspendProcessInstance(a) {
securityUtil.logInAs("baijie");
processRuntime.suspend(
ProcessPayloadBuilder
.suspend()
.withProcessInstanceId("ae3f7967-7a36-11eb-8698-80a589c981f4")
.build()
);
}
/* Restart the process instance */
@Test
public void resumeProcessInstance(a) {
securityUtil.logInAs("bajie");
processRuntime
.resume(ProcessPayloadBuilder
.resume()
.withProcessInstanceId("ae3f7967-7a36-11eb-8698-80a589c981f4")
.build()
);
}
/* Process instance parameters */
@Test
public void getVariables(a) {
securityUtil.logInAs("bajie");
List<VariableInstance> variables = processRuntime.variables(ProcessPayloadBuilder
.variables()
.withProcessInstanceId("ae3f7967-7a36-11eb-8698-80a589c981f4")
.build()
);
for (VariableInstance variable : variables) {
LOGGER.info("-- -- -- -- -- -- -- -- -- -- -- -- -- -- --");
LOGGER.info("getName = {}",variable.getName());
LOGGER.info("getTaskId = {}",variable.getTaskId());
LOGGER.info("getProcessInstanceId = {}",variable.getProcessInstanceId()); }}Copy the code
New features TaskRuntime
-
Java code
private static final Logger LOGGER = LoggerFactory.getLogger(Part9_TaskRuntime.class); @Resource private TaskRuntime taskRuntime; @Resource private SecurityUtil securityUtil; @Test public void getTask(a) { securityUtil.logInAs("bajie"); Page<Task> tasks = taskRuntime.tasks(Pageable.of(0.100)); int totalItems = tasks.getTotalItems(); LOGGER.info("Total data = {}", totalItems); List<Task> content = tasks.getContent(); for (Task task : content) { LOGGER.info("task.id = {}", task.getId()); LOGGER.info("task.getName() = {}", task.getName()); LOGGER.info("task.getStatus() = {}", task.getStatus()); LOGGER.info("task.getCreatedDate() = {}", task.getCreatedDate()); }}@Test public void completeTask(a) { securityUtil.logInAs("bajie"); Task task = taskRuntime.task(""); if (task.getAssignee() == null) { LOGGER.info("Assignee: Task to be picked"); taskRuntime.claim(TaskPayloadBuilder .claim() .withTaskId(task.getId()) .build()); } else { taskRuntime.complete(TaskPayloadBuilder .complete() .withTaskId(task.getId()) .build()); LOGGER.info("Assignee: = {}", task.getAssignee()); }}Copy the code
The SpringSecurity user logs in
function
- certification
- Authentication/authorization
Three sources of users
- Application.properties Configures the user
- Configure the memory user in the code
- Load the user from the database
Knowledge of this course
-
Memory login is changed to database data login
-
SpringSecurity configuration file details
-
Login response processing scheme
Memory login is changed to database data login
Simulated database verification
@Override
public UserDetails loadUserByUsername(String userName) throws UsernameNotFoundException {
String passwrod = passwordEncoder().encode("111");
return new User(
userName
, passwrod
, AuthorityUtils.commaSeparatedStringToAuthorityList("ROLE_ACTIVITI_USER")); }Copy the code
Front-end login verification
@Override
public UserDetails loadUserByUsername(String userName) throws UsernameNotFoundException {
String passwrod = passwordEncoder().encode("111");
UserInfoBean userInfoBean = userInfoBeanMapper.selectByUsername(userName);
if (StringUtils.isEmpty(userInfoBean)) {
throw new UsernameNotFoundException("Please register before login.");
}
return userInfoBean;
/* return new User( userName , passwrod , AuthorityUtils.commaSeparatedStringToAuthorityList("ROLE_ACTIVITI_USER") ); * /
}
Copy the code
-
The entity class for the database user
@Component public class UserInfoBean implements UserDetails { private Integer id; private String address; private String name; private String username; private String roles; private String password; /* Assign the role */ @Override public Collection<? extends GrantedAuthority> getAuthorities() { return Arrays.stream(roles.split(",")).map( s -> new SimpleGrantedAuthority(s)) .collect(Collectors.toList() ); } public String getAddress(a) { return address; } @Override public String getPassword(a) { return password; } @Override public String getUsername(a) { return username; } @Override public boolean isAccountNonExpired(a) { return true; } @Override public boolean isAccountNonLocked(a) { return true; } @Override public boolean isCredentialsNonExpired(a) { return true; } @Override public boolean isEnabled(a) { return true; }}Copy the code
SpringSecurity configuration
- Memory login is changed to database value login
- SpringSecurity configuration details
- Login response processing scheme
SpringSecurity configures login interface/interceptor authoring
@Configuration
public class ActivitiSecurityConfig extends WebSecurityConfigurerAdapter {
@Resource
private LoginSuccessHandler loginSuccessHandler;
@Resource
private LoginFailureHandler loginFailureHandler;
@Override
protected void configure(HttpSecurity httpSecurity) throws Exception {
httpSecurity.formLogin()
// Login method
.loginPage("/login")
.loginProcessingUrl("/login") .successHandler(loginSuccessHandler) .failureHandler(loginFailureHandler) .and() .authorizeRequests() .anyRequest().permitAll() .and() .logout().permitAll() .and() .csrf().disable() .headers().frameOptions().disable(); }}Copy the code
SpringSecurity returns customized information after a successful login
@Component("loginSuccessHandler")
public class LoginSuccessHandler implements AuthenticationSuccessHandler {
@Override
public void onAuthenticationSuccess(HttpServletRequest request, HttpServletResponse response, FilterChain chain, Authentication authentication) throws IOException, ServletException {}@Override
public void onAuthenticationSuccess(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, Authentication authentication) throws IOException, ServletException {
httpServletResponse.setContentType("applicationn/json; charset=UTF-8");
httpServletResponse.getWriter().write("Successful landing!"+authentication.getPrincipal()); }}Copy the code
SpringSecurity login response
Login failure message
public class ActivitiSecurityController {
@RequestMapping("/login")
@ResponseStatus(code = HttpStatus.UNAUTHORIZED)
public String requireAuthentication(HttpServletRequest httpServletRequest , HttpServletResponse httpServletResponse) {
return "Please login first, use login.html or make a POST login request."; }}Copy the code
- Control layer preparation
public class ActivitiSecurityController {
@RequestMapping("/login")
@ResponseStatus(code = HttpStatus.UNAUTHORIZED)
public String requireAuthentication(HttpServletRequest httpServletRequest , HttpServletResponse httpServletResponse) {
return "Please login first, use login.html or make a POST login request."; }}Copy the code
BPMN – JS integration
- Bpmn-js download address: github.com/bpmn-io/bpm…
- The: BPMNJS initializer. Zip file in the root directory of the project is added to resource/resource