Skip to content

Commit 4bc99f1

Browse files
committed
fix workitems and user tasks
1 parent 4ca4ea0 commit 4bc99f1

File tree

3 files changed

+373
-376
lines changed

3 files changed

+373
-376
lines changed

api/kogito-api/src/main/java/org/kie/kogito/auth/SecurityPolicy.java

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@
2626
import org.kie.kogito.internal.process.workitem.KogitoWorkItem;
2727
import org.kie.kogito.internal.process.workitem.NotAuthorizedException;
2828
import org.kie.kogito.internal.process.workitem.Policy;
29+
import org.slf4j.Logger;
30+
import org.slf4j.LoggerFactory;
2931

3032
/**
3133
* Security policy that delivers <code>IdentityProvider</code> to allow to security
@@ -34,6 +36,8 @@
3436
*/
3537
public class SecurityPolicy implements Policy {
3638

39+
private static final Logger LOGGER = LoggerFactory.getLogger(SecurityPolicy.class);
40+
3741
private IdentityProvider identity;
3842

3943
/**
@@ -61,6 +65,8 @@ protected SecurityPolicy(IdentityProvider identity) {
6165

6266
@Override
6367
public void enforce(KogitoWorkItem workItem) {
68+
69+
String actualOwner = workItem.getActualOwner();
6470
String actualOwners = (String) workItem.getParameter("ActorId");
6571
String actualRoles = (String) workItem.getParameter("GroupId");
6672
String excludedOwner = (String) workItem.getParameter("ExcludedOwnerId");
@@ -71,11 +77,14 @@ public void enforce(KogitoWorkItem workItem) {
7177
List<String> roles = actualRoles != null ? List.of(actualRoles.split(",")) : new ArrayList<>();
7278
List<String> userRoles = new ArrayList<>(identity.getRoles());
7379
userRoles.retainAll(roles);
74-
String actualOwner = workItem.getActualOwner();
75-
if (actualOwner != null && !identity.getName().equals(actualOwner)) {
76-
throw new NotAuthorizedException("this work item " + workItem.getStringId() + " is not allows by this owner" + actualOwner);
77-
} else if (!owners.contains(identity.getName()) && userRoles.isEmpty()) {
78-
throw new NotAuthorizedException("this work item " + workItem.getStringId() + " is not allows by this owner" + actualOwners + " or " + actualRoles);
80+
LOGGER.info("enforcing identity {} and roles {} with potential owners {} and potential groups {} and exclude groups {}",
81+
identity.getName(), identity.getRoles(), owners, roles, excluded);
82+
if (!owners.contains(identity.getName()) && userRoles.isEmpty()) {
83+
LOGGER.error("not authorized with owner {} against identity {}", actualOwner, identity.getName());
84+
throw new NotAuthorizedException("this work item " + workItem.getStringId() + " is not allows by this owner " + actualOwners + " or " + actualRoles);
85+
} else if (userRoles.isEmpty() && actualOwner != null && !identity.getName().equals(actualOwner)) {
86+
LOGGER.error("identity {} with roles {} not authorized in {}", identity.getName(), identity.getRoles(), roles);
87+
throw new NotAuthorizedException("this work item " + workItem.getStringId() + " is not allows by this owner " + actualOwner);
7988
}
8089
}
8190
}

0 commit comments

Comments
 (0)