본문 바로가기
TIL

8. [TIL] 오늘의 배움일지 ( 20-09-25 )

by VIPeveloper 2020. 9. 25.
반응형

1. 키클락 보안설정

키클락 튜토리얼로 로그인하는 과정을 배웠고, 이제 보안설정하는 방법을 알아보려 한다.

2. 다른 포트간 통신하는 방법

야매일수도 있겠지만 어찌되었던 통신이 되는 방법을 알았다.

예를들면, 80포트의 @Getmapping("/sender")와 81포트의 @Getmapping("/receiver") 같은 경우의 통신을 말한다.

예제를 보자.

1. 81포트에서 로그인 버튼을 클릭 시, @Getmapping("/login")으로 이동하게 된다.

    @GetMapping("/login")
    public RedirectView hello(Principal principal){
        return new RedirectView("http://localhost:8084/loginRequest");
    }

그러면 84포트의 loginRequest로 RedirectView 라는 객체로 보낸다.

2.  84포트의 @Getmapping("/loginRequest")는 principal.getName()을 받아서 저렇게 하단에 싣어 보내주면 된다.

addCustomers 라던지 Principal이 왜 나왔는지보다는 다른 포트간 컨트롤러 통신을 어떻게 하는지에 대해 집중해야 한다. 이것만을 위한 포스팅이니까.

    @GetMapping(path = "/loginRequest")
    public RedirectView customers(Principal principal, ModelMap model) {
        addCustomers();
//        Iterable<Customer> customers = customerDAO.findAll();
//        model.addAttribute("customers", customers);
        model.addAttribute("username", principal.getName());
        return new RedirectView("http://localhost:8081/result?user=" + principal.getName());
    }

 

반응형