What is the simplest way to add application users in a Thorntail WildFly server?

前端 未结 2 1960
不知归路
不知归路 2021-01-25 12:09

As said in the title, is there a way to add application users in Thorntail WilFly server, much like you would do with \"add-user.sh -a\" script in the full server distribution?

2条回答
  •  南方客
    南方客 (楼主)
    2021-01-25 12:59

    The answer by Thomas Herzog is very good from a conceptual point of view -- I'd especially agree with securing the application using an external Keycloak, potentially with the help of MicroProfile JWT. I'm just gonna provide a few points in case you decide not to.

    You can define users directly in project-defaults.yml, like this:

    thorntail:
      management:
        security-realms:
          ApplicationRealm:
            in-memory-authentication:
              users:
                bob:
                  password: tacos!
            in-memory-authorization:
              users:
                bob:
                  roles:
                  - admin
    

    The project-defaults.yml file doesn't have to be external to the app, you can build it directly into it. Typically, in your source code, the file will be located in src/main/resources, and after building, it will be embedded inside the -thorntail.jar. It can be external, of course, and if this is something else than a throwaway prototype or test, sensitive data like this should be external.

    You can also use the .properties files from WildFly:

    thorntail:
      management:
        security-realms:
          ApplicationRealm:
            properties-authentication:
              path: .../path/to/application-users.properties
            properties-authorization:
              path: .../path/to/application-roles.properties
    

提交回复
热议问题