Coder Social home page Coder Social logo

cindoddcindy / springboot-haversine-jwt Goto Github PK

View Code? Open in Web Editor NEW

This project forked from alaamezian/springboot-haversine-jwt

1.0 1.0 0.0 82 KB

this repository contains a demonstration on how to use haversine formula to get the nearest locations to a given location with in distance ,also the project is built around jwt authentication and role based access authorization using spring boot framework ,please consider rating and leaving a start if you find it useful

Java 100.00%

springboot-haversine-jwt's Introduction

SpringBoot-Haversine-Jwt

this repository contains a demonstration on how to use haversine formula to get the nearest locations to a given location with in distance ,also the project is built around jwt authentication and role based access authorization using spring boot framework ,please consider rating and leaving a start if you find it useful

What is Haversine Formula

this is a formula that is used to calculate the distance between 2 location and it goes as the following : a = sin²(Δφ/2) + cos φ1 ⋅ cos φ2 ⋅ sin²(Δλ/2) c = 2 ⋅ atan2( √a, √(1−a) ) d = R ⋅ c where φ is latitude, λ is longitude, R is earth’s radius (mean radius = 6,371km); note that angles need to be in radians to pass to trig functions!

How Can We Make A good Use of it

imagine you have a list of long and lat of locations in a database and a user provided you with his location ,using haver sine formula we can do magic, haver sine going to calculate the distance between the user location and a given point so we can then use it ,to display locations near user with in a radius .

other use we can query directly to the data base using haversine forumla which mean we can retrive entites based on there locations with in distance from neareast to farthest using this magical query

💥💥

static String HAVERSINE_PART = "(6371 * acos(cos(radians(:latitude)) * cos(radians(c.latitude)) * cos(radians(c.longitude) - radians(:longitude)) + sin(radians(:latitude)) * sin(radians(c.latitude))))";

	@Query("SELECT c FROM Client c WHERE " + HAVERSINE_PART + " < :distance ORDER BY " + HAVERSINE_PART + " DESC")
	public List<Client> findClientWithNearestLocation(@Param("latitude") double latitude,
			@Param("longitude") double longitude, @Param("distance") double distance);

Jwt authentication And Role Based Access

also in this repository you will find an insight on how to implement role based authorization and jwt athentication

What is Jwt Authentication ?!

its an authentication mechanism based aroud if user is authenticated he/she will obtain an encrypted token and that token will be used to authenticate the user ,the user will provide the token on each request and the server will decide if its a valid token or not and then grant access for the user on that resource.

we integrated role based access by putting the role of the user inside the token and then use spring security annotations such as @PreAuthorized("hasRole('ROLE-CUSTOMER')") to know whether the user is authorized to perform an action / get access to a specific end point

please feel free to rate ⭐ happy programming 😃 ✌️

Tweet

springboot-haversine-jwt's People

Contributors

alaamezian avatar

Stargazers

 avatar

Watchers

 avatar

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.