gyo*_*ham 5 java spring business-process-management camunda spring-boot
我成功地将Spring Security与Camunda的IdentityService集成在一起。我的目标是在两者之间共享一个通用的身份验证领域,因为我们有一个基于Spring Boot的Web应用程序,该应用程序也运行camunda。在我们的应用程序中,Spring Security应该只管理单个身份验证领域,仅将Camunda用作只读客户端代码。
我们计划将业务流程与用户绑定在一起,并且应该从Spring Security验证这些用户。
我的问题是我应该完全实现/重写什么?
我当前的代码如下:
import org.camunda.bpm.engine.impl.identity.db.DbReadOnlyIdentityServiceProvider;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.authentication.AuthenticationManager;
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
import org.springframework.security.core.AuthenticationException;
import org.springframework.stereotype.Component;
/**
* Wires Camunda {@link org.camunda.bpm.engine.IdentityService} with Spring Security.
* TODO check if other method overrides are needed
*/
@Component
public class SpringSecurityReadOnlyIdentityServiceProvider extends DbReadOnlyIdentityServiceProvider {
@Autowired
private AuthenticationManager authenticationManager;
/**
* Checks if username and password is valid.
*
* @param userId Username
* @param password Password
* @return True if authentication succeeded
*/
@Override
public boolean checkPassword(String userId, String password) {
try {
authenticationManager.authenticate(new UsernamePasswordAuthenticationToken(userId, password));
} catch (AuthenticationException e) {
return false;
}
return true;
}
}
Run Code Online (Sandbox Code Playgroud)
它可以工作(布线本身),但是我不知道我应该重写更多的方法。
该代码检查给定的用户名和密码在Spring Security领域中是否正确。这够了吗?我确实阅读了Camunda的文档。它包含大约两行内容,说我应该实现ReadOnlyIdentityProvider或WritableIdentityProvider,但是我认为实现每种方法都不过分。这就是为什么我扩展了DbReadOnlyIdentityServiceProvider的原因。
谢谢!
与此同时,Camunda 7.9 引入了 ContainerBasedAuthenticationFilter,它可以与自定义 Camunda AuthenticationProvider 结合使用。
这是将 Camunda >=7.9 与 Spring Security 集成的完整示例: https://github.com/camunda-consulting/code/tree/master/snippets/springboot-security-sso
| 归档时间: |
|
| 查看次数: |
829 次 |
| 最近记录: |