Hello,
I have a question regarding non-user-request triggered code in the Workflow-Service application (fullstack template, old WF architecture) . It looks similar to a former question of mine: Approach for dealing with security context in the case of scheduled methods but there are differences.
Our workflow services application has set mgmtp.a12.uaa.authentication.client.rest.authentication-type=DELEGATED which means that in order to use the DataServices RPC client, it reuses (delegates) the UAA token provided by the client, e.g. when a user clicks “start process”.
Now, we want to implement a @Scheduled bean which periodically loads data from another system and wants to create DS documents and start Camunda processes. However, we have trouble to authenticate the DS REST client request in this scenario.
What we tried already is to wrap the REST client calling code with code which sets a security context, like this.
@Component
public class SystemUser {
private final ModulFUser user = PermissionHelper.createTechnicalUser(AuthConstants.ADMIN,
List.of(new SimpleGrantedAuthority(AuthConstants.ADMIN)));
public void execute(final Runnable function) {
DelegatingSecurityContextRunnable.create(function, createSecurityContext()).run();
}
private SecurityContext createSecurityContext() {
final SecurityContext context = SecurityContextHolder.createEmptyContext();
context.setAuthentication(new UsernamePasswordAuthenticationToken(user, "", user.getAuthorities()));
return context;
}
}
Unfortunately, this does not work:
java.lang.NullPointerException: Cannot invoke "com.mgmtp.a12.uaa.client.rest.auth.AuthorizationData.getAuthenticationTokenType()" because "credentialData" is null
at com.mgmtp.a12.uaa.client.rest.auth.internal.AuthorizationInterceptor.intercept(AuthorizationInterceptor.java:53)
at org.springframework.http.client.InterceptingClientHttpRequest$InterceptingRequestExecution.execute(InterceptingClientHttpRequest.java:93)
at org.springframework.http.client.InterceptingClientHttpRequest.executeInternal(InterceptingClientHttpRequest.java:77)
at org.springframework.http.client.AbstractBufferingClientHttpRequest.executeInternal(AbstractBufferingClientHttpRequest.java:48)
at org.springframework.http.client.AbstractClientHttpRequest.execute(AbstractClientHttpRequest.java:66)
at org.springframework.web.client.RestTemplate.doExecute(RestTemplate.java:782)
at org.springframework.web.client.RestTemplate.execute(RestTemplate.java:717)
What we tried before is to switch to authentication mode CERTIFICATE which works technically but does not meet our business requirements, because in the standard use case that a user starts a process, we need the user information (who created a document) in DS also.
What is your advice, here?
And a subsequent question: does mgmtp.a12.uaa.authentication.client.rest.authentication-type=DELEGATED apply to both, the DS REST client and the Camunda service REST client? So once we have a solution, will it also work for requests to Camunda?
Thanks in advance,
Rainer.