Uploaded image for project: 'Kogito'
  1. Kogito
  2. KOGITO-2754

Processes: Move policy handling out of REST endpoint

XMLWordPrintable

    • Icon: Task Task
    • Resolution: Done
    • Icon: Major Major
    • None
    • None
    • Core Engine
    • None
    • 2020 Week 34-36 (from Aug 17)

      Currently REST endpoints generate a protected policies() method which always resolves to the same body:

            protected Policy[] policies(String user, List<String> groups) {
                if (user == null) {
                    return new Policy[0];
                }
                org.kie.kogito.auth.IdentityProvider identity = null;
                if (user != null) {
                    identity = new org.kie.kogito.services.identity.StaticIdentityProvider(user, groups);
                }
                return new Policy[] { SecurityPolicy.of(identity) };
            }
      
      

      There are also isolated usages of the sole lines:

                org.kie.kogito.auth.IdentityProvider identity = null;
                if (user != null) {
                    identity = new org.kie.kogito.services.identity.StaticIdentityProvider(user, groups);
                }
      

      Move this code to one or more utility classes that we invoke statically in the generated code.
      Alternatively, if we want to retain "customizability", we can scaffold a separate class with the method
      and invoke the method of that class. In this case, the class may be also @Singleton and @Inject'ed
      e.g.:

          @Singleton
          class MyProcessPolicies implements ProcessPolicies {
              public IdentityProvider identityProvider(String user, List<String> groups) {
                  org.kie.kogito.auth.IdentityProvider identity = null;
                  if (user != null) {
                      identity = new org.kie.kogito.services.identity.StaticIdentityProvider(user, groups);
                  }
              }
              public Policy[] of(String user, List<String> groups) {
                  if (user == null) {
                      return new Policy[0];
                  }
                  org.kie.kogito.auth.IdentityProvider identity = identityProvider(user, groups);
                  return new Policy[] { SecurityPolicy.of(identity) };
              }
      
      
          }
      
          // usage:
                @Inject ProcessPolicies policies;
                org.kie.kogito.auth.IdentityProvider identity = policies.of(user, groups);
      
      

      We should be able to generate this only once, and globally for all processes.

      see also https://gist.github.com/evacchi/d0ee8b08d6fe97c909568a1ae24f4fd4 for a more comprehensive example

              ftirados Francisco Javier Tirado Sarti
              evacchi Edoardo Vacchi (Inactive)
              Marian Macik Marian Macik
              Marian Macik Marian Macik
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

                Created:
                Updated:
                Resolved: