在上个章节《[6]深入浅出工作开源框架Camunda: 如何远程Debug camunda-webapp的源代码》笔者解释了如何进行Camunda的远程Debug,这个章节笔者给大家分享如何进行camunda-webapp 用户登录功能代码分析. 首先还是输入,http://127.0.0.1:8080/camunda/app/welcome/default/#!/login

点击“Login” 按钮后,其会执行下面的代码:

package org.camunda.bpm.webapp.impl.security.auth;import java.util.ArrayList;
import java.util.List;
import java.util.Set;import javax.servlet.http.HttpServletRequest;
import javax.ws.rs.FormParam;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.Response.Status;import org.camunda.bpm.engine.ProcessEngine;
import org.camunda.bpm.engine.identity.Group;
import org.camunda.bpm.engine.identity.Tenant;
import org.camunda.bpm.engine.rest.exception.InvalidRequestException;
import org.camunda.bpm.webapp.impl.util.ProcessEngineUtil;/*** Jax-Rs resource allowing users to authenticate with username and password</p>** @author Daniel Meyer**/
@Path(UserAuthenticationResource.PATH)
public class UserAuthenticationResource {public static final String PATH = "/auth/user";@Contextprotected HttpServletRequest request;@GET@Path("/{processEngineName}")public Response getAuthenticatedUser(@PathParam("processEngineName") String engineName) {Authentications allAuthentications = Authentications.getCurrent();if (allAuthentications == null) {return notFound();}Authentication engineAuth = allAuthentications.getAuthenticationForProcessEngine(engineName);if (engineAuth == null) {return notFound();} else {return Response.ok(AuthenticationDto.fromAuthentication(engineAuth)).build();}}@POST@Path("/{processEngineName}/login/{appName}")public Response doLogin(@PathParam("processEngineName") String engineName,@PathParam("appName") String appName,@FormParam("username") String username,@FormParam("password") String password) {final ProcessEngine processEngine = ProcessEngineUtil.lookupProcessEngine(engineName);if(processEngine == null) {throw new InvalidRequestException(Status.BAD_REQUEST, "Process engine with name "+engineName+" does not exist");}// make sure authentication is executed without authentication :)processEngine.getIdentityService().clearAuthentication();// check password / usernameboolean isPasswordValid = processEngine.getIdentityService().checkPassword(username, password);if (!isPasswordValid) {return unauthorized();}AuthenticationService authenticationService = new AuthenticationService();UserAuthentication authentication = (UserAuthentication) authenticationService.createAuthenticate(processEngine, username, null, null);Set<String> authorizedApps = authentication.getAuthorizedApps();if (!authorizedApps.contains(appName)) {return forbidden();}if (request != null) {Authentications.revalidateSession(request, authentication);}return Response.ok(AuthenticationDto.fromAuthentication(authentication)).build();}protected List<String> getGroupsOfUser(ProcessEngine engine, String userId) {List<Group> groups = engine.getIdentityService().createGroupQuery().groupMember(userId).list();List<String> groupIds = new ArrayList<String>();for (Group group : groups) {groupIds.add(group.getId());}return groupIds;}protected List<String> getTenantsOfUser(ProcessEngine engine, String userId) {List<Tenant> tenants = engine.getIdentityService().createTenantQuery().userMember(userId).includingGroupsOfUser(true).list();List<String> tenantIds = new ArrayList<String>();for(Tenant tenant : tenants) {tenantIds.add(tenant.getId());}return tenantIds;}@POST@Path("/{processEngineName}/logout")public Response doLogout(@PathParam("processEngineName") String engineName) {final Authentications authentications = Authentications.getCurrent();// remove authentication for process engineauthentications.removeAuthenticationForProcessEngine(engineName);return Response.ok().build();}protected Response unauthorized() {return Response.status(Status.UNAUTHORIZED).build();}protected Response forbidden() {return Response.status(Status.FORBIDDEN).build();}protected Response notFound() {return Response.status(Status.NOT_FOUND).build();}
}

上面代码来自于类UserAuthenticationResource, 其会调用doLogin() 方法,整体认证流程如下如所示意!

[7]深入浅出工作开源框架Camunda: camunda-webapp 用户登录功能代码分析相关推荐

  1. mysql flask-login_Flask框架通过Flask_login实现用户登录功能示例

    本文实例讲述了Flask框架通过Flask_login实现用户登录功能.分享给大家供大家参考,具体如下: 通过Flask_Login实现用户验证登录,并通过login_required装饰器来判断用户 ...

  2. [1]深入浅出工作开源框架Camunda: 安装和使用

    目前比较出名的开源工作流框架大概有4个,分别是Activiti/Camunda/Flowable/Jbpm.下面我们先抛开Jbpm框架,因为JBPM的二次开发难度比较大:笔者窃以为Camunda是一个 ...

  3. [15]深入浅出工作开源框架Camunda:定时任务

    1.引言 在BPMN中,可以通过改变"Timer Start Event" 启动节点的启动类型来自动启动流程实例. 其提供了下面三种定时自动触发流程实例的模式: 指定固定的时间点启 ...

  4. [13]深入浅出工作开源框架Camunda:多实例并行用户任务

    Camunda提供了多实例并行用户任务,比如下面的并行多任务流程! 必须选择三条竖杠. 选择之后,就可以让"并行会签预审批"任务同时由多个人处理~ 参考<基于camunda如 ...

  5. python开源代码-这7个开源的Python库,让你轻松代码分析

    原标题:这7个开源的Python库,让你轻松代码分析 开源最前线(ID:OpenSourceTop) 猿妹编译 来源:https://opensource.com/article/18/7/7-pyt ...

  6. python flask框架下登录注册界面_Python的Flask框架中实现简单的登录功能的教程

    Python 的 Flask 框架中实现简单的登录功能的教程 , 登录是各个 web 框架中的基础功能 , 需要的朋友可以参考下 回顾 在前面的系列章节中, 我们创建了一个数据库并且学着用用户和邮件来 ...

  7. 使用 Flask 框架写用户登录功能的Demo时碰到的各种坑(一)——创建应用

    使用 Flask 框架写用户登录功能的Demo时碰到的各种坑(一)--创建应用 使用 Flask 框架写用户登录功能的Demo时碰到的各种坑(二)--使用蓝图功能进行模块化 使用 Flask 框架写用 ...

  8. 【PHP开源产品】Ecshop的商品筛选功能实现分析之一(主要对category.php进行分析)

    [PHP开源产品]Ecshop的商品筛选功能实现分析之一(主要对category.php进行分析) 一.首先,说明一下为什么要对category.php文件进行分析. (1)原因如下: ①个人对商城类 ...

  9. 大数据开源框架之基于Spark的气象数据处理与分析

    Spark配置请看: (30条消息) 大数据开源框架环境搭建(七)--Spark完全分布式集群的安装部署_木子一个Lee的博客-CSDN博客 目录 实验说明: 实验要求: 实验步骤: 数据获取: 数据 ...

最新文章

  1. linux显示前一天时间,在linux显示昨天(前一天)的日期
  2. 用init-connect+binlog实现用户操作追踪【转】
  3. Postman for Linux(x86)
  4. FreeRtos osMessagePut osMessageGet 函数
  5. python批量读取文件名_python - 从路径中提取文件名,无论os / path形式如何
  6. zsh 隐藏用户名和主机
  7. 判断字段长度大于某长度_判断数据库性能只能通过count(*)?No,这些优化方案了解一下!...
  8. php 高效判断是否登录,php 判断用户是否登录
  9. 解决maven dependencies xxx not found
  10. Linux内存管理:kmemcheck介绍
  11. 字节大牛耗时八个月又一力作,原理+实战讲解
  12. VassistX的简单介绍与下载安装
  13. 李宏毅机器学习Homework1(代码简洁版)
  14. 数据恢复工具winhex使用教程
  15. God‘s Perspective - God View - 上帝视角
  16. 手动释放Linux显卡显存
  17. 关于selenium调用firefox浏览器的调试
  18. 统计分析知识之--描述性统计
  19. Javaweb 实现简单的用户注册登录(含数据库访问功能)
  20. 欧洲杯第五周的比赛闲聊

热门文章

  1. 独立性检验(卡方检验)
  2. PyDev Eclipse使用技巧说明
  3. package import
  4. 两两独立为什么不能推出相互独立
  5. RAID磁盘阵列的几种模式
  6. C++小知识——VS2013 MFC基于对话框编程
  7. 什么是字节码?采用字节码的好处是什么?
  8. 大合集!互联网行业常用数据分析指标
  9. (Android)很抱歉,“xx”程序已经停止运行
  10. python生成春联图片,并包装为GUI工具