Giter Site home page Giter Site logo

spring-security-simple-factor-auth's Introduction

spring-security-simple-factor-auth

Spring Security - Simple factor auth

Do zarządzania Spring Security została utworzona klasa WebSecurityConfig która dziedziczy po klasie WebSecurityConfigurerAdapter

W tej klasie nadpisujemy metody configure(AuthenticationManagerBuilder auth) i metode configure(HttpSecurity http)

W metodzie configure(AuthenticationManagerBuilder) podajemy klasę która implementuje interfejs UserDetailsService. Tutaj będzie umieszczona logika która będzie sprawdzać czy wprowadzony przez użytkownika login i hasło jest prawidłowe.

W drugiej metodzie configure(HttpSecurity http) możemy określić jakie uprawnienia mają określeni użytkownicy. Każdy użytkownik ma przypisaną rolę (ROLE_ADMIN, ROLE_USER) Na podstawie tej roli możemy w tej metodzie napisać logikę określającą prawa dostępu do konkretnego zasobu.

W klasie MailService jest prosta implementacja logiki wysyłania maili do zarejestrowanych użytkowników w celu potwierdzenia swojego adresu email.

Do tego celu potrzebujemy konta email z którego będą wysyłane wiadomości. W tym celu dodajemy odpowiednią konfigurację do application.properties, gdzie podajemy również nasze dane do maila

spring.mail.host=smtp.gmail.com spring.mail.port=587 spring.mail.username=todo spring.mail.password=todo spring.mail.properties.mail.smtp.auth=true spring.mail.properties.mail.smtp.starttls.enable=true

Aby wysyłka maili działa trzeba wejść w opcje skrzynki pocztowej -> Bezpieczeństwo -> Dostęp mniej bezpiecznych aplikacji -> i tutaj Włącz dostę (Niezalecane)

spring-security-simple-factor-auth's People

Contributors

mmilak197 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.