Skip to content

scaredmeow/spring-chainsLog

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

23 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

spring-chainsLog

A CRUD Spring Boot project focused in building discussion board for web 3.0. To see the full website visit https://chainslog.herokuapp.com/.

Tech Stack Used

Spring SpringSecurity Thymeleaf CSS3 MySQL

Requirements

For building and running the application you need:

Running the application locally

This project is done through Eclipse IDE, to run the application locally open projects from file system and select the project, then run as spring application.

Alternatively you can use the Spring Boot Maven plugin like so:

get dependencies

mvn clean install

run application locally

mvn spring-boot:run

Screenshots

Landing Page image

Signin and Signup Pages image image

Forum Page image

Create a New Post Page image

Post Page image

Implementation of Frameworks

SpringSecurity

  • Used in: Authentication and Route Protection [AuthService, Home Controller]
  • Reference Video: Spring Boot Security Fundamentals
  • How it is implemented in the project?:
    • Initial Setup for Spring Security (Dependency)

       <dependency>
         <groupId>org.springframework.boot</groupId>
         <artifactId>spring-boot-starter-security</artifactId>
       </dependency>
    • To configure spring security, create a SecurityConfiguration that extends WebSecurityConfigurerAdapter.

      1. Override two configure methdos (AuthenticationManagerBuilding and HttpSecurity)
      2. HttpSecurity focuses on route protection and must be user defined based on roles and authentication;
      3. Additionally, to interact with the session token the following must be also configure: Login, Logout, RememberMe.
      4. AuthenicationManagerBuilder focuses on authentication of the account, which needs to configure the following two beans;
      5. DaoAuthenticationProvider to get the input and validate the input from database using the UserAccountService, while
      6. Password Encoder is a spring security features that uses bycrpy to encrypt passwords before receiving and sending in databases.
    • Next, is configure the UserAccount Model;

      1. UserAccount will implements the UserDetails from Spring Security to access its internal model for users,
      2. Then map the username/email, password to your existing User model.
      3. [Optional], you can also implement custom properties in this model to be accessed in session token.
    • For the UserAccount Service,

      1. UserAccount service will implement the UserDetailsService from Spring Security to retrieve the user details from the database.
      2. Create a Data Access Object (Dao) that will find user using username.
      3. Assign the user to the UserAccount Model you configure earlier.
    • Additional Steps,

      1. You can interact directly to spring security if you are currently using thymeleaf.
      2. Include in the pom.xml the following dependency:

       <dependency>
         <groupId>org.springframework.boot</groupId>
         <artifactId>spring-boot-starter-thymeleaf</artifactId>  
       </dependency>

Thymeleaf

  • Used in: Frontend [Template]
  • Reference Link: Baeldung Thymeleaf Fundamentals
  • How it is implemented in the project?:
    • Initial Setup for Thymeleaf (Dependency)
       <dependency>
           <groupId>org.springframework.boot</groupId>
           <artifactId>spring-boot-starter-security</artifactId>
       </dependency>
    • Integrating Thymeleaf in templates
      1. Create a HTML file in resources/templates.
      2. Include the following attributes in the HTML Tag;
       <html xmlns:th="http://www.thymeleaf.org"
           xmlns:sec="http://www.thymeleaf.org/extras/spring-security"
           lang="en">
    • Using Thymeleaf Fragments
      1. Create fragments.html which you will put all of your thymeleaf fragments in project.
      2. Suggested fragments is head (if you will not use JS), navbar and repetitive components in your web app.
      3. To define a thymeleaf fragment include in the opening tag the attribute th:fragment="<name-of-fragment>"
      4. To use the defined fragment on other pages use the attribute th:replace="<html-of-your-fragments> :: <name-of-fragment>"
    • Using Thymeleaf Links/URL
      1. To link an image in your thymeleaf page, use the ordinary <img> tag with the following attribute, th:src="@{/link}"
      2. Similar with the <a> and other tags that utilizes links, you must append th: in the beggining of attribute and define the link as @{/link}
    • Using Thymeleaf Conditionals
      1. In a scenario that you need to display something base on a variable (defined by `${var}), you can use conditionals directly in thymeleaf.
      2. th:if="${var}" is used to display a html tag when the var is true,
      3. Vice versa, th:unless="${true}" is used to NOT display a html tag when the var is true.
      4. sec:authorize="isAuthenticated()" is used to display a html tag if the user is authenticated.
      5. Vice versa, sec:authorize="isAnonymous()" is used to display a html tag if the user is anonymous.
    • Other usage of Thymeleaf in Project
      1. th:text="${var} / <text> is used to replace the text of the current tag.
      2. th:each="var-name: ${var-list}" is used to repetively create a html tag based on the current var-list.

Contact

github linkedin gmail Calendly