UAA with LOCAL authentication: Run code as user?

This is a “simulator” based on the A12 project template that runs only internally (as a stand-in for a component that will later be developed externally), so for simplicity we are using LOCAL authentication with UAA.

There should be some REST endpoints that can be called without authentication.
In the implementation, however, I need to read/write some A12 documents.
Currently, that fails (understandably) with a Spring AccessDeniedException.

How can I make my code run in the context of a specific local user?
I tried battling with Spring’s Run-As Authentication, but without success so far.

hi,

I think the backend-authentication feature from UAA is what you are looking for.
You can refer

Cheers,
Nguyen

Thanks a lot! That turned out to be easy :smiley:

Couple remarks:

  • Docs for “pure Spring” (is anyone still using Spring without Boot?) versus “Spring Boot” could be clearer

    • Docs “4.1.1. Spring Application”: Yes, I have a Spring application, so I went ahead and added the configuration class to my sources. Then in “4.1.2 Spring Boot Application” I also added the auto-configuration - which breaks the configuration. It’s pretty clear after having made that mistake, but maybe add to “4.1.1.”:

    In a pure Spring application (without Spring Boot) the following dependency needs to be added:

    Plus maybe switch the sections so that Spring Boot is mentioned first?

  • “4.2. Setting up a backend user”

    • Small typo (“will create a user”):

      Based on the configuration the module will create a use with given username with regular privileges or all privileges.

    • What exactly are “regular privileges”?
  • “4.3 Custom user loader implementation”
    I thought it is safer to not generate a user in the fly, but configure a user (my app uses local authentication) with exactly the rights needed and use that. My understanding from reading this section is that the code given in YamlBackendUserLoader does exactly that. Two problems:

    • It does not even compile, because there is no method localUserManager.createUser
      I changed that to localUserManager.createPrincipal
    • but apparently that isn’t right, either. At runtime, before my annotated method is even invoked, the loadUser() method is called with user name “superUser”, which I haven’t even set-up anywhere and promptly fails.
      So clearly, I don’t understand understand it well enough, yet.