Skip to content
Snippets Groups Projects
Commit b1ea5b7c authored by 천 진강's avatar 천 진강
Browse files

feat: 토큰 발행시 프로젝트별 Role 반환

parent e76498c5
Branches
No related tags found
3 merge requests!15Feat/certificate,!6Feat/forwarding 포트포워딩 CRUD,!3Feat/auth 프로젝트 role 조회 api 추가
...@@ -2,7 +2,6 @@ package com.aolda.itda.service; ...@@ -2,7 +2,6 @@ package com.aolda.itda.service;
import com.aolda.itda.dto.auth.LoginRequestDTO; import com.aolda.itda.dto.auth.LoginRequestDTO;
import com.aolda.itda.dto.auth.LoginResponseDTO; import com.aolda.itda.dto.auth.LoginResponseDTO;
import com.aolda.itda.dto.auth.ProjectIdAndNameDTO;
import com.aolda.itda.dto.auth.ProjectRoleDTO; import com.aolda.itda.dto.auth.ProjectRoleDTO;
import com.aolda.itda.exception.CustomException; import com.aolda.itda.exception.CustomException;
import com.aolda.itda.exception.ErrorCode; import com.aolda.itda.exception.ErrorCode;
...@@ -45,8 +44,7 @@ public class AuthService { ...@@ -45,8 +44,7 @@ public class AuthService {
response.addHeader("X-Subject-Token", token); response.addHeader("X-Subject-Token", token);
return LoginResponseDTO.builder() return LoginResponseDTO.builder()
.isAdmin(false) .lists(getRolesWithProjects(user))
.lists(getProjectsWithUser(user))
.build(); .build();
} }
...@@ -65,9 +63,11 @@ public class AuthService { ...@@ -65,9 +63,11 @@ public class AuthService {
" ],\n" + " ],\n" +
" \"password\": {\n" + " \"password\": {\n" +
" \"user\": {\n" + " \"user\": {\n" +
" \"name\": \""+ id + "\",\n" +
" \"domain\": {\n" + " \"domain\": {\n" +
" \"name\": \"Default\"\n" + " \"name\": \"Default\"\n" +
" },\n" + " },\n" +
" \"password\": \"" + password + "\"\n" +
" }\n" + " }\n" +
" }\n" + " }\n" +
" }\n" + " }\n" +
...@@ -126,32 +126,4 @@ public class AuthService { ...@@ -126,32 +126,4 @@ public class AuthService {
Map<String, String> user = getToken(adminId, adminPassword); Map<String, String> user = getToken(adminId, adminPassword);
return user.get("token"); return user.get("token");
} }
private List<ProjectIdAndNameDTO> getProjectsWithUser(Map<String, String> user) throws JsonProcessingException {
String userId = user.get("id");
String token = user.get("token");
if (userId == null || token == null) {
throw new CustomException(ErrorCode.INVALID_USER_INFO);
}
String url = keystone + "/users/" + userId + "/projects";
HttpHeaders headers = new HttpHeaders();
headers.set("X-Auth-Token", getAdminToken());
HttpEntity<String> requestEntity = new HttpEntity<>(headers);
ResponseEntity<String> res = restTemplate.exchange(url, HttpMethod.GET, requestEntity, String.class);
JsonNode node = objectMapper.readTree(res.getBody());
ArrayNode arrayNode = (ArrayNode) node.get("projects");
List<ProjectIdAndNameDTO> lists = new ArrayList<>();
for (JsonNode assignment : arrayNode) {
String projectId = assignment.path("id").asText();
String projectName = assignment.path("name").asText();
lists.add(new ProjectIdAndNameDTO(projectId, projectName));
}
return lists;
}
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment