【问题标题】:How to force authentication in Camunda Java api?如何在 Camunda Java api 中强制进行身份验证?
【发布时间】:2016-03-20 09:52:30
【问题描述】:
我们在 Camunda BPM 中部署了一个基于 Spring 的应用程序。我们在这里使用 Camunda JAVA api 公开了一些 REST 服务。我们这样做是为了满足一些没有可用的 Camunda REST api 的特定要求。这些自定义 REST 服务在没有身份验证和授权的情况下运行。我能够通过这些服务创建/完成/删除流程和任务,而无需验证有效用户。我想知道如何强制 Camunda Java api 在执行之前寻找经过身份验证的用户。我正在使用 Camunda BPM 7.3。
【问题讨论】:
标签:
authentication
camunda
【解决方案1】:
我找到了答案。在这种情况下,身份验证在我们手中。我们必须以任何我们想要的方式对用户进行身份验证,然后在 identityService 中设置经过身份验证的 userId。如果经过身份验证的用户为空,则也会跳过授权检查。因此,我的代码无需身份验证即可工作。
在 AuthorizationManager 类中检查以下代码 -
public void checkAuthorization(List<PermissionCheck> permissionChecks) {
Authentication currentAuthentication = getCurrentAuthentication();
CommandContext commandContext = getCommandContext();
if(isAuthorizationEnabled() && currentAuthentication != null && commandContext.isAuthorizationCheckEnabled()) {
String userId = currentAuthentication.getUserId();
boolean isAuthorized = isAuthorized(userId, currentAuthentication.getGroupIds(), permissionChecks);
...........
.......
从 IF 条件可以看出,如果 currentAuthentication 为 null,则不会调用 isAuthroized() 方法。
要记住的另一件事是在 bpm-platform.xml 中,我们定义了 ProcessEngineConfiguration,我们需要将 authorizationEnabled 属性设置为 true。