Git Product home page Git Product logo

jwt-spring-boot-3.0.2's Introduction

jwt-spring-boot-3.0.2

Proyecto básico para la implementación de Autenticación y Autorización con Spring Boot + Spring Security + JWT + MySql

Acceso Base Datos

  • Recuerde crear su base de datos antes de ejecutar el proyecto y actualizar el nombre de la misma en el archivo configuration.properties.
  • El proyecto esta configurado para conectarse a una base de datos MYSQL pero puede cambiar en el configuration.properties las propiedades de conexión que se ajusten a su base de datos.

Tablas

Al ejecutar el proyecto por primera vez se crearan dos tablas en tu base de datos

  • Rol - En esta tabla es necesario insertar los dos roles que maneja el ejemplo, estos roles son ADMINISTRADOR, USUARIO_RESTRINGIDO, los nombres de usuarios los puede adaptar a sus necesidades
  • Usuario - En esta tabla el sistema guardara el nuevo usuario con una referencia al ROL al que pertenece el usuario. La entidad usuario implementa la interfaz UserDetails de spring security que le ayuda a saber como obtener la informacion del usuario por ejemplo el username y si el usuario esta activo o no.

Rutas Sin Proteccion

  • Puede revisar en la clase ConfiguracionSeguridad las rutas permitidas como usuario anónimo. Las demas rutas es obligatorio enviar el token en la peticion y en dependencia del ROL permitido para el metodo podremos o no acceder al recurso.

EndPoint o URL

JSON ENTRADA

{
    "nombreUsuario": "administrador",
    "clave" : "123",
    "rol": "ADMINISTRADOR"
}

JSON SALIDA

{
    "id": 1,
    "nombreUsuario": "administrador",
    "rol": "ADMINISTRADOR",
    "token": null
}

JSON ENTRADA

{
    "nombreUsuario": "administrador",
    "clave" : "123"
}

JSON SALIDA

{
    "id": 1,
    "nombreUsuario": "administrador",
    "rol": "ADMINISTRADOR",
    "token": "eyJhbGciOiJIUzM4NCJ9.eyJzdWIiOiJhZG1pbmlzdHJhZG9yIiwiZXhwIjoxNjc1NTcwOTkzfQ.TdjXBEVgSxsPvScrQwhs3Fuwj-bTo_KO3LYckXJ0Fsoi_rDfA9KHPf9w0wdFEA7a"
}

Cada vez que se ejecute el método login se genera un token que tendrá una validez de 1h

Bono

No es una buena practica exponer en nuestros endpoint nuestras entidades, esto es algo comun en la mayoria de los cursos de programacion que se encuentran en la red. Es por eso que aqui les dejo tambien un pequeño ejemplo de como podemos recibir y devolver DTO sin exponer nuestra entidad.

Para este ejemplo se uso mapstruct para convertir el UsuarioDTO -> Usuario y Usuario -> UsuarioDTO.

jwt-spring-boot-3.0.2's People

Contributors

yoelvysmartinez avatar

Stargazers

Jeet Panchal avatar Daniel Gibran Hinostrosa Villa avatar  avatar  avatar Federico Silva avatar Josue Getsemani Sandoval Villarreal avatar Darwin Zaldaña avatar Raul Moreno avatar  avatar  avatar  avatar JoeyKo avatar Miguel A. Martínez B.  avatar Maximiliano Sandoval avatar  avatar Marco Zuniga Ugalde avatar Mario Amarilla avatar  avatar Daniel Vasquez A avatar Emmanuel Montiel Cruz avatar Óscar Orlando Rodríguez Cristancho avatar AKBiofröst avatar Jonathan Moscoso avatar Salvador Pocasangre avatar Luis Gerardo Ramírez Cabrera avatar Antony Quintero avatar Mauricio Meneses avatar David McEwen avatar Salvador  German avatar Francisco Nasta avatar Ariel Santos avatar Yonathan Román avatar Bryan Méndez avatar Marcos avatar Cristian España  avatar Clever Rivera avatar TonalliC.S.  avatar Diego Vicente avatar Kevin Benítez avatar Rommel Valdiviezo avatar Lucas Ariel Franco avatar

Watchers

 avatar Cristian España  avatar

jwt-spring-boot-3.0.2's Issues

Suggestion to add a license file to the repository

Hello! I came across your code and I was wondering if you have considered adding a license file to your repository. A license file is a way of letting others know how they can use or modify your code legally. Without a license file, your code is technically not open source and no one can use it without your permission. This might limit the potential impact and reach of your project. GitHub recommends that you include a license in your repository to let others know how can your code be used and built upon (Source: Licensing a repository). If you are interested in making your project open source, you can check out Choosing a license to learn more about the different types of licenses and their benefits.

To add a license file to your repository, you can follow the steps in this guide: Adding a license to a repository. You can also read this article for more information on open source licensing: Open Source Licensing Guide.

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.