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.RequestReplyFuture;
|
||||
import ru.micord.ervu.kafka.exception.KafkaMessageException;
|
||||
import ru.micord.ervu.kafka.exception.KafkaMessageReplyTimeoutException;
|
||||
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"));
|
||||
}
|
||||
catch (InterruptedException | ExecutionException e) {
|
||||
throw new KafkaMessageException("Failed to get kafka response", e);
|
||||
throw new KafkaMessageReplyTimeoutException(e);
|
||||
}
|
||||
}
|
||||
protected abstract ReplyingKafkaTemplate<String, T, V> getTemplate();
|
||||
|
|
|
|||
|
|
@ -39,10 +39,10 @@ public class EsiaController {
|
|||
}
|
||||
|
||||
@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,
|
||||
HttpServletResponse response) {
|
||||
return esiaAuthService.getEsiaTokensByCode(code, error, request, response);
|
||||
esiaAuthService.authEsiaTokensByCode(code, error, request, response);
|
||||
}
|
||||
|
||||
@RequestMapping(value = "/esia/refresh")
|
||||
|
|
|
|||
|
|
@ -17,13 +17,13 @@ import java.util.Objects;
|
|||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Qualifier;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.context.support.MessageSourceAccessor;
|
||||
import org.springframework.security.core.context.SecurityContext;
|
||||
import ru.micord.ervu.kafka.model.Document;
|
||||
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.model.Token;
|
||||
|
||||
import ru.cg.webbpm.modules.core.runtime.api.MessageBundleUtils;
|
||||
|
||||
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
|
||||
public class EsiaAuthService {
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
|
||||
|
||||
private static final MessageSourceAccessor MESSAGE_SOURCE = MessageBundleUtils.createAccessor(
|
||||
"messages/common_errors_messages");
|
||||
@Autowired
|
||||
private ObjectMapper objectMapper;
|
||||
|
||||
|
|
@ -151,13 +154,10 @@ public class EsiaAuthService {
|
|||
return uriBuilder.toString();
|
||||
}
|
||||
|
||||
public ResponseEntity<?> getEsiaTokensByCode(String esiaAuthCode, String error,
|
||||
public void authEsiaTokensByCode(String esiaAuthCode, String error,
|
||||
HttpServletRequest request, HttpServletResponse response) {
|
||||
if (error != null && !error.equals("null")) {
|
||||
return new ResponseEntity<>(
|
||||
"Произошла неизвестная ошибка. Обратитесь к системному администратору",
|
||||
HttpStatus.FORBIDDEN
|
||||
);
|
||||
throw new EsiaException(error);
|
||||
}
|
||||
String esiaAccessTokenStr = null;
|
||||
String prnOid = null;
|
||||
|
|
@ -238,20 +238,16 @@ public class EsiaAuthService {
|
|||
LOGGER.info("Thread {}: SignSecret: {}ms RequestAccessToken: {}ms VerifySecret: {}ms",
|
||||
Thread.currentThread().getId(), signSecret, requestAccessToken, verifySecret);
|
||||
}
|
||||
String ervuId = null;
|
||||
try {
|
||||
Response ervuIdResponse = getErvuIdResponse(esiaAccessTokenStr);
|
||||
createTokenAndAddCookie(response, prnOid, ervuIdResponse.getErvuId(), expiresIn);
|
||||
return ResponseEntity.ok("Authentication successful");
|
||||
ervuId = ervuIdResponse.getErvuId();
|
||||
}
|
||||
catch (Exception e) {
|
||||
createTokenAndAddCookie(response, prnOid, null, expiresIn);
|
||||
String messageId = getMessageId(e);
|
||||
String messageWithId = String.format("[%s] %s", messageId, e.getMessage());
|
||||
LOGGER.error(messageWithId, e);
|
||||
return new ResponseEntity<>(
|
||||
"Произошла ошибка " + messageId + ". Обратитесь к системному администратору",
|
||||
HttpStatus.FORBIDDEN
|
||||
);
|
||||
catch (EsiaException | JsonProcessingException e) {
|
||||
throw new EsiaException(e);
|
||||
}
|
||||
finally {
|
||||
createTokenAndAddCookie(response, prnOid, ervuId, expiresIn);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -374,7 +370,7 @@ public class EsiaAuthService {
|
|||
}
|
||||
}
|
||||
|
||||
public Response getErvuIdResponse(String accessToken) {
|
||||
public Response getErvuIdResponse(String accessToken) throws JsonProcessingException {
|
||||
long requestPersonData = 0, requestIdERVU = 0;
|
||||
try {
|
||||
long startTime = System.currentTimeMillis();
|
||||
|
|
@ -388,9 +384,6 @@ public class EsiaAuthService {
|
|||
requestIdERVU = System.currentTimeMillis() - startTime;
|
||||
return objectMapper.readValue(kafkaResponse, Response.class);
|
||||
}
|
||||
catch (Exception e) {
|
||||
throw new EsiaException(e);
|
||||
}
|
||||
finally {
|
||||
LOGGER.info("Thread {}: RequestPersonData: {}ms RequestIdERVU: {}ms",
|
||||
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