@Test public void testFindWhoAmI() { String companyId = UUID.randomUUID().toString(); TeamDto teamDto1 = TeamDto.builder() .companyId(companyId) .name("test_team1") .dayWeekStarts("Monday") .color("#3D85C6") .timezone(TimeZone.getDefault().getID()) .build(); TeamDto teamDto2 = TeamDto.builder() .companyId(companyId) .name("test_team2") .dayWeekStarts("Monday") .color("#95AF44") .timezone(TimeZone.getDefault().getID()) .build(); WorkerOfList workerOfList = WorkerOfList.builder() .userId(TestConfig.TEST_USER_ID) .build(); workerOfList.getTeams().add(teamDto1); workerOfList.getTeams().add(teamDto2); when(companyClient.getWorkerOf(AuthConstant.AUTHORIZATION_WHOAMI_SERVICE, TestConfig.TEST_USER_ID)) .thenReturn(new GetWorkerOfResponse(workerOfList)); CompanyDto companyDto = CompanyDto.builder() .name("test_company") .id(companyId) .defaultDayWeekStarts("Monday") .defaultTimezone(TimeZone.getDefault().getID()) .build(); AdminOfList adminOfList = AdminOfList.builder() .userId(TestConfig.TEST_USER_ID) .build(); adminOfList.getCompanies().add(companyDto); when(companyClient.getAdminOf(AuthConstant.AUTHORIZATION_WHOAMI_SERVICE, TestConfig.TEST_USER_ID)). thenReturn(new GetAdminOfResponse(adminOfList)); FindWhoAmIResponse findWhoAmIResponse = whoAmIClient.findWhoAmI(AuthConstant.AUTHORIZATION_AUTHENTICATED_USER); log.info(findWhoAmIResponse.toString()); assertThat(findWhoAmIResponse.isSuccess()).isTrue(); IAmDto iAmDto = findWhoAmIResponse.getIAm(); assertThat(iAmDto.getWorkerOfList().getUserId()).isEqualTo(TestConfig.TEST_USER_ID); assertThat(iAmDto.getWorkerOfList().getTeams()).containsExactly(teamDto1, teamDto2); assertThat(iAmDto.getAdminOfList().getUserId()).isEqualTo(TestConfig.TEST_USER_ID); assertThat(iAmDto.getAdminOfList().getCompanies()).containsExactly(companyDto); }
@Authorize(value = { AuthConstant.AUTHORIZATION_AUTHENTICATED_USER, AuthConstant.AUTHORIZATION_SUPPORT_USER }) @GetMapping public FindWhoAmIResponse findWhoAmI() { String userId = AuthContext.getUserId(); IAmDto iAmDto = whoAmIService.findWhoIAm(userId); String authz = AuthContext.getAuthz(); if (AuthConstant.AUTHORIZATION_SUPPORT_USER.equals(authz)) { iAmDto.setSupport(true); } return new FindWhoAmIResponse(iAmDto); }
WhoAmIController { @Authorize(value = { AuthConstant.AUTHORIZATION_AUTHENTICATED_USER, AuthConstant.AUTHORIZATION_SUPPORT_USER }) @GetMapping public FindWhoAmIResponse findWhoAmI() { String userId = AuthContext.getUserId(); IAmDto iAmDto = whoAmIService.findWhoIAm(userId); String authz = AuthContext.getAuthz(); if (AuthConstant.AUTHORIZATION_SUPPORT_USER.equals(authz)) { iAmDto.setSupport(true); } return new FindWhoAmIResponse(iAmDto); } }
WhoAmIController { @Authorize(value = { AuthConstant.AUTHORIZATION_AUTHENTICATED_USER, AuthConstant.AUTHORIZATION_SUPPORT_USER }) @GetMapping public FindWhoAmIResponse findWhoAmI() { String userId = AuthContext.getUserId(); IAmDto iAmDto = whoAmIService.findWhoIAm(userId); String authz = AuthContext.getAuthz(); if (AuthConstant.AUTHORIZATION_SUPPORT_USER.equals(authz)) { iAmDto.setSupport(true); } return new FindWhoAmIResponse(iAmDto); }  }
WhoAmIController { @Authorize(value = { AuthConstant.AUTHORIZATION_AUTHENTICATED_USER, AuthConstant.AUTHORIZATION_SUPPORT_USER }) @GetMapping public FindWhoAmIResponse findWhoAmI() { String userId = AuthContext.getUserId(); IAmDto iAmDto = whoAmIService.findWhoIAm(userId); String authz = AuthContext.getAuthz(); if (AuthConstant.AUTHORIZATION_SUPPORT_USER.equals(authz)) { iAmDto.setSupport(true); } return new FindWhoAmIResponse(iAmDto); }  @Authorize(value = { AuthConstant.AUTHORIZATION_AUTHENTICATED_USER, AuthConstant.AUTHORIZATION_SUPPORT_USER }) @GetMapping FindWhoAmIResponse findWhoAmI(); @Authorize(value = { AuthConstant.AUTHORIZATION_AUTHENTICATED_USER, AuthConstant.AUTHORIZATION_SUPPORT_USER }) @GetMapping(value = "/intercom") GetIntercomSettingResponse getIntercomSettings(); }
WhoAmIController { @Authorize(value = { AuthConstant.AUTHORIZATION_AUTHENTICATED_USER, AuthConstant.AUTHORIZATION_SUPPORT_USER }) @GetMapping public FindWhoAmIResponse findWhoAmI() { String userId = AuthContext.getUserId(); IAmDto iAmDto = whoAmIService.findWhoIAm(userId); String authz = AuthContext.getAuthz(); if (AuthConstant.AUTHORIZATION_SUPPORT_USER.equals(authz)) { iAmDto.setSupport(true); } return new FindWhoAmIResponse(iAmDto); }  @Authorize(value = { AuthConstant.AUTHORIZATION_AUTHENTICATED_USER, AuthConstant.AUTHORIZATION_SUPPORT_USER }) @GetMapping FindWhoAmIResponse findWhoAmI(); @Authorize(value = { AuthConstant.AUTHORIZATION_AUTHENTICATED_USER, AuthConstant.AUTHORIZATION_SUPPORT_USER }) @GetMapping(value = "/intercom") GetIntercomSettingResponse getIntercomSettings();  }