SUPPORT-9301: добавил передачу токена для методов к получению аккаунтов
This commit is contained in:
parent
bb87bf48ee
commit
3f8d8aff72
5 changed files with 35 additions and 14 deletions
|
|
@ -3,11 +3,14 @@ package ru.micord.ervu.account_applications.component.service;
|
|||
import java.net.URI;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.http.HttpEntity;
|
||||
import org.springframework.http.HttpHeaders;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.http.HttpMethod;
|
||||
import org.springframework.web.client.RestTemplate;
|
||||
import org.springframework.web.util.UriComponentsBuilder;
|
||||
import ru.micord.ervu.account_applications.component.exception.IdmValidatorException;
|
||||
import ru.micord.ervu.account_applications.security.context.SecurityContext;
|
||||
import ru.micord.ervu.account_applications.service.constant.PathConstant;
|
||||
|
||||
/**
|
||||
|
|
@ -15,17 +18,20 @@ import ru.micord.ervu.account_applications.service.constant.PathConstant;
|
|||
*/
|
||||
public abstract class AbstractIdmValidatorService implements IdmValidatorService{
|
||||
protected RestTemplate restTemplate;
|
||||
protected SecurityContext securityContext;
|
||||
|
||||
@Value("${idm.url}")
|
||||
protected String idmUrl;
|
||||
@Value("${ervu.url}")
|
||||
protected String ervuUrl;
|
||||
|
||||
protected AbstractIdmValidatorService(RestTemplate restTemplate) {
|
||||
protected AbstractIdmValidatorService(RestTemplate restTemplate, SecurityContext securityContext) {
|
||||
this.restTemplate = restTemplate;
|
||||
this.securityContext = securityContext;
|
||||
}
|
||||
|
||||
protected boolean checkExistsByQuery(String endpoint, String queryParamName, String queryParamValue) {
|
||||
URI uri = UriComponentsBuilder
|
||||
.fromHttpUrl(idmUrl)
|
||||
.fromHttpUrl(ervuUrl)
|
||||
.path(PathConstant.IDM_PATH)
|
||||
.pathSegment(PathConstant.PERSONS_PATH)
|
||||
.path(endpoint)
|
||||
.queryParam(queryParamName, queryParamValue)
|
||||
|
|
@ -33,11 +39,15 @@ public abstract class AbstractIdmValidatorService implements IdmValidatorService
|
|||
.encode()
|
||||
.toUri();
|
||||
|
||||
HttpHeaders headers = new HttpHeaders();
|
||||
headers.setBearerAuth(securityContext.getToken());
|
||||
HttpEntity<Void> request = new HttpEntity<>(headers);
|
||||
|
||||
try {
|
||||
ResponseEntity<Boolean> response = restTemplate.exchange(
|
||||
uri,
|
||||
HttpMethod.GET,
|
||||
null,
|
||||
request,
|
||||
Boolean.class
|
||||
);
|
||||
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@ package ru.micord.ervu.account_applications.component.service;
|
|||
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.web.client.RestTemplate;
|
||||
import ru.micord.ervu.account_applications.security.context.SecurityContext;
|
||||
|
||||
/**
|
||||
* @author Emir Suleimanov
|
||||
|
|
@ -9,8 +10,8 @@ import org.springframework.web.client.RestTemplate;
|
|||
@Service
|
||||
public class IdmLoginValidatorService extends AbstractIdmValidatorService {
|
||||
|
||||
public IdmLoginValidatorService(RestTemplate restTemplate) {
|
||||
super(restTemplate);
|
||||
public IdmLoginValidatorService(RestTemplate restTemplate, SecurityContext securityContext) {
|
||||
super(restTemplate, securityContext);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@ package ru.micord.ervu.account_applications.component.service;
|
|||
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.web.client.RestTemplate;
|
||||
import ru.micord.ervu.account_applications.security.context.SecurityContext;
|
||||
|
||||
/**
|
||||
* @author Emir Suleimanov
|
||||
|
|
@ -9,8 +10,8 @@ import org.springframework.web.client.RestTemplate;
|
|||
@Service
|
||||
public class IdmSnilsValidatorService extends AbstractIdmValidatorService {
|
||||
|
||||
public IdmSnilsValidatorService(RestTemplate restTemplate) {
|
||||
super(restTemplate);
|
||||
public IdmSnilsValidatorService(RestTemplate restTemplate, SecurityContext securityContext) {
|
||||
super(restTemplate, securityContext);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -28,6 +28,7 @@ import ru.micord.ervu.account_applications.component.model.Account;
|
|||
import ru.micord.ervu.account_applications.component.model.Role;
|
||||
import ru.micord.ervu.account_applications.component.model.dto.SearchRequest;
|
||||
import ru.micord.ervu.account_applications.component.model.dto.SearchResponse;
|
||||
import ru.micord.ervu.account_applications.security.context.SecurityContext;
|
||||
import ru.micord.ervu.account_applications.service.constant.PathConstant;
|
||||
|
||||
import ru.cg.webbpm.modules.standard_annotations.editor.ObjectRef;
|
||||
|
|
@ -43,15 +44,18 @@ public class AccountFetchService implements EntityFetchService<Account> {
|
|||
private static final String FIELD_ROLES = "roles";
|
||||
private final RestTemplate restTemplate;
|
||||
private final ObjectMapper mapper;
|
||||
@Value("${idm.url}")
|
||||
private String idmUrl;
|
||||
private final SecurityContext securityContext;
|
||||
@Value("${ervu.url}")
|
||||
private String ervuUrl;
|
||||
@ObjectRef
|
||||
public EditableGridColumn editableGridColumnRef;
|
||||
|
||||
|
||||
public AccountFetchService(RestTemplate restTemplate, ObjectMapper mapper) {
|
||||
public AccountFetchService(RestTemplate restTemplate, ObjectMapper mapper,
|
||||
SecurityContext securityContext) {
|
||||
this.restTemplate = restTemplate;
|
||||
this.mapper = mapper;
|
||||
this.securityContext = securityContext;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -65,9 +69,11 @@ public class AccountFetchService implements EntityFetchService<Account> {
|
|||
try {
|
||||
HttpHeaders headers = new HttpHeaders();
|
||||
headers.setContentType(MediaType.APPLICATION_JSON);
|
||||
headers.setBearerAuth(securityContext.getToken());
|
||||
HttpEntity<SearchRequest> httpEntity = new HttpEntity<>(request, headers);
|
||||
|
||||
URI uri = UriComponentsBuilder.fromHttpUrl(idmUrl)
|
||||
URI uri = UriComponentsBuilder.fromHttpUrl(ervuUrl)
|
||||
.path(PathConstant.IDM_PATH)
|
||||
.pathSegment(PathConstant.ACCOUNTS_PATH, "search", "v1")
|
||||
.build()
|
||||
.toUri();
|
||||
|
|
@ -107,7 +113,8 @@ public class AccountFetchService implements EntityFetchService<Account> {
|
|||
}
|
||||
|
||||
private Account fetchAccountById(Object id) {
|
||||
URI uri = UriComponentsBuilder.fromHttpUrl(idmUrl)
|
||||
URI uri = UriComponentsBuilder.fromHttpUrl(ervuUrl)
|
||||
.path(PathConstant.IDM_PATH)
|
||||
.pathSegment(PathConstant.ACCOUNTS_PATH, id.toString(), "v1")
|
||||
.build()
|
||||
.toUri();
|
||||
|
|
@ -115,6 +122,7 @@ public class AccountFetchService implements EntityFetchService<Account> {
|
|||
try {
|
||||
HttpHeaders headers = new HttpHeaders();
|
||||
headers.setContentType(MediaType.APPLICATION_JSON);
|
||||
headers.setBearerAuth(securityContext.getToken());
|
||||
HttpEntity<Void> request = new HttpEntity<>(headers);
|
||||
|
||||
ResponseEntity<Account> response = restTemplate.exchange(
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@ package ru.micord.ervu.account_applications.service.constant;
|
|||
public final class PathConstant {
|
||||
public static final String ACCOUNTS_PATH = "accounts";
|
||||
public static final String PERSONS_PATH = "persons";
|
||||
public static final String IDM_PATH = "/service/idm";
|
||||
|
||||
private PathConstant() {
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue