Skip to content

Commit

Permalink
Merge pull request #12 from GApple-T/donghak
Browse files Browse the repository at this point in the history
필터 수정하다 만거
  • Loading branch information
enbraining authored Nov 22, 2023
2 parents 0a37e05 + 4d91cc6 commit e062e24
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,16 @@ public class Okay {
private Long id;

@Column(nullable = false)
private Long issuedAt = null; // 상담 신청 일자
private Long issuedAt; // 상담 신청 일자

@Column(nullable = false)
private Long startAt = null; // 언제 가야하는지
private Long startAt; // 언제 가야하는지

@Column(nullable = false)
private boolean isAccess = false; // 선생님이 승인했는지
private boolean isAccess; // 선생님이 승인했는지

@Column(nullable = false)
private boolean isTrue = false; // 활성화된 Check 인지
private boolean isTrue; // 활성화된 Check 인지

@OneToOne(mappedBy = "okay")
private User user;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public class User {
@Column(columnDefinition = "VARCHAR(50)", nullable = false)
private String email;

@Column(columnDefinition = "VARCHAR(24)", nullable = false)
@Column(columnDefinition = "VARCHAR(80)", nullable = false)
private String password;

@OneToOne
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,6 @@ public class UserJoinRequest {

@NotBlank
@Size(min = 8, max = 24)
@Pattern(regexp = "^(?=.*[A-Za-z])(?=.*\\d)(?=.*[@$!%*#?&])[A-Za-z\\d@$!%*#?&]{8,24}$", message = "비밀번호는 8~24 자리이며, 특수문자가 1개 이상 들어가야합니다.")
// @Pattern(regexp = "^(?=.*[A-Za-z])(?=.*\\d)(?=.*[@$!%*#?&])[A-Za-z\\d@$!%*#?&]{8,24}$", message = "비밀번호는 8~24 자리이며, 특수문자가 1개 이상 들어가야합니다.")
private String password;
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,9 @@ public class SecurityConfig {
@Bean
public SecurityFilterChain filterChain(HttpSecurity http) throws Exception{
http.authorizeHttpRequests(request -> request
// .requestMatchers("/user/**").permitAll()
// .requestMatchers("/send-mail/**").permitAll()
// .anyRequest().authenticated()
.anyRequest().permitAll()
.requestMatchers("/user/**").permitAll()
.requestMatchers("/send-mail/**").permitAll()
.anyRequest().authenticated()
)
.httpBasic(withDefaults())
.formLogin(withDefaults())
Expand Down
13 changes: 7 additions & 6 deletions src/main/java/com/gapple/weeingback/global/filter/JwtFilter.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.gapple.weeingback.global.jwt.JwtProperties;
import com.gapple.weeingback.global.jwt.JwtProvider;
import com.gapple.weeingback.global.jwt.userDetails.UserDetailsServiceImpl;
import io.jsonwebtoken.Jwts;
import jakarta.servlet.FilterChain;
import jakarta.servlet.ServletException;
import jakarta.servlet.http.HttpServletRequest;
Expand All @@ -25,14 +26,15 @@ public class JwtFilter extends OncePerRequestFilter {

@Override
protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain) throws ServletException, IOException {
String header = request.getHeader("Authorization");
log.warn(header);
String authorization = request.getHeader("authorization");

if(isNullOrWrong(header)){
if (isNullOrWrong(authorization))
super.doFilter(request, response, filterChain);
}

String accessToken = extractAccessToken(header);
log.warn(authorization);


String accessToken = extractAccessToken(authorization);
String email = getEmailFromToken(accessToken);

UserDetails userDetails = service.loadUserByUsername(email);
Expand Down Expand Up @@ -63,6 +65,5 @@ private String getEmailFromToken(String accessToken) {

private Authentication createAuthenticationToken(UserDetails userDetails){
return new UsernamePasswordAuthenticationToken(userDetails.getUsername(), userDetails.getPassword());
// TODO Authentication 객체 만들어서 반환하기
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.gapple.weeingback.global.jwt.userDetails;

import com.gapple.weeingback.domain.user.entity.User;
import com.gapple.weeingback.domain.user.repository.UserRepository;
import lombok.RequiredArgsConstructor;
import org.springframework.security.core.userdetails.UserDetails;
Expand All @@ -13,6 +14,7 @@ public class UserDetailsServiceImpl implements UserDetailsService {
private final UserRepository userRepository;
@Override
public UserDetails loadUserByUsername(String email) throws UsernameNotFoundException {
return new UserDetailsImpl(userRepository.findUserByEmail(email));
User user = userRepository.findUserByEmail(email);
return new UserDetailsImpl(user);
}
}
6 changes: 2 additions & 4 deletions src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ spring:
open-in-view: false
hibernate:
dialect: org.hibernate.dialect.MySQL5Dialect
ddl-auto: create-drop
ddl-auto: create
properties:
hibernate:format_sql: true
show-sql: true
Expand All @@ -31,6 +31,4 @@ spring:
password: 1

jwt:
secret: MjFmcnlmc2RmamE3OXlZRnNkRnN5ZGY5eWZzZGhnSGdxZWc0Mwo=
server:
port: 8081
secret: MjFmcnlmc2RmamE3OXlZRnNkRnN5ZGY5eWZzZGhnSGdxZWc0Mwo=

0 comments on commit e062e24

Please sign in to comment.