Skip to content

Commit

Permalink
[KOGITO-9650] Adding identity to SWF workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
fjtirado committed Aug 31, 2023
1 parent a3e2868 commit 167a697
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@
"type": "expression",
"operation": ".message |=.+\" and in my native language dog is translated to \"+$CONST.dog.castellano"
},
{
"name": "userMessage",
"type": "expression",
"operation": ".user |= $WORKFLOW.identity"
},
{
"name": "contextMessage",
"type": "expression",
Expand Down Expand Up @@ -96,6 +101,10 @@
"name": "costantMessageAction",
"functionRef" : "constantMessage"
},
{
"name": "userMessageAction",
"functionRef" : "userMessage"
},
{
"name": "contextMessageAction",
"functionRef" : "contextMessage"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ void testExpressionRest() {
.body("workflowdata.result", is(4))
.body("workflowdata.number", nullValue())
.body("workflowdata.message", is("my name is javierito and in my native language dog is translated to perro and the header pepe is pepa"))
.body("workflowdata.user", is("anonymous"))
.body("workflowdata.discardedResult", nullValue());
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/*
* Copyright 2023 Red Hat, Inc. and/or its affiliates.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.kie.kogito.serverless.workflow;

import java.util.Map;
import java.util.function.Function;

import org.kie.kogito.internal.process.runtime.KogitoProcessContext;
import org.kie.kogito.serverless.workflow.utils.KogitoProcessContextResolverExtension;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import io.quarkus.arc.Arc;
import io.quarkus.security.identity.SecurityIdentity;

public class QuarkusKogitoProcessContextResolver implements KogitoProcessContextResolverExtension {

private static final Logger logger = LoggerFactory.getLogger(QuarkusKogitoProcessContextResolver.class);

@Override
public Map<String, Function<KogitoProcessContext, Object>> getKogitoProcessContextResolver() {
return Map.of("identity", this::resolveInitiator);
}

private String resolveInitiator(KogitoProcessContext context) {
try {
SecurityIdentity identity = Arc.container().select(SecurityIdentity.class).get();
return identity.isAnonymous() ? "anonymous" : identity.getPrincipal().getName();
} catch (RuntimeException ex) {
logger.warn("Unable to resolve quarkus user identity", ex);
return null;
}
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
org.kie.kogito.serverless.workflow.QuarkusKogitoProcessContextResolver

0 comments on commit 167a697

Please sign in to comment.