SUPPORT-8702: fix notification display
This commit is contained in:
parent
f7e168f80c
commit
30c85a5f1f
6 changed files with 47 additions and 38 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);
|
||||
}
|
||||
}
|
||||
|
|
@ -11,6 +11,7 @@ import org.springframework.kafka.requestreply.RequestReplyFuture;
|
|||
import org.springframework.kafka.support.KafkaHeaders;
|
||||
import org.springframework.stereotype.Service;
|
||||
import ru.micord.ervu.kafka.exception.KafkaMessageException;
|
||||
import ru.micord.ervu.kafka.exception.KafkaMessageReplyTimeoutException;
|
||||
import ru.micord.ervu.kafka.service.ReplyingKafkaService;
|
||||
|
||||
/**
|
||||
|
|
@ -39,7 +40,7 @@ public class BaseReplyingKafkaServiceImpl implements ReplyingKafkaService {
|
|||
.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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -32,10 +32,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);
|
||||
}
|
||||
|
||||
@PostMapping(value = "/esia/refresh")
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
package ru.micord.ervu.security.esia.service;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.lang.invoke.MethodHandles;
|
||||
import java.net.URI;
|
||||
import java.net.URL;
|
||||
|
|
@ -18,22 +19,16 @@ 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 ervu.service.okopf.OkopfService;
|
||||
import org.springframework.context.support.MessageSourceAccessor;
|
||||
import org.springframework.stereotype.Service;
|
||||
import ru.micord.ervu.security.esia.exception.EsiaException;
|
||||
import ru.micord.ervu.security.esia.model.EmployeeModel;
|
||||
import ru.micord.ervu.security.esia.model.EsiaAccessToken;
|
||||
import ru.micord.ervu.security.esia.model.EsiaHeader;
|
||||
import ru.micord.ervu.security.esia.model.EsiaTokenResponse;
|
||||
import ru.micord.ervu.security.esia.model.FormUrlencoded;
|
||||
import ru.micord.ervu.security.esia.model.OrganizationModel;
|
||||
import ru.micord.ervu.security.esia.model.SignResponse;
|
||||
import ru.micord.ervu.security.esia.model.*;
|
||||
import ru.micord.ervu.security.esia.token.EsiaTokensStore;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.security.core.context.SecurityContext;
|
||||
import org.springframework.util.StringUtils;
|
||||
import ru.micord.ervu.security.esia.config.EsiaConfig;
|
||||
|
|
@ -52,6 +47,9 @@ 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.LocalizedException;
|
||||
import ru.cg.webbpm.modules.core.runtime.api.MessageBundleUtils;
|
||||
|
||||
import static ru.micord.ervu.security.webbpm.jwt.util.SecurityUtil.getCurrentUsername;
|
||||
|
||||
/**
|
||||
|
|
@ -60,6 +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;
|
||||
@Autowired
|
||||
|
|
@ -154,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;
|
||||
|
|
@ -246,28 +243,20 @@ public class EsiaAuthService {
|
|||
LOGGER.info("Thread {}: SignSecret: {}ms RequestAccessToken: {}ms VerifySecret: {}ms",
|
||||
Thread.currentThread().getId(), timeSignSecret, timeRequestAccessToken, timeVerifySecret);
|
||||
}
|
||||
String ervuId = null;
|
||||
try {
|
||||
hasRole = ulDataService.checkRole(esiaAccessTokenStr);
|
||||
String ervuId = getErvuId(esiaAccessTokenStr, prnOid);
|
||||
createTokenAndAddCookie(response, prnOid, ervuId, hasRole, expiresIn);
|
||||
ervuId = getErvuId(esiaAccessTokenStr, prnOid);
|
||||
if (!hasRole) {
|
||||
LOGGER.error("The user with id = " + prnOid + " does not have the required role");
|
||||
return new ResponseEntity<>(
|
||||
"Доступ запрещен. Пользователь должен быть включен в группу \"Сотрудник, ответственный за военно-учетную работу\" в ЕСИА",
|
||||
HttpStatus.FORBIDDEN
|
||||
);
|
||||
throw new LocalizedException("access_denied", MESSAGE_SOURCE);
|
||||
}
|
||||
return ResponseEntity.ok("Authentication successful");
|
||||
}
|
||||
catch (Exception e) {
|
||||
createTokenAndAddCookie(response, prnOid, null, hasRole , 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, hasRole , expiresIn);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -339,7 +328,7 @@ public class EsiaAuthService {
|
|||
String ervuId = getErvuId(esiaAccessTokenStr, prnOid);
|
||||
createTokenAndAddCookie(response, esiaAccessToken.getSbjId(), ervuId, true, expiresIn);
|
||||
}
|
||||
catch (Exception e) {
|
||||
catch (EsiaException | IOException | InterruptedException e) {
|
||||
throw new EsiaException(e);
|
||||
}
|
||||
}
|
||||
|
|
@ -395,7 +384,7 @@ public class EsiaAuthService {
|
|||
}
|
||||
}
|
||||
|
||||
public String getErvuId(String accessToken, String prnOid) {
|
||||
public String getErvuId(String accessToken, String prnOid) throws JsonProcessingException {
|
||||
long timeRequestPersonDataOrg = 0, timeRequestPersonDataEmployee = 0, timeRequestPersonDataChief = 0, timeRequestIdERVU = 0;
|
||||
try {
|
||||
long startTime = System.currentTimeMillis();
|
||||
|
|
@ -422,9 +411,6 @@ public class EsiaAuthService {
|
|||
}
|
||||
return ervuId;
|
||||
}
|
||||
catch (Exception e) {
|
||||
throw new EsiaException(e);
|
||||
}
|
||||
finally {
|
||||
LOGGER.info("Thread {}: RequestPersonDataOrg: {}ms RequestPersonDataEmployee: {}ms RequestPersonDataChief: {}ms RequestIdERVU: {}ms",
|
||||
Thread.currentThread().getId(), timeRequestPersonDataOrg, timeRequestPersonDataEmployee, timeRequestPersonDataChief, timeRequestIdERVU);
|
||||
|
|
|
|||
|
|
@ -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