SUPPORT-8702: fix notification display
This commit is contained in:
parent
39a1f753e3
commit
cca35f3b04
6 changed files with 42 additions and 26 deletions
|
|
@ -0,0 +1,18 @@
|
||||||
|
package ru.micord.ervu.kafka.exception;
|
||||||
|
|
||||||
|
import org.springframework.context.support.MessageSourceAccessor;
|
||||||
|
|
||||||
|
import ru.cg.webbpm.modules.core.runtime.api.LocalizedException;
|
||||||
|
import ru.cg.webbpm.modules.core.runtime.api.MessageBundleUtils;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Emir Suleimanov
|
||||||
|
*/
|
||||||
|
public class KafkaMessageReplyTimeoutException extends LocalizedException {
|
||||||
|
private static final MessageSourceAccessor MESSAGE_SOURCE = MessageBundleUtils.createAccessor("messages/common_errors_messages");
|
||||||
|
private static final String KAFKA_REPLY_TIMEOUT = "kafka_reply_timeout";
|
||||||
|
|
||||||
|
public KafkaMessageReplyTimeoutException(Throwable cause) {
|
||||||
|
super(KAFKA_REPLY_TIMEOUT, MESSAGE_SOURCE, cause);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -8,6 +8,7 @@ import org.apache.kafka.clients.producer.ProducerRecord;
|
||||||
import org.springframework.kafka.requestreply.ReplyingKafkaTemplate;
|
import org.springframework.kafka.requestreply.ReplyingKafkaTemplate;
|
||||||
import org.springframework.kafka.requestreply.RequestReplyFuture;
|
import org.springframework.kafka.requestreply.RequestReplyFuture;
|
||||||
import ru.micord.ervu.kafka.exception.KafkaMessageException;
|
import ru.micord.ervu.kafka.exception.KafkaMessageException;
|
||||||
|
import ru.micord.ervu.kafka.exception.KafkaMessageReplyTimeoutException;
|
||||||
import ru.micord.ervu.kafka.service.ReplyingKafkaService;
|
import ru.micord.ervu.kafka.service.ReplyingKafkaService;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -26,7 +27,7 @@ public abstract class BaseReplyingKafkaService<T, V> implements ReplyingKafkaSer
|
||||||
.orElseThrow(() -> new KafkaMessageException("Kafka return result is null"));
|
.orElseThrow(() -> new KafkaMessageException("Kafka return result is null"));
|
||||||
}
|
}
|
||||||
catch (InterruptedException | ExecutionException e) {
|
catch (InterruptedException | ExecutionException e) {
|
||||||
throw new KafkaMessageException("Failed to get kafka response", e);
|
throw new KafkaMessageReplyTimeoutException(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
protected abstract ReplyingKafkaTemplate<String, T, V> getTemplate();
|
protected abstract ReplyingKafkaTemplate<String, T, V> getTemplate();
|
||||||
|
|
|
||||||
|
|
@ -39,10 +39,10 @@ public class EsiaController {
|
||||||
}
|
}
|
||||||
|
|
||||||
@GetMapping(value = "/esia/auth")
|
@GetMapping(value = "/esia/auth")
|
||||||
public ResponseEntity<?> esiaAuth(@RequestParam(value = "code", required = false) String code,
|
public void esiaAuth(@RequestParam(value = "code", required = false) String code,
|
||||||
@RequestParam(value = "error", required = false) String error, HttpServletRequest request,
|
@RequestParam(value = "error", required = false) String error, HttpServletRequest request,
|
||||||
HttpServletResponse response) {
|
HttpServletResponse response) {
|
||||||
return esiaAuthService.getEsiaTokensByCode(code, error, request, response);
|
esiaAuthService.authEsiaTokensByCode(code, error, request, response);
|
||||||
}
|
}
|
||||||
|
|
||||||
@RequestMapping(value = "/esia/refresh")
|
@RequestMapping(value = "/esia/refresh")
|
||||||
|
|
|
||||||
|
|
@ -17,13 +17,13 @@ import java.util.Objects;
|
||||||
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
import javax.servlet.http.HttpServletResponse;
|
import javax.servlet.http.HttpServletResponse;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
import org.springframework.beans.factory.annotation.Qualifier;
|
import org.springframework.beans.factory.annotation.Qualifier;
|
||||||
import org.springframework.beans.factory.annotation.Value;
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
import org.springframework.http.HttpStatus;
|
import org.springframework.context.support.MessageSourceAccessor;
|
||||||
import org.springframework.http.ResponseEntity;
|
|
||||||
import org.springframework.security.core.context.SecurityContext;
|
import org.springframework.security.core.context.SecurityContext;
|
||||||
import ru.micord.ervu.kafka.model.Document;
|
import ru.micord.ervu.kafka.model.Document;
|
||||||
import ru.micord.ervu.kafka.model.Person;
|
import ru.micord.ervu.kafka.model.Person;
|
||||||
|
|
@ -48,6 +48,8 @@ import ru.micord.ervu.security.webbpm.jwt.helper.SecurityHelper;
|
||||||
import ru.micord.ervu.security.webbpm.jwt.service.JwtTokenService;
|
import ru.micord.ervu.security.webbpm.jwt.service.JwtTokenService;
|
||||||
import ru.micord.ervu.security.webbpm.jwt.model.Token;
|
import ru.micord.ervu.security.webbpm.jwt.model.Token;
|
||||||
|
|
||||||
|
import ru.cg.webbpm.modules.core.runtime.api.MessageBundleUtils;
|
||||||
|
|
||||||
import static ru.micord.ervu.security.webbpm.jwt.util.SecurityUtil.getCurrentUsername;
|
import static ru.micord.ervu.security.webbpm.jwt.util.SecurityUtil.getCurrentUsername;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -56,7 +58,8 @@ import static ru.micord.ervu.security.webbpm.jwt.util.SecurityUtil.getCurrentUse
|
||||||
@Service
|
@Service
|
||||||
public class EsiaAuthService {
|
public class EsiaAuthService {
|
||||||
private static final Logger LOGGER = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
|
private static final Logger LOGGER = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
|
||||||
|
private static final MessageSourceAccessor MESSAGE_SOURCE = MessageBundleUtils.createAccessor(
|
||||||
|
"messages/common_errors_messages");
|
||||||
@Autowired
|
@Autowired
|
||||||
private ObjectMapper objectMapper;
|
private ObjectMapper objectMapper;
|
||||||
|
|
||||||
|
|
@ -151,13 +154,10 @@ public class EsiaAuthService {
|
||||||
return uriBuilder.toString();
|
return uriBuilder.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
public ResponseEntity<?> getEsiaTokensByCode(String esiaAuthCode, String error,
|
public void authEsiaTokensByCode(String esiaAuthCode, String error,
|
||||||
HttpServletRequest request, HttpServletResponse response) {
|
HttpServletRequest request, HttpServletResponse response) {
|
||||||
if (error != null && !error.equals("null")) {
|
if (error != null && !error.equals("null")) {
|
||||||
return new ResponseEntity<>(
|
throw new EsiaException(error);
|
||||||
"Произошла неизвестная ошибка. Обратитесь к системному администратору",
|
|
||||||
HttpStatus.FORBIDDEN
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
String esiaAccessTokenStr = null;
|
String esiaAccessTokenStr = null;
|
||||||
String prnOid = null;
|
String prnOid = null;
|
||||||
|
|
@ -238,20 +238,16 @@ public class EsiaAuthService {
|
||||||
LOGGER.info("Thread {}: SignSecret: {}ms RequestAccessToken: {}ms VerifySecret: {}ms",
|
LOGGER.info("Thread {}: SignSecret: {}ms RequestAccessToken: {}ms VerifySecret: {}ms",
|
||||||
Thread.currentThread().getId(), signSecret, requestAccessToken, verifySecret);
|
Thread.currentThread().getId(), signSecret, requestAccessToken, verifySecret);
|
||||||
}
|
}
|
||||||
|
String ervuId = null;
|
||||||
try {
|
try {
|
||||||
Response ervuIdResponse = getErvuIdResponse(esiaAccessTokenStr);
|
Response ervuIdResponse = getErvuIdResponse(esiaAccessTokenStr);
|
||||||
createTokenAndAddCookie(response, prnOid, ervuIdResponse.getErvuId(), expiresIn);
|
ervuId = ervuIdResponse.getErvuId();
|
||||||
return ResponseEntity.ok("Authentication successful");
|
|
||||||
}
|
}
|
||||||
catch (Exception e) {
|
catch (EsiaException | JsonProcessingException e) {
|
||||||
createTokenAndAddCookie(response, prnOid, null, expiresIn);
|
throw new EsiaException(e);
|
||||||
String messageId = getMessageId(e);
|
}
|
||||||
String messageWithId = String.format("[%s] %s", messageId, e.getMessage());
|
finally {
|
||||||
LOGGER.error(messageWithId, e);
|
createTokenAndAddCookie(response, prnOid, ervuId, expiresIn);
|
||||||
return new ResponseEntity<>(
|
|
||||||
"Произошла ошибка " + messageId + ". Обратитесь к системному администратору",
|
|
||||||
HttpStatus.FORBIDDEN
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -374,7 +370,7 @@ public class EsiaAuthService {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public Response getErvuIdResponse(String accessToken) {
|
public Response getErvuIdResponse(String accessToken) throws JsonProcessingException {
|
||||||
long requestPersonData = 0, requestIdERVU = 0;
|
long requestPersonData = 0, requestIdERVU = 0;
|
||||||
try {
|
try {
|
||||||
long startTime = System.currentTimeMillis();
|
long startTime = System.currentTimeMillis();
|
||||||
|
|
@ -388,9 +384,6 @@ public class EsiaAuthService {
|
||||||
requestIdERVU = System.currentTimeMillis() - startTime;
|
requestIdERVU = System.currentTimeMillis() - startTime;
|
||||||
return objectMapper.readValue(kafkaResponse, Response.class);
|
return objectMapper.readValue(kafkaResponse, Response.class);
|
||||||
}
|
}
|
||||||
catch (Exception e) {
|
|
||||||
throw new EsiaException(e);
|
|
||||||
}
|
|
||||||
finally {
|
finally {
|
||||||
LOGGER.info("Thread {}: RequestPersonData: {}ms RequestIdERVU: {}ms",
|
LOGGER.info("Thread {}: RequestPersonData: {}ms RequestIdERVU: {}ms",
|
||||||
Thread.currentThread().getId(), requestPersonData, requestIdERVU);
|
Thread.currentThread().getId(), requestPersonData, requestIdERVU);
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,2 @@
|
||||||
|
kafka_reply_timeout=Превышено время ожидания ответа от сервера. Попробуйте повторить запрос позже или обратитесь к системному администратору
|
||||||
|
access_denied=Доступ запрещен. Пользователь должен быть включен в группу "Сотрудник, ответственный за военно-учетную работу" в ЕСИА
|
||||||
|
|
@ -0,0 +1,2 @@
|
||||||
|
kafka_reply_timeout=Превышено время ожидания ответа от сервера. Попробуйте повторить запрос позже или обратитесь к системному администратору
|
||||||
|
access_denied=Доступ запрещен. Пользователь должен быть включен в группу "Сотрудник, ответственный за военно-учетную работу" в ЕСИА
|
||||||
Loading…
Add table
Add a link
Reference in a new issue