Skip to content

Instantly share code, notes, and snippets.

Choonghee Lee choonghee-lee

Block or report user

Report or block choonghee-lee

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
// UserDetailsService를 extends 했을때 오버라이드 해야하는 메소드
public UserDetails loadUserByUsername(String email) throws UsernameNotFoundException {
UserEntity userEntity = userRepository.findByEmail(email);
if(userEntity == null) {
throw new UsernameNotFoundException(email);
return new User(userEntity.getEmail(), userEntity.getEncryptedPassword(), new ArrayList<>());
public class WebSecurity extends WebSecurityConfigurerAdapter{
private final UserService userDetailsService;
private final BCryptPasswordEncoder bCryptPasswordEncoder;
public WebSecurity(UserService userDetailsService, BCryptPasswordEncoder bCryptPasswordEncoder) {
this.userDetailsService = userDetailsService;
this.bCryptPasswordEncoder = bCryptPasswordEncoder;
private BCryptPasswordEncoder bCryptPasswordEncoder;
public UserDto createUser(UserDto user) {
if (userRepository.findByEmail(user.getEmail()) != null) {
throw new RuntimeException("Record already exists");
UserEntity userEntity = new UserEntity();
public BCryptPasswordEncoder bCryptPasswordEncoder() {
return new BCryptPasswordEncoder();
View pom.xml
View layout.jsp
<%@ taglib prefix="sec" uri="" %>
<!-- 유저가 해당 롤을 가지면 코드를 렌더링한다. -->
<sec:authorize access="hasRole('ADMIN')">
<a class="brand" href="/"> Admins Home </a>
<sec:authorize access="hasRole('USER')">
<a class="brand" href="/"> Users Home </a>
spring.mvc.view.prefix: /WEB-INF/jsp/
spring.mvc.view.suffix: .jsp
View pom.xml
public class Utils {
private final Random RANDOM = new SecureRandom();
private final String ALPHABET = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
public String generateUserId(int length) {
return generateRandomString(length);
public interface UserRepository extends CrudRepository<User, Long> {
UserEntity findByEmail(String email);
You can’t perform that action at this time.