Skip to content

Instantly share code, notes, and snippets.

View abhijeetchopra05's full-sized avatar

Abhijeet Chopra abhijeetchopra05

View GitHub Profile
@abhijeetchopra05
abhijeetchopra05 / JwtRequestFilter.java
Created November 10, 2019 08:07
Use of SecurityContextHolder in spring security
package com.personal.banking.config;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.web.authentication.WebAuthenticationDetailsSource;
import org.springframework.stereotype.Component;
import org.springframework.web.filter.OncePerRequestFilter;
@abhijeetchopra05
abhijeetchopra05 / CustomUserDetailService.java
Created November 10, 2019 07:58
Custom UserDetailsService for spring security
package com.personal.banking.config;
import com.personal.banking.domain.Role;
import com.personal.banking.domain.User;
import com.personal.banking.repo.UserRepo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.security.crypto.password.PasswordEncoder;
@abhijeetchopra05
abhijeetchopra05 / CustomAuthenticationManager.java
Last active February 21, 2024 10:19
SpringSecurity Custom AuthenticationManager
package com.personal.banking.config;
import com.personal.banking.domain.Role;
import com.personal.banking.domain.User;
import com.personal.banking.repo.UserRepo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.authentication.AuthenticationManager;
import org.springframework.security.authentication.BadCredentialsException;
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
import org.springframework.security.core.Authentication;