26
26
import org .kie .kogito .internal .process .workitem .KogitoWorkItem ;
27
27
import org .kie .kogito .internal .process .workitem .NotAuthorizedException ;
28
28
import org .kie .kogito .internal .process .workitem .Policy ;
29
+ import org .slf4j .Logger ;
30
+ import org .slf4j .LoggerFactory ;
29
31
30
32
/**
31
33
* Security policy that delivers <code>IdentityProvider</code> to allow to security
34
36
*/
35
37
public class SecurityPolicy implements Policy {
36
38
39
+ private static final Logger LOGGER = LoggerFactory .getLogger (SecurityPolicy .class );
40
+
37
41
private IdentityProvider identity ;
38
42
39
43
/**
@@ -61,6 +65,8 @@ protected SecurityPolicy(IdentityProvider identity) {
61
65
62
66
@ Override
63
67
public void enforce (KogitoWorkItem workItem ) {
68
+
69
+ String actualOwner = workItem .getActualOwner ();
64
70
String actualOwners = (String ) workItem .getParameter ("ActorId" );
65
71
String actualRoles = (String ) workItem .getParameter ("GroupId" );
66
72
String excludedOwner = (String ) workItem .getParameter ("ExcludedOwnerId" );
@@ -71,11 +77,14 @@ public void enforce(KogitoWorkItem workItem) {
71
77
List <String > roles = actualRoles != null ? List .of (actualRoles .split ("," )) : new ArrayList <>();
72
78
List <String > userRoles = new ArrayList <>(identity .getRoles ());
73
79
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 );
79
88
}
80
89
}
81
90
}
0 commit comments