Skip to content

phclummia/spring-security

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Spring Security Studies

This application developed for Spring Security capabilities. At the beginning there exist only one endpoint without security.
In time I will add new branches with different capabilities.

Branch oauth2

With this branch integrated oauth2 with a Third Party Identity and Access Management. Related articles about install IAM as Docker, Initialize Configuration's of IAM and Integrate Sprint Boot Security
Keycloak : link
Initialize and Integrate : link

File Description
create.sql Table changed to a private resource which only authenticate user can select
data Removed old repository, add new repository
service Removed old service, add new service
application.yml Added new Keycloak configurations under keycloak
templates Added basic html pages
WebSecurityConfig.java Updated according to oauh2 and Keycloak
WebController.java Added html's controllers
pom.xml Added new dependencies

** Some files deleted. You can check these files over history or other branches.

Keycloak Generate Token

Keycloak Generate Token

Public Page

Public Page

Keycloak Login Page

Keycloak Login Page

Private Page

Private Page

Branch database-customization

With this branch jdbcAuthentication customized specific user table. With new table need to implement new table repository.

Changelog

File Description
create.sql Create Table and Insert Queries changed according to column's names
data Added data package for JPA flows
service Added service package to access repository
CustomAuthenticationProvider.java Added CustomAuthenticationProvider to check over custom table
application.yml Added new database name and added minor hibernate config physical-strategy

spring.jpa.hibernate.ddl-auto

JPA DDL-UPDATE

spring.jpa.hibernate.physical-strategy

JPA DDL-UPDATE

Branch jdbc-authentication

With this branch inMemoryAuthentication convert to jdbcAuthentication.
For jdbc authentication you need valid database and tables structure.

There is valid database

If you have valid database, you can run create.sql for creating tables and relations.
After that you need to update application.yml related datasource details.

    spring:
      datasource:
        url: jdbc:mysql://localhost:3306/workshop_security
        username: root
        password: pass
        driver-class-name: com.mysql.cj.jdbc.Driver

There isn't valid database (Docker Solution)

If you don't have valid database, you can use docker-compose.yml for creating database, tables and relations in a container.
Run the below command in the docker directory.

    docker-compose -f "docker-compose.yml" up -d --build

If you use this solution, you don't need to update application.yml

Branch security-first-init

With this branch added features detailed below.

Feature Description
pom.xml Added Spring Security dependencies to pom.xml
WebSecurityConfig.java Added inMemoryAuthentication to REST API

Technologies

The project is built on Spring Boot architecture. Maven used as build automation tool.

Project Setup

  • You need valid database, tables and relations. At branch change notes there is two solutions for database requirements.

  • Make sure to be in the root directory

  • Run the command to run the project locally:

mvnw spring-boot:run
  • Run the command to run the tets:
mvnw test
  • Run the command to create runnable jar file:
mvnw package

API Endpoints

GET Endpoint /api/v1/security/get/

This endpoint return SecurityResponse object. That means successfully access the resource.

Authentication Detail

Authentication Type User Name Password
Basic Authentication user pass

Response

    {
  "id": 7919202912837799685,
  "key": "Resource Key",
  "value": "Resource Value"
}

POST Endpoint /api/v1/security/post/

This endpoint return SecurityResponse object. That means successfully access the resource.

Authentication Detail

Authentication Type User Name Password
Basic Authentication user pass

Request

    {
  "key": "Resource Key",
  "value": "Resource Value"
}

Response

    {
  "id": 7919202912837799685,
  "key": "Resource Key",
  "value": "Resource Value"
}