Code Monkey home page Code Monkey logo

spring-boot-angular-template's Introduction

Spring-Boot-Angular-Template

Build Status Quality Gate Status Coverage Technical Debt

Starter Template to create a OAuth2 secured dockerized Spring Boot 2.1 Application with Angular 8 Frontend.

A user with a Google- or Github-Account get access to the Application using OAuth2-Authentication, so no additional User Registration is required. A new user get the Default-Role ROLE_USER. Additional Roles, like ROLE_ADMIN for administrative access, can be assigned to a user through the Role-Management. The data get stored in a PostgreSQL database inside a Docker-Container.

Login-Screen

spring-boot-angular-login

Technology-Stack StackShare

spring-boot-angular-template-stack

Need to be installed on the OS to startup the application: Docker

Need to be installed on the OS for development purposes: Git, JDK 11, Maven, Lombok, Node.js, Angular-CLI

Getting Started

To get the application running, some configuration need to be to do.

Prerequisites

Step 1: Install Docker on your OS. Direct Download Links: Docker for Windows, Docker for Mac-OS

Step 2: After Docker is installed, go to the Docker-Settings and share the drive in which you will later download the latest Release of the Spring-Boot-Angular-Template. This is necessary for accessing the SQL-Files for setting up the database.

Obtaining API-Keys

To use the O2Auth-Authentication from Google or Github, we need to register this application to obtain the appropiate Client-ID and Client-Secret.


google

Step 1: Visit the Google Cloud Console

Step 2: Click on the Button Create Project

Step 3: In the following New Project-Dialog set as Project name spring_boot_angular_template and click on the Button Create

Step 4: On the top left, click on the Button with the three horizontal stripes to open the left-side Navigation-Menu. Select APIs & Services → Credentials

Step 5: In the Credentials-View click on the Button Create credentials and than select the Menu-Item OAuth client ID.

Step 6: In the Create OAuth client ID-Dialog type in following:

create oauth client id

Click than on the Create-Button.

Step 7: A dialog appears with a generated client ID and client secret which you need to copy for later usage.


github

Step 1: Visit the Github Account Settings

Step 2: Press on the left navigation side menu the Menu-Item Developer-Settings

Step 3: In the Developer-Settings, select on the left navigation side menu OAuth Apps and click on the Button Register a new application.

Step 4: In the Register a new OAuth application-Dialog type in following:

github-register-new-oauth-application

Click than on the button Register application

Step 5: In the following view copy the generated Client ID and Client Secret for later usage.

ℹ️
Unfortunately github is not allowing adding more than one Homepage URL and Authorization callback URL. So for development purposes using the Google-OAuth2 should be prefered.

Installing

Step 1: Download the latest Release to your working-directory and unzip the file with following commands:

$ wget https://github.com/mrrobworks/spring-boot-angular-template/releases/download/v0.1-alpha/spring-boot-angular-template.tar.gz
$ tar -xvzf spring-boot-angular-template.tar.gz

Step 2: Load the Docker-Image to your Local Docker Registry with:

$ docker load < docker-image.tar

Step 3: In the file docker-compose.ref.yml search for the following entries:

GOOGLE_CLIENT_ID: [google-client-id]
GOOGLE_CLIENT_SECRET: [google-client-secret]
GITHUB_CLIENT_ID: [github-client-id]
GITHUB_CLIENT_SECRET: [github-client-secret]

Replace [google-client-id], [google-client-secret], [github-client-id], [github-client-secret] with your copied values from the Obtaining API-Keys-Section.

Run the application

Now you can simply run the application with following steps:

Step 1: Type following:

$ docker-compose -f docker-compose.yml -f docker-compose.ref.yml up

Step 2: In your Webbrowser type http://localhost:8091 and the webapplication shows up.

Development

Before development getting started, we need a terminal for executing commands. If you are running a bash-shell on a Linux-Distrubtion or Mac-OS everything should be fine. The Windows Powershell and CMD could make some problems and the build-process fails. My recommendation is to install the Windows Subsystem for Linux (WSL) in Windows 10 and using the bash-shell from it. For further use of Docker in WSL follow the instructions described in this Blog-Post.

Now we need to install some additional software:

Step 1: Install Git, JDK 11, Maven and Node.js on your OS.

Step 2: Open a terminal and type

$ npm install -g @angular/cli

to install the Angular-CLI

Step 3: Open your IDE and install Lombok as a Plugin.

Now we can download and install the Spring-Boot-Angular-Template for development:

Step 1: Git-Clone the Spring-Boot-Angular-Template to your working directory with:

$ git clone https://github.com/mrrobworks/spring-boot-angular-template.git
$ cd spring-boot-angular-template

Step 2: In the application.dev.yml you will find following:

google:
  client:
    client-id: [google-client-id]
    client-secret: [google-client-secret]
github:
  client:
    client-id: [github-client-id]
    client-secret: [google-client-secret]

Replace [google-client-id], [google-client-secret], [github-client-id], [github-client-secret] with your copied values from the Obtaining API-Keys-Section.

Step 3: Install the application with the command:

$ ./mvnw clean install

To start the PostgreSQL database in a Docker-Container, open a terminal, change the location to the project-root directory and type following:

$  docker-compose -f docker-compose.yml -f docker-compose.dev.yml up

If you develop with IntelliJ IDEA there are also some Run-Configurations in the Project-Repository. Start the Run-Configurations docker-compose-DEV, backend-spring-boot-DEV and frontend-angular-DEV in IntellJ and you are ready to go. Open a webbrowser, type http://localhost:4200 and the webapplication shows up.

Troubleshooting

Trouble 1: When installing the application with ./mvnw clean install and you getting a error like this:

[ERROR] Get https://registry-1.docker.io/v2/: net/http: request canceled while waiting for connection (Client.Timeout exceeded while awaiting headers)
[WARNING] An attempt failed, will retry 1 more times
org.apache.maven.plugin.MojoExecutionException: Could not build image

then restart the Docker deamon and the error should be gone.

Trouble 2: Using CMD or Powershell in Windows and install the application with mvnw.cmd clean install it appears following:

[INFO] > cd bin && ng build --prod
[INFO]
[ERROR] 'ng' is not recognized as an internal or external command,
[ERROR] operable program or batch file.

This is usually a problem when installing the application with CMD or Powershell. The command ng from the Angular-CLI is not recognized correctly. You need to install Node.js and Angular-CLI and then set the corresponding Windows-Evironment-Path variables. Also you can change in frontend/package.json the following:

"scripts": {
    "ng": "ng",
    "start": "ng serve --proxy-config proxy.conf.json",
    "build": "ng build --prod",
    "test": "ng test",
    "lint": "ng lint",
    "e2e": "ng e2e"
  }

Trouble 3: Resolving EACCES permissions errors when installing packages globally

[INFO] Running 'npm install -g @angular/[email protected]' in /mnt/c/opt/workspace/intellij/spring-boot-angular-template/frontend
[ERROR] npm ERR! path /mnt/c/opt/workspace/intellij/spring-boot-angular-template/frontend/lib/node_modules/@angular/cli/node_modules/normalize-package-data[ERROR] npm ERR! code EACCES[ERROR] npm ERR! errno -13
[ERROR] npm ERR! syscall rename[ERROR] npm ERR! Error: EACCES: permission denied, rename '/mnt/c/opt/workspace/intellij/spring-boot-angular-template/frontend/lib/node_modules/@angular/cli/node_modules/normalize-package-data' -> '/mnt/c/opt/workspace/intellij/spring-boot-angular-template/frontend/lib/node_modules/@angular/cli/node_modules/.normalize-package-data.DELETE'

Follow the instructions from here.

TODOs

  • ❏ Redesign Angular-Frontend CSS

  • ❏ Replace some components in frontend (Checkbox)

  • ❏ Review Code in Frontend

  • ❏ WebMvcTest for REST-Controller (mockMvc)

  • ❏ Add Swagger Documentation for REST-Controllers

  • ❏ Swagger with OAuth2 or BasicAuth?

  • ❏ Add spring-boot-devtools?

  • ❏ Using EntityGraph for JPA (instead FetchType.EAGER)?

  • ✓ Fix .gitignore-File

  • ✓ Add Mockito Tests

  • ✓ Create ViewModel-Beans for each JPA-Model-Entity-Bean? Using Mapstruct.

  • ✓ Using var for local-variables

  • ✓ Microservices from this project for creating github-repositories

  • ✓ Remove Maven-Module dbsetup and move sql-Files to backend

  • ✓ Replace Liquibase with Flyway

  • ✓ Changing return types of REST-Controllers to ResponseEntity

  • ✓ User-Roles Access on custom sites / elements

  • ✓ Angular / CSS / Bootstrap (Angular-Material implemented)

  • ✓ Profile in OAuthSecurityConfiguration (Google, Github)

  • ✓ User-Role-assignment through webapplication

  • ✓ Save LoggedIn User to Session

  • ✓ CRUD Roles for Administrator of the Application

  • ✓ Building Docker-Image with Spring-Boot and Angular

  • ✓ Create schema.sql and data.sql for script based data initialization

  • ✓ Validation Rules in backend-model classes (Java Bean Validation API, JSR-303)

  • ✓ application.properties change to application.yml

  • ✓ Update README.md with actual installation instructions for development and how to setup Intellij / Docker.

  • ✓ application-external.properties to yml and add installation instructions to README.md

  • ✓ Login-Site Radio-Button Google and Github link to /login and /login/github

spring-boot-angular-template's People

Contributors

mrrobworks avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

spring-boot-angular-template's Issues

Add Typescript Code Coverage to sonar-project.properties

For the Java code coverage by SonarCloud the Jacoco Reports are being used. For Typescript code coverage something like

sonar.typescript.lcov.reportPaths=target/test-results/lcov.info

need to be added.

Links:

Writing frontend tests

Adding tests for following frontend test classes:

  • role-delete.component.spec.ts
  • role-detail.component.ts
  • role-list.component.ts
  • user-detail.component.spec.ts
  • user-detail.component.ts
  • user-list.component.ts

Writing backend tests

Following test classes have to be written:

  • AppRoleControllerTest
  • AppRoleRepositoryImplTest
  • AppRoleServiceImplTest
  • AppUserControllerTest
  • AppUserRepositoryImplTest
  • AppUserServiceImplTest

Optimize Docker Packaging

For running the Docker Package following steps are still to do:

TMP_REPO_DIR=https://raw.githubusercontent.com/mrrobworks/spring-boot-angular-template/master/
wget $TMP_REPO_DIR/docker-compose.yml
wget $TMP_REPO_DIR/docker-compose.ref.yml
mkdir -p ./backend/src/main/resources/db/migration/
wget -P ./backend/src/main/resources/db/migration/ $TMP_REPO_DIR/backend/src/main/resources/db/migration/V0_1__init.sql
wget $TMP_REPO_DIR/wait-for.sh

This can be reduced to:

TMP_REPO_DIR=https://raw.githubusercontent.com/mrrobworks/spring-boot-angular-template/master/
wget $TMP_REPO_DIR/docker-compose.yml
wget $TMP_REPO_DIR/docker-compose.ref.yml

To do so, it is necessary to replace the dockerfile-maven-plugin vom spotify with the docker-maven-plugin from fabric8io (https://github.com/fabric8io/docker-maven-plugin). With this multiple Docker images can be build, which is necessary to put the missing files in these images.

Improve .gitignore file

The files in .idea/sonarlint/** are not being ignored and are untracked in the working tree from Git. Further more the .gitignore file need to be cleaned up.

Log in to top navigation bar

  • In the top navigation bar add a new entry Sign in or Log in
  • Remove Log in site from home site
  • When click on Log in in the top navigation bar open the Login site

CSS adjustments

  • Create a clean CSS design across all frontend sites
  • Remove unnecessary style definitions and place them in CSS files

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.