Skip to content

Commit

Permalink
Merge pull request #151 from KUIT-Space/develop
Browse files Browse the repository at this point in the history
24.09.11 ๋ฐฐํฌ
  • Loading branch information
drbug2000 authored Sep 11, 2024
2 parents ea31a0e + c264c7f commit fa2c572
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 6 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/gradle.yml
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ jobs:

- name: Set YML
run: |
echo "${{ secrets.APPLICATION_YML_DEV }}" | base64 --decode > src/main/resources/application.yml
echo "${{ secrets.APPLICATION_YML_DEV }}" > src/main/resources/application.yml
# (5) Gradle build (Test ์ œ์™ธ)
- name: Build with Gradle
Expand Down
15 changes: 15 additions & 0 deletions src/main/java/space/space_spring/config/SecurityConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,18 @@
import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.security.config.http.SessionCreationPolicy;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.security.web.SecurityFilterChain;

@Configuration
@EnableWebSecurity
public class SecurityConfig {
@Bean
public PasswordEncoder passwordEncoder() {
return new BCryptPasswordEncoder();
}

@Bean
public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception {
Expand All @@ -18,6 +25,14 @@ public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Excepti
.csrf((csrfConfig) ->
csrfConfig.disable()
)
// HTTP ์ธ์ฆ ์š”๊ตฌ ๋น„ํ™œ์„ฑํ™”
// .authorizeHttpRequests(auth -> auth
// .anyRequest().authenticated()
// )
// Session ์‚ฌ์šฉ ์„ค์ • ํ•ด์ œ
.sessionManagement(session -> session
.sessionCreationPolicy(SessionCreationPolicy.STATELESS)
)
// h2 console ํ™”๋ฉด์„ ์‚ฌ์šฉํ•˜๊ธฐ ์œ„ํ•ด ํ•ด๋‹น ์˜ต์…˜๋“ค disable
.headers((headerConfig) ->
headerConfig.frameOptions(frameOptionsConfig ->
Expand Down
4 changes: 1 addition & 3 deletions src/main/java/space/space_spring/entity/User.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,6 @@ public void saveUser(String email, String password, String userName, UserSignupT
initializeBaseEntityFields();
}

public boolean passwordMatch(String password) {
return this.password.equals(password);
}


}
8 changes: 6 additions & 2 deletions src/main/java/space/space_spring/service/UserService.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import space.space_spring.dao.UserSpaceDao;
Expand Down Expand Up @@ -35,6 +36,7 @@ public class UserService {
private final JwtLoginProvider jwtLoginProvider;
private final UserSpaceDao userSpaceDao;
private final UserUtils userUtils;
private final PasswordEncoder passwordEncoder;

@Transactional
public Long signup(PostUserSignupRequest postUserSignupRequest) {
Expand All @@ -45,7 +47,7 @@ public Long signup(PostUserSignupRequest postUserSignupRequest) {

// TODO 2. ํšŒ์›์ •๋ณด db insert
String email = postUserSignupRequest.getEmail();
String password = postUserSignupRequest.getPassword();
String password = passwordEncoder.encode(postUserSignupRequest.getPassword());
String userName = postUserSignupRequest.getUserName();

User saveUser = userDao.saveUser(email, password, userName, LOCAL);
Expand Down Expand Up @@ -79,9 +81,11 @@ public PostLoginDto login(PostLoginDto.Request request) {
}

private void validatePassword(User userByEmail, String password) {
if (!userByEmail.passwordMatch(password)) {
String encodePassword = userByEmail.getPassword();
if(!passwordEncoder.matches(password,encodePassword)){
throw new CustomException(PASSWORD_NO_MATCH);
}

}

@Transactional
Expand Down

0 comments on commit fa2c572

Please sign in to comment.