Skip to content

It is a mock-up auth and resource server project with ADMIN and USER roles with redis integrated. WebSocket chatting is also added

Notifications You must be signed in to change notification settings

kerimdemir9/demo-auth-and-resource-server-with-redis

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Demo Auth and Resource Server

  • Implemented a Spring Authorization Server with a matching Resource Server that gets its JWT tokens from the Auth Server
  • Redis is integrated for demo purposes into the book controller
  • Chatting feature is also added using Websocket where users need to send JWT tokens obtained from the Auth Server while connecting to the socket for the first time and sending any messages
  • Users need to have Admin role to be able send broadcast messages
  • Sample endpoints are created to test role based auth inside helloController

API Usage

Login

  GET http://localhost:9000/api/login
Body Type Value
username string admin or user
password string admin or user

Register

  GET http://localhost:9000/api/register
Body Type Value
username string admin or user
password string admin or user
role string ["ADMIN", "USER"] or ["USER"]

Test Admin Role

  GET http://localhost:8888/hello-admin
Header Value
Authorization Bearer JWT_TOKEN

Test User Role

 GET http://localhost:8888/hello-auth
Header Value
Authorization Bearer JWT_TOKEN

Public URL

 GET http://localhost:8888/

Chatting Feature (with WebSockets)

Connect To Socket (token required)

http://localhost:8888/chat

Subscribe To Own Queue

'/user/${username}/queue/private'

Subscribe To Broadcast Channel

'/topic/public'

Send Private Message (token required)

'/app/private'

Send Broadcast Message (token required/only for admin)

'/app/broadcast'

DDL Script For Database Creation

create table books
(
 id     int auto_increment primary key,
 name   varchar(255) null,
 author varchar(255) null
);

create table user
(
 id            int auto_increment primary key,
 username      varchar(255)                        not null unique,
 password      varchar(255)                        not null,
 refresh_token text                                null,
 role          json                                not null,
 created       timestamp default CURRENT_TIMESTAMP null
);

create table messages
(
 id           int auto_increment primary key,
 message_from varchar(255) not null,
 message_to   varchar(255) null,
 text         varchar(255) not null,
 seen         tinyint(1)   not null,
 created      datetime     not null,
 type         varchar(255) not null,
 constraint messages_ibfk_1
     foreign key (message_from) references user (username)
         on delete cascade,
 constraint messages_ibfk_2
     foreign key (message_to) references user (username)
         on delete cascade
);

About

It is a mock-up auth and resource server project with ADMIN and USER roles with redis integrated. WebSocket chatting is also added

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages