Skip to content

Commit

Permalink
#82 fix : Jwt PasswordEncoder Bean 등록
Browse files Browse the repository at this point in the history
  • Loading branch information
rivkode committed Apr 25, 2024
1 parent 1ced325 commit 9f23fb3
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,7 @@
import org.springframework.scheduling.annotation.EnableScheduling;

@SpringBootApplication
@EnableCaching
@EnableJpaAuditing
@EnableScheduling
@ConfigurationPropertiesScan("com.seoultech.synergybe.system.config.properties")
public class SynergyBeApplication {
static {
System.setProperty("com.amazonaws.sdk.disableEc2Metadata", "true");
}

public static void main(String[] args) {
SpringApplication.run(SynergyBeApplication.class, args);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package com.seoultech.synergybe.domain.common;

import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.stereotype.Component;
public interface CustomPasswordEncoder{
String encodePassword(String rawPassword);

@Component
public class CustomPasswordEncoder extends BCryptPasswordEncoder {
boolean matchesPassword(String rawPassword, String encodedPassword);

boolean noneMatchesPassword(String rawPassword, String encodedPassword);
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public class UserPassword {
public UserPassword(String rawPassword, CustomPasswordEncoder passwordEncoder) {
validateNotNull(rawPassword);
validateUserPasswordLength(rawPassword);
this.password = passwordEncoder.encode(rawPassword);
this.password = passwordEncoder.encodePassword(rawPassword);
}

private void validateNotNull(String password) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.seoultech.synergybe.system.security;
package com.seoultech.synergybe.system.config;

import com.seoultech.synergybe.domain.common.CustomPasswordEncoder;
import com.seoultech.synergybe.system.security.*;
import lombok.RequiredArgsConstructor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
Expand Down Expand Up @@ -32,10 +34,15 @@ public class SecurityConfig {
private final AuthenticationConfiguration authenticationConfiguration;

@Bean
public PasswordEncoder passwordEncoder() {
return new BCryptPasswordEncoder();
public static CustomPasswordEncoder customPasswordEncoder() {
return new BCryptCustomPasswordEncoder(new BCryptPasswordEncoder());
}

// @Bean
// public PasswordEncoder passwordEncoder() {
// return new BCryptPasswordEncoder();
// }

@Bean
public AuthenticationManager authenticationManager(AuthenticationConfiguration configuration) throws Exception {
return configuration.getAuthenticationManager();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package com.seoultech.synergybe.system.security;

import com.seoultech.synergybe.domain.common.CustomPasswordEncoder;
import lombok.RequiredArgsConstructor;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;

@RequiredArgsConstructor
public class BCryptCustomPasswordEncoder implements CustomPasswordEncoder {

private final BCryptPasswordEncoder passwordEncoder;

@Override
public String encodePassword(String rawPassword) {
return passwordEncoder.encode(rawPassword);
}

@Override
public boolean matchesPassword(String rawPassword, String encodedPassword) {
return passwordEncoder.matches(rawPassword, encodedPassword);
}

@Override
public boolean noneMatchesPassword(String rawPassword, String encodedPassword) {
return !matchesPassword(rawPassword, encodedPassword);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public class JwtAuthenticationFilter extends UsernamePasswordAuthenticationFilte

public JwtAuthenticationFilter(JwtUtil jwtUtil) {
this.jwtUtil = jwtUtil;
setFilterProcessesUrl("/api/users/login");
setFilterProcessesUrl("/api/v1/users/login");
}

@Override
Expand Down

0 comments on commit 9f23fb3

Please sign in to comment.