User manager is responsible to handle authentication process inside MODAPTO. It connects with Keycloak and routes all requests to authenticate users, refresh tokens, manage users and request information regarding their authorization in the system.
It exploits OAuth2.0 and OpenID protocols integrated with Spring Security with configured Request Filters to increase the security of the application and generate JWT Tokens for users.
-
Clone the repository:
git clone https://github.com/Modapto/access-control.git cd access-control
-
Install the dependencies:
mvn install
-
Instantiate an instance of Keycloak with PostgreSQL and configure the following variables in the application properties:
spring.security.oauth2.resourceserver.jwt.issuer-uri=${KC_ISSUER_URI:###} spring.security.oauth2.resourceserver.jwt.jwk-set-uri=${spring.security.oauth2.resourceserver.jwt.issuer-uri}/protocol/openid-connect/certs keycloak.token-uri=${KC_TOKEN_URI:###} keycloak.admin.uri=${KC_ADMIN_URI:###} keycloak.client-id=${KC_CLIENT_ID:###} keycloak.client-secret=${KC_CLIENT_SECRET:###} keycloak.admin-username=${KC_ADMIN_USERNAME:###} keycloak.admin-password=${KC_ADMIN_PASSWORD:###} keycloak.realm=${KC_REALM:###} keycloak.auth-server-url=${KC_AUTH_SERVER:###} spring.mail.username = ${GMAIL_USERNAME:MODAPTO} spring.mail.password = ${GMAIL_APP_PASSWORD:###}
-
If deployed via Docker Compose file the following variables must be set in the .env file:
POSTGRES_USER= POSTGRES_PASSWORD= KEYCLOAK_ADMIN_USER= KEYCLOAK_ADMIN_PASSWORD= PGADMIN_DEFAULT_EMAIL= PGADMIN_DEFAULT_PASSWORD= HOST_IP= MAIL_USERNAME= MAIL_PASSWORD=
-
Upon the usage of the Component, when creating a new User, an activation process is followed as displayed below:
a. Super Admin / Admin creates a new User
b. An activation token and expiration time are generated as attributes of User, which is initialized as disabled User
c. An email is sent to the designated email address with the token value that must be passed along with the new password for the user to be enabled to MODAPTO system.
-
Run the application after Keycloak is deployed:
mvn spring-boot:run
-
The application will start on
http://localhost:8093
. -
Access the OpenAPI documentation at
http://localhost:8093/api/user-manager/swagger-ui/index.html
. -
Set up properly the Identity Manager described in the next section
-
NOTE: To use the app and its APIs a user must be initially authenticated in the platform (/api/users/authenticate). Depending on the action, some requests would require specific privileges according to the user type (Super Admin, Admin, User).
On folder Keycloak Realm Data two files can be located:
-
modapto-dev-realm.json : Configuration of modapto-dev realm
-
modapto-dev-users.json : Two initial users for MODAPTO. More user can be created as requested
Upon the initialization of Keycloak container, we implement the following steps to initialize the realm:
-
Press to create a new Realm
-
Upload the modapto-dev-realm.json
-
Press create realm
To accordingly upload the initial users in the system:
-
Navigate to Realm Settings
-
On the top right corner of UI press "Action"
-
Select "Partial Import"
-
Upload the modapto-dev-users.json file
-
Select the box for user creation and set the resource strategy to overwrite / skip
-
Press "Import"
For the created Users you can use the following credentials (username / password):
-
CRF User: [email protected] / CRF@user123@
-
Super Admin: [email protected] / S@admin123@
Current configuration of Keycloak Roles, User Attributes, Clients and Realm Roles is depicted in the following images.
For local deployment Docker containers can be utilized to deploy the microservice with the following procedure:
-
Ensure Docker is installed and running.
-
Build the maven project:
mvn package
-
Build the Docker container:
docker build -t modapto-user-manager .
-
Run the Docker container including the environmental variables:
docker run -d -p 8093:8093 --name modapto-user-manager modapto-user-manager
-
To stop container run:
docker stop modapto-user-manager
Along with the Spring Boot application docker container in the project repository there is a Docker Compose file to instantiate a local instance of Keycloak and PostgreSQL. Create an .env file to include the corresponding environmental variables.
This project has received funding from the European Union's Horizon 2022 research and innovation programm, under Grant Agreement 101091996.
For more details about the licence, see the LICENSE file.
- Alkis Aznavouridis ([email protected])