Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[KOGITO-9650] Adding identity to SWF workflow #3201

Merged
merged 1 commit into from
Aug 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading