-
Notifications
You must be signed in to change notification settings - Fork 41
/
Copy pathMemberController.java
54 lines (46 loc) · 2.08 KB
/
MemberController.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
package nextstep.app.ui;
import nextstep.app.domain.Member;
import nextstep.app.domain.MemberRepository;
import nextstep.security.authentication.AuthenticationException;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
import javax.servlet.http.HttpServletRequest;
import java.util.List;
@RestController
public class MemberController {
private final MemberRepository memberRepository;
public MemberController(MemberRepository memberRepository) {
this.memberRepository = memberRepository;
}
@GetMapping("/members")
public ResponseEntity<List<Member>> list(HttpServletRequest request) {
// String authorization = request.getHeader(HttpHeaders.AUTHORIZATION);
// String[] split = authorization.split(" ");
// String type = split[0];
// String credential = split[1];
// if (!"Basic".equalsIgnoreCase(type)) {
// throw new AuthenticationException();
// }
// try {
// String decodedCredential = new String(Base64Utils.decodeFromString(credential));
// String[] emailAndPassword = decodedCredential.split(":");
// String email = emailAndPassword[0];
// String password = emailAndPassword[1];
// Member member = memberRepository.findByEmail(email).orElseThrow(AuthenticationException::new);
// member.checkPassword(password);
// List<Member> members = memberRepository.findAll();
// return ResponseEntity.ok(members);
// } catch (Exception e) {
// throw new AuthenticationException();
// }
List<Member> members = memberRepository.findAll();
return ResponseEntity.ok(members);
}
@ExceptionHandler(AuthenticationException.class)
public ResponseEntity<Void> handleAuthenticationException() {
return ResponseEntity.status(HttpStatus.UNAUTHORIZED).build();
}
}