Session04 - Spring Security
Session04 - Spring Security
Objectives
• Authentication and Authorization
• JSON Web Token
• Spring Security
• Techniques
Authentication Authorization
1/ Password-Based Authentication JSON web token (JWT)
2/ Single Sign On (SSO)
Drawbacks:
• During each validation the Gmail server needs to fetch the information corresponding to it.
• Not suitable for micro services architecture involving multiple API's and servers
R2S Academy - Internal Use 7
Authentication and Authorization (6)
Example
• Using JWT for Authorization
JWT
Request
Authenticated
user?
return http.build();
}
R2S Academy - Internal Use 23
Spring Security (14)
Implement
• Configure WebSecurity (cont):
@Bean
public UserDetailsService userDetailsService() {
return username -> userRepository.findByUsername(username)
.orElseThrow(() -> new UsernameNotFoundException("User not found" + username));
}
@Bean
public AuthenticationProvider authenticationProvider() {
DaoAuthenticationProvider authenticationProvider = new DaoAuthenticationProvider();
authenticationProvider.setUserDetailsService(userDetailsService());
authenticationProvider.setPasswordEncoder(passwordEncoder());
return authenticationProvider;
}
@Bean
public AuthenticationManager authenticationManager(AuthenticationConfiguration config) throws Exception {
return config.getAuthenticationManager();
}
@Bean
public PasswordEncoder passwordEncoder() {
return new BCryptPasswordEncoder();
}
R2S Academy - Internal Use 24
Keeping up those inspiration and the enthusiasm in the learning path.
Let confidence to bring it into your career path for getting gain the success as
your expectation.
Thank you
Contact
- Name: R2S Academy
- Email: [email protected]
Questions and Answers
- Hotline/Zalo: 0919 365 363
- Website: https://r2s.edu.vn
- Fanpage: https://www.facebook.com/r2s.tuyendung