Compare commits
16 Commits
4f0e0499ab
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
| 325e1493b2 | |||
| f2d764c7c2 | |||
| d7aebd21dc | |||
| a52d9822c8 | |||
| b73cbc3818 | |||
| 6d2b4c8b3e | |||
| 5bf5ac81ea | |||
| 34019b4d0d | |||
| de5263656e | |||
| f07097744a | |||
| 4b64cae8c5 | |||
| 00d39d73bc | |||
| eaff336f2a | |||
| bd35689d6c | |||
| 117c1e53df | |||
| 6b3a7327de |
41
README.md
41
README.md
@ -28,6 +28,47 @@ ____
|
|||||||
|
|
||||||
____
|
____
|
||||||
|
|
||||||
|
Запаковка в хранилище ключей
|
||||||
|
|
||||||
|
```sh
|
||||||
|
openssl pkcs12 -export \
|
||||||
|
-in authorization.crt \
|
||||||
|
-inkey authorization.key \
|
||||||
|
-out keystore.p12 \
|
||||||
|
-name tomcat \
|
||||||
|
-CAfile authorization-ca.crt \
|
||||||
|
-caname root \
|
||||||
|
-password pass:MFNX344yh4
|
||||||
|
```
|
||||||
|
|
||||||
|
📖 Расшифровка аргументов:
|
||||||
|
|
||||||
|
| Параметр | Назначение |
|
||||||
|
|---------------------------------|---------------------------------------------------------------------------------------------|
|
||||||
|
| `openssl pkcs12` | Утилита OpenSSL, работающая с PKCS#12 контейнерами (включают сертификаты и ключи). |
|
||||||
|
| `-export` | Указывает, что нужно экспортировать (создать) PKCS#12-файл. |
|
||||||
|
| `-in authorization.crt` | Основной (публичный) сертификат. Это то, что выдано для твоего домена. |
|
||||||
|
| `-inkey authorization.key` | Приватный ключ, соответствующий сертификату. Нужен для использования сертификата. |
|
||||||
|
| `-out keystore.p12` | Выходной файл (итоговый контейнер PKCS#12). Это будет твой `keystore`. |
|
||||||
|
| `-name tomcat` | Алиас (имя) для ключа в хранилище. Spring Boot (и Tomcat) по умолчанию ищет alias `tomcat`. |
|
||||||
|
| `-CAfile authorization-ca.crt` | (Необязательно) Цепочка доверенных сертификатов (например, корневой и промежуточные CA). |
|
||||||
|
| `-caname root` | Имя для CA-сертификата (используется внутри контейнера). |
|
||||||
|
| `-password pass: XXXXXX` | Пароль для защиты хранилища (в Spring Boot это `key-store-password`). |
|
||||||
|
|
||||||
|
|
||||||
|
### Получить токен для защиты от CSRF атак
|
||||||
|
https://istransit.kz/api/authorization/v02/get_request_token
|
||||||
|
|
||||||
|
GET запрос без данных.
|
||||||
|
|
||||||
|
Пример ответа:
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"ttl":600,
|
||||||
|
"token":"VTf8zvHKqK7QFJ0ZEyheOYAUrI7cRIbejxMzRKlMzYM"
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
### Получить список разрешений для пользователя по Access token
|
### Получить список разрешений для пользователя по Access token
|
||||||
https://istransit.kz/api/authorization/v02/access/
|
https://istransit.kz/api/authorization/v02/access/
|
||||||
|
|
||||||
|
|||||||
20
org-ccalm-jwt.md
Normal file
20
org-ccalm-jwt.md
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
Записываем значения в Vault:
|
||||||
|
|
||||||
|
Записываем в kv хранилище:
|
||||||
|
```sh
|
||||||
|
vault kv put org-ccalm/jwt server.ssl.key-store-password=M4yh4
|
||||||
|
```
|
||||||
|
|
||||||
|
Читаем так:
|
||||||
|
```sh
|
||||||
|
vault kv get org-ccalm/jwt
|
||||||
|
```
|
||||||
|
|
||||||
|
Должно вывести:
|
||||||
|
```text
|
||||||
|
Key Value
|
||||||
|
--- -----
|
||||||
|
server.ssl.key-store-password M4yh4
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
103
org-ccalm-jwt.yml
Normal file
103
org-ccalm-jwt.yml
Normal file
@ -0,0 +1,103 @@
|
|||||||
|
server:
|
||||||
|
port: 8082
|
||||||
|
ssl:
|
||||||
|
enabled: true
|
||||||
|
key-store: classpath:keystore.p12
|
||||||
|
key-store-password: MFNX344yh4
|
||||||
|
key-store-type: PKCS12
|
||||||
|
key-alias: tomcat
|
||||||
|
issuer:
|
||||||
|
name: ccalm
|
||||||
|
|
||||||
|
spring:
|
||||||
|
# config:
|
||||||
|
# import:
|
||||||
|
# - vault://org-ccalm/jwt
|
||||||
|
# - vault://org-ccalm/public
|
||||||
|
cloud:
|
||||||
|
vault:
|
||||||
|
enabled: false
|
||||||
|
# uri: http://localhost:8200
|
||||||
|
# authentication: APPROLE
|
||||||
|
# app-role:
|
||||||
|
# role-id: c0064fe2-8f0e-b317-7fe7-66f7405b45a1
|
||||||
|
# secret-id: 24f31c88-7185-0d93-9a51-e221c2925265
|
||||||
|
# kv:
|
||||||
|
# kv-version: 2
|
||||||
|
application:
|
||||||
|
name: org-ccalm-jwt
|
||||||
|
datasource:
|
||||||
|
url: jdbc:postgresql://10.0.0.1:5432/CCALM?ApplicationName=org_ccalm_main&connectTimeout=10000&socketTimeout=30000
|
||||||
|
#url: jdbc:postgresql://ccalm.org:5432/CCALM?ApplicationName=org_ccalm_jwt&ssl=true&sslmode=require&connectTimeout=10000&socketTimeout=10000&compression=gzip
|
||||||
|
#url: jdbc:postgresql://127.0.0.1:5432/CCALM?ApplicationName=org_ccalm_jwt&ssl=true&sslmode=require&connectTimeout=10000&socketTimeout=10000&compression=gzip
|
||||||
|
username: app_authorization_1
|
||||||
|
password: 4699KEE464YKR0AW0EE464YK0AEE464YK
|
||||||
|
driver-class-name: org.postgresql.Driver
|
||||||
|
hikari:
|
||||||
|
maximum-pool-size: 10
|
||||||
|
minimum-idle: 5
|
||||||
|
max-lifetime: 1740000
|
||||||
|
idle-timeout: 300000
|
||||||
|
connection-timeout: 20000
|
||||||
|
connection-test-query: SELECT 1
|
||||||
|
validation-timeout: 5000
|
||||||
|
leak-detection-threshold: 30000
|
||||||
|
keepalive-time: 60000
|
||||||
|
jpa:
|
||||||
|
properties:
|
||||||
|
hibernate:
|
||||||
|
dialect: org.hibernate.dialect.PostgreSQLDialect
|
||||||
|
redis:
|
||||||
|
host: 127.0.0.1
|
||||||
|
port: 6379
|
||||||
|
password: 9F3/NKWeOjd815vkadT2DcgVHf6fEpVQXw==
|
||||||
|
|
||||||
|
mail:
|
||||||
|
host: smtp.yandex.ru
|
||||||
|
port: 465
|
||||||
|
login: info@ccalm.org
|
||||||
|
password: fu2lpsoGPGiq1xlRm8ag
|
||||||
|
|
||||||
|
captcha:
|
||||||
|
key: PPExpv36jk4Vzda3NpYnXLfuHCLYXqaNrxlOH/Jr/1M=
|
||||||
|
time: 600
|
||||||
|
|
||||||
|
url:
|
||||||
|
reset: https://ccalm.org/api/authorization/v02/reset
|
||||||
|
main: https://ccalm.org/
|
||||||
|
|
||||||
|
personal_data:
|
||||||
|
key: 7dd2Nek1
|
||||||
|
|
||||||
|
private:
|
||||||
|
key: MIIEvAIBADANBgkqhkiG9w0BAQEFAASCBKYwggSiAgEAAoIBAQDNgtaCfu5QlhWfU8bJAooLoX+bo/ARsvoWUJf5NodkGOivze5Lqtu5eq6ptT+gVKK+IEsjpmDsFPMCE2CW7xLZfgbtrWmTPd+fiRb2Z/fMudedo166H5WEgS3+TDWKt7WkLA/3kqvIqdBotuL4BENwZj6CIjGNdG01RNsCaDA/vxTkzx9njz6kfgAda/+wbdOJNwjNRgIb9AyedQT5OKvqRXequzrrOKD9wrm1O4nv8lA6WFg5YEMSW7T6WRIeArZsQr1aHv6qkiu47YreApfdFIWHxd9QinA9WrLPYdWXONr7+xyvqS4MHSJh9ZmCvMsc/HcF3RHJgEwgiC8E6hiZAgMBAAECggEAByZOICwaTmNqTSi0+blE5DKyJdAGQhdf6/bR0rG69BiJv9QCPk+rZUCHYxATLpjDMKoe8xaOuKfh7GiQK7AVj8t6ojouOhkk9n/mdJwZWt38Slesq/z9TqbP2tD769+ISjXeOFa58zk1Lu9t5gL/9aEY+54E607pnbjPhb3qL819/7absLbY1y3GKw2Cwd7RfP8nOWj0ViwnalFjfg6YZS1BL5c9NSg41FzZolwPruZ/bBGbc3nMW2khpuK7CtRk1pRJHUNYuVCsaBU4M4sf3tlZQPOdB6eYmQ3xmPtdnHYB13s588KialXKFlAuO4zG0CFa8DfIKsWDv6xTC1cMgQKBgQD6CjJuu715oKob7ohDTfrSppk4PY/kxWhUkKyKVW1Y1jXQOcd4BwVSyH6s7N8pCSWMwWmoF/t/l2kIcAWNZnsbzAQ8TYOhp1THstXMVb6c7JOL3SQC5RjbgW1RWCalh7/4QVE0xYeEL3qv5I2t9215zKR87Z6LIdJkxxAsHgMSbQKBgQDSaOp0kJZPkQH/75ltaI9exczyoaf+5U/OrnqT2lpRwa+5wqUTPWpTFTCDcJdu8OKCgrKPOQ6NACuX4PbIW/jR+70w7nbC46Tx3JdDYxBlm+6MuHUs5RXufFDJyGoN8lJzoPGax3uxY1kxWwSaSIB0sVXV/P3PIE31I5DbarWjXQKBgQCrRyLm4anYUCtWuN4UpK0lcUPR17Hi9ysRioz2sbAWw53XRk0SNlT6MSc9E4GGnaJgOflDUTJRY4lqYzoac1HvZ6CbIkoCCRq1NRbpQu8wlYo4q8JITWDqtE0LBMRsbYId77hN2uWKse9r37cBrVULsxgWD7uj+QYjTI0Se3iFPQJ/SSYwXFXn68F98Hxb2q1/KnOZzMBmpzcRh8kg1EYVIFc1wF7rBMVVMY0sUIXUH72fAcBuU1yCsoJcpXCQWxeeaWIbY+eDYj3CGlOWQtct3CVZyZJXKkR6W27cp0oFlNOp1okddbHkTsc7Ou1prDmIbwk3zi0mD9wrPg4fTijK/QKBgQDrYEWT77dQLPcN3RTVn3Ua2d9aj/IWwC330I4qZq2SFKOaB/olnPA6fLNYToTWO70A2ZlsMtVepdThIeYFidkA7Lj7lTVYFdQQzREsO5908A1YWE4sgMEEdMc7n5xKT85vpkPOjBOLZYQ6JjDeWBMDxnXR9/txwbau4bsq3/QFuQ==
|
||||||
|
public:
|
||||||
|
key: MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAzYLWgn7uUJYVn1PGyQKKC6F/m6PwEbL6FlCX+TaHZBjor83uS6rbuXquqbU/oFSiviBLI6Zg7BTzAhNglu8S2X4G7a1pkz3fn4kW9mf3zLnXnaNeuh+VhIEt/kw1ire1pCwP95KryKnQaLbi+ARDcGY+giIxjXRtNUTbAmgwP78U5M8fZ48+pH4AHWv/sG3TiTcIzUYCG/QMnnUE+Tir6kV3qrs66zig/cK5tTuJ7/JQOlhYOWBDElu0+lkSHgK2bEK9Wh7+qpIruO2K3gKX3RSFh8XfUIpwPVqyz2HVlzja+/scr6kuDB0iYfWZgrzLHPx3Bd0RyYBMIIgvBOoYmQIDAQAB
|
||||||
|
access:
|
||||||
|
time: 600
|
||||||
|
refresh:
|
||||||
|
time: 43200
|
||||||
|
|
||||||
|
#logging.level.org.springframework.cloud.vault: DEBUG
|
||||||
|
|
||||||
|
#logging:
|
||||||
|
# level:
|
||||||
|
# org:
|
||||||
|
# springframework:
|
||||||
|
# cloud:
|
||||||
|
# vault: DEBUG
|
||||||
|
# org.springframework: WARN
|
||||||
|
# org.ccalm.jwt: ERROR
|
||||||
|
# com:
|
||||||
|
# zaxxer:
|
||||||
|
# hikari: WARN
|
||||||
|
|
||||||
|
|
||||||
|
# Swagger
|
||||||
|
springdoc:
|
||||||
|
api-docs:
|
||||||
|
enabled: true
|
||||||
|
path: /api-docs
|
||||||
|
swagger-ui:
|
||||||
|
enabled: true
|
||||||
|
path: /api-docs-ui
|
||||||
24
pom.xml
24
pom.xml
@ -5,12 +5,12 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<groupId>org.springframework.boot</groupId>
|
<groupId>org.springframework.boot</groupId>
|
||||||
<artifactId>spring-boot-starter-parent</artifactId>
|
<artifactId>spring-boot-starter-parent</artifactId>
|
||||||
<version>3.4.2</version>
|
<version>3.5.5</version>
|
||||||
<relativePath/> <!-- lookup parent from repository -->
|
<relativePath/> <!-- lookup parent from repository -->
|
||||||
</parent>
|
</parent>
|
||||||
<groupId>org.ccalm</groupId>
|
<groupId>org.ccalm</groupId>
|
||||||
<artifactId>jwt</artifactId>
|
<artifactId>jwt</artifactId>
|
||||||
<version>0.0.1-SNAPSHOT</version>
|
<version>1.0.1</version>
|
||||||
<name>jwt</name>
|
<name>jwt</name>
|
||||||
<description>jwt</description>
|
<description>jwt</description>
|
||||||
<properties>
|
<properties>
|
||||||
@ -66,7 +66,7 @@
|
|||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.springframework.cloud</groupId>
|
<groupId>org.springframework.cloud</groupId>
|
||||||
<artifactId>spring-cloud-starter-vault-config</artifactId>
|
<artifactId>spring-cloud-starter-vault-config</artifactId>
|
||||||
<version>4.2.0</version>
|
<version>4.3.0</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.postgresql</groupId>
|
<groupId>org.postgresql</groupId>
|
||||||
@ -79,16 +79,7 @@
|
|||||||
<artifactId>json</artifactId>
|
<artifactId>json</artifactId>
|
||||||
<version>20231013</version>
|
<version>20231013</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<!--dependency>
|
|
||||||
<groupId>io.jsonwebtoken</groupId>
|
|
||||||
<artifactId>jjwt-api</artifactId>
|
|
||||||
<version>0.11.5</version>
|
|
||||||
</dependency-->
|
|
||||||
<!--dependency>
|
|
||||||
<groupId>io.jsonwebtoken</groupId>
|
|
||||||
<artifactId>jjwt-api</artifactId>
|
|
||||||
<version>0.12.6</version>
|
|
||||||
</dependency-->
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>io.jsonwebtoken</groupId>
|
<groupId>io.jsonwebtoken</groupId>
|
||||||
<artifactId>jjwt-api</artifactId>
|
<artifactId>jjwt-api</artifactId>
|
||||||
@ -177,9 +168,16 @@
|
|||||||
<scope>provided</scope>
|
<scope>provided</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>net.logstash.logback</groupId>
|
||||||
|
<artifactId>logstash-logback-encoder</artifactId>
|
||||||
|
<version>8.1</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
<build>
|
<build>
|
||||||
|
<finalName>org-ccalm-jwt</finalName>
|
||||||
<plugins>
|
<plugins>
|
||||||
<plugin>
|
<plugin>
|
||||||
<groupId>org.springframework.boot</groupId>
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
|||||||
@ -16,7 +16,8 @@ public class GlobalExceptionHandler {
|
|||||||
@ExceptionHandler(NoHandlerFoundException.class)
|
@ExceptionHandler(NoHandlerFoundException.class)
|
||||||
public ResponseEntity<ErrorResponseModel> handleNotFound(NoHandlerFoundException ex) {
|
public ResponseEntity<ErrorResponseModel> handleNotFound(NoHandlerFoundException ex) {
|
||||||
ErrorResponseModel errorResponse = new ErrorResponseModel(
|
ErrorResponseModel errorResponse = new ErrorResponseModel(
|
||||||
10000 + HttpStatus.NOT_FOUND.value(),
|
HttpStatus.NOT_FOUND.value(),
|
||||||
|
10000,
|
||||||
"Not_Found",
|
"Not_Found",
|
||||||
UUID.randomUUID().toString()
|
UUID.randomUUID().toString()
|
||||||
);
|
);
|
||||||
@ -26,7 +27,8 @@ public class GlobalExceptionHandler {
|
|||||||
@ExceptionHandler(Exception.class)
|
@ExceptionHandler(Exception.class)
|
||||||
public ResponseEntity<ErrorResponseModel> handleException(Exception ex) {
|
public ResponseEntity<ErrorResponseModel> handleException(Exception ex) {
|
||||||
ErrorResponseModel errorResponse = new ErrorResponseModel(
|
ErrorResponseModel errorResponse = new ErrorResponseModel(
|
||||||
10000 + HttpStatus.NOT_FOUND.value(),
|
HttpStatus.NOT_FOUND.value(),
|
||||||
|
10000,
|
||||||
"Internal_Server_Error", //Collections.singletonList("Internal_Server_Error"),
|
"Internal_Server_Error", //Collections.singletonList("Internal_Server_Error"),
|
||||||
UUID.randomUUID().toString()
|
UUID.randomUUID().toString()
|
||||||
);
|
);
|
||||||
@ -36,7 +38,8 @@ public class GlobalExceptionHandler {
|
|||||||
@RequestMapping("/error")
|
@RequestMapping("/error")
|
||||||
public ResponseEntity<ErrorResponseModel> handleError() {
|
public ResponseEntity<ErrorResponseModel> handleError() {
|
||||||
ErrorResponseModel errorResponse = new ErrorResponseModel(
|
ErrorResponseModel errorResponse = new ErrorResponseModel(
|
||||||
10000 + HttpStatus.NOT_FOUND.value(),
|
HttpStatus.NOT_FOUND.value(),
|
||||||
|
10000,
|
||||||
"Unknown_error",
|
"Unknown_error",
|
||||||
UUID.randomUUID().toString()
|
UUID.randomUUID().toString()
|
||||||
);
|
);
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@ -51,16 +51,19 @@ public class SecurityConfig {
|
|||||||
protected boolean shouldNotFilter(HttpServletRequest request) throws ServletException {
|
protected boolean shouldNotFilter(HttpServletRequest request) throws ServletException {
|
||||||
String path = request.getRequestURI();
|
String path = request.getRequestURI();
|
||||||
if(!path.equals("/")) System.out.println(path); // https://127.0.0.1:8082/logout
|
if(!path.equals("/")) System.out.println(path); // https://127.0.0.1:8082/logout
|
||||||
|
|
||||||
|
//Define paths that do not require authorization
|
||||||
return path.equals("/") ||
|
return path.equals("/") ||
|
||||||
path.equals("/login") ||
|
path.equals("/login") ||
|
||||||
path.equals("/logout") ||
|
//path.equals("/logout") ||
|
||||||
path.equals("/create") ||
|
path.equals("/create") ||
|
||||||
path.equals("/captcha") ||
|
path.equals("/captcha") ||
|
||||||
path.equals("/restore") ||
|
path.equals("/restore") ||
|
||||||
path.equals("/reset") ||
|
path.equals("/reset") ||
|
||||||
path.equals("/get_session") ||
|
path.equals("/get_session") ||
|
||||||
path.equals("/get_request_token") ||
|
path.equals("/get_request_token") ||
|
||||||
path.equals("/access");
|
path.equals("/verification") ||
|
||||||
|
path.equals("/update");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -85,6 +88,7 @@ public class SecurityConfig {
|
|||||||
//Simple check
|
//Simple check
|
||||||
if (jwt_a == null || !jwt_a.contains(".")) {
|
if (jwt_a == null || !jwt_a.contains(".")) {
|
||||||
ErrorResponseModel errorResponse = new ErrorResponseModel(
|
ErrorResponseModel errorResponse = new ErrorResponseModel(
|
||||||
|
HttpServletResponse.SC_UNAUTHORIZED,
|
||||||
10000 + HttpServletResponse.SC_UNAUTHORIZED,
|
10000 + HttpServletResponse.SC_UNAUTHORIZED,
|
||||||
List.of("Please_log_in", "Please_send_a_valid_JWT_token"),
|
List.of("Please_log_in", "Please_send_a_valid_JWT_token"),
|
||||||
""
|
""
|
||||||
@ -107,6 +111,7 @@ public class SecurityConfig {
|
|||||||
|
|
||||||
if(userId==0L) {
|
if(userId==0L) {
|
||||||
ErrorResponseModel errorResponse = new ErrorResponseModel(
|
ErrorResponseModel errorResponse = new ErrorResponseModel(
|
||||||
|
HttpServletResponse.SC_UNAUTHORIZED,
|
||||||
10000 + HttpServletResponse.SC_UNAUTHORIZED,
|
10000 + HttpServletResponse.SC_UNAUTHORIZED,
|
||||||
List.of("Please_log_in"),
|
List.of("Please_log_in"),
|
||||||
""
|
""
|
||||||
|
|||||||
@ -0,0 +1,14 @@
|
|||||||
|
package org.ccalm.jwt;
|
||||||
|
|
||||||
|
import ch.qos.logback.classic.spi.IThrowableProxy;
|
||||||
|
import ch.qos.logback.classic.spi.ThrowableProxyUtil;
|
||||||
|
import ch.qos.logback.classic.pattern.ThrowableProxyConverter;
|
||||||
|
|
||||||
|
public class SingleLineThrowableProxyConverter extends ThrowableProxyConverter {
|
||||||
|
@Override
|
||||||
|
protected String throwableProxyToString(IThrowableProxy tp) {
|
||||||
|
if (tp == null) return "";
|
||||||
|
String stackTrace = ThrowableProxyUtil.asString(tp);
|
||||||
|
return stackTrace.replace("\r", "").replace("\n", "\\n").replace("\t", " ");
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -1,16 +1,20 @@
|
|||||||
package org.ccalm.jwt;
|
package org.ccalm.jwt;
|
||||||
|
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
import org.springframework.context.ApplicationContext;
|
import org.springframework.context.ApplicationContext;
|
||||||
import org.springframework.context.ApplicationContextAware;
|
import org.springframework.context.ApplicationContextAware;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
@Component
|
@Component
|
||||||
public class SpringContext implements ApplicationContextAware {
|
public class SpringContext implements ApplicationContextAware {
|
||||||
|
private static final Logger logger = LoggerFactory.getLogger(SpringContext.class);
|
||||||
private static ApplicationContext context;
|
private static ApplicationContext context;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setApplicationContext(ApplicationContext applicationContext) {
|
public void setApplicationContext(ApplicationContext applicationContext) {
|
||||||
context = applicationContext;
|
context = applicationContext;
|
||||||
|
logger.warn("App is start");
|
||||||
}
|
}
|
||||||
|
|
||||||
public static ApplicationContext getApplicationContext() {
|
public static ApplicationContext getApplicationContext() {
|
||||||
|
|||||||
@ -1,5 +1,6 @@
|
|||||||
package org.ccalm.jwt.models;
|
package org.ccalm.jwt.models;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||||
import io.swagger.v3.oas.annotations.media.Schema;
|
import io.swagger.v3.oas.annotations.media.Schema;
|
||||||
import org.springframework.http.HttpStatus;
|
import org.springframework.http.HttpStatus;
|
||||||
@ -7,6 +8,7 @@ import org.springframework.web.bind.annotation.ResponseStatus;
|
|||||||
|
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
@Schema(
|
@Schema(
|
||||||
description = "Error API response",
|
description = "Error API response",
|
||||||
@ -15,6 +17,9 @@ import java.util.List;
|
|||||||
|
|
||||||
public class ErrorResponseModel {
|
public class ErrorResponseModel {
|
||||||
|
|
||||||
|
@JsonIgnore
|
||||||
|
private int httpCode;
|
||||||
|
|
||||||
@Schema(description = "Error code", example = "10000")
|
@Schema(description = "Error code", example = "10000")
|
||||||
@JsonProperty("error_code")
|
@JsonProperty("error_code")
|
||||||
private int errorCode;
|
private int errorCode;
|
||||||
@ -31,39 +36,51 @@ public class ErrorResponseModel {
|
|||||||
@JsonProperty("error_marker")
|
@JsonProperty("error_marker")
|
||||||
private String errorMarker;
|
private String errorMarker;
|
||||||
|
|
||||||
public ErrorResponseModel(int errorCode) {
|
public ErrorResponseModel(int httpCode, int errorCode) {
|
||||||
|
this.httpCode = httpCode;
|
||||||
this.errorCode = errorCode;
|
this.errorCode = errorCode;
|
||||||
this.errorMessage = null;
|
this.errorMessage = null;
|
||||||
this.errorSetting = null;
|
this.errorSetting = null;
|
||||||
this.errorMarker = null;
|
this.errorMarker = UUID.randomUUID().toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
public ErrorResponseModel(int errorCode, List<String> errorMessage, String errorMarker) {
|
public ErrorResponseModel(int httpCode, int errorCode, List<String> errorMessage, String errorMarker) {
|
||||||
|
this.httpCode = httpCode;
|
||||||
this.errorCode = errorCode;
|
this.errorCode = errorCode;
|
||||||
this.errorMessage = errorMessage;
|
this.errorMessage = errorMessage;
|
||||||
this.errorMarker = errorMarker;
|
this.errorMarker = errorMarker;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ErrorResponseModel(int errorCode, String errorMessage, String errorMarker) {
|
public ErrorResponseModel(int httpCode, int errorCode, String errorMessage, String errorMarker) {
|
||||||
|
this.httpCode = httpCode;
|
||||||
this.errorCode = errorCode;
|
this.errorCode = errorCode;
|
||||||
this.errorMessage = Collections.singletonList(errorMessage);
|
this.errorMessage = Collections.singletonList(errorMessage);
|
||||||
this.errorMarker = errorMarker;
|
this.errorMarker = errorMarker;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ErrorResponseModel(int errorCode, String errorMessage, String errorSetting, String errorMarker) {
|
public ErrorResponseModel(int httpCode, int errorCode, String errorMessage, String errorSetting, String errorMarker) {
|
||||||
|
this.httpCode = httpCode;
|
||||||
this.errorCode = errorCode;
|
this.errorCode = errorCode;
|
||||||
this.errorMessage = Collections.singletonList(errorMessage);
|
this.errorMessage = Collections.singletonList(errorMessage);
|
||||||
this.errorSetting = Collections.singletonList(errorSetting);
|
this.errorSetting = Collections.singletonList(errorSetting);
|
||||||
this.errorMarker = errorMarker;
|
this.errorMarker = errorMarker;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ErrorResponseModel(int errorCode, List<String> errorMessage, List<String> errorSetting, String errorMarker) {
|
public ErrorResponseModel(int httpCode, int errorCode, List<String> errorMessage, List<String> errorSetting, String errorMarker) {
|
||||||
|
this.httpCode = httpCode;
|
||||||
this.errorCode = errorCode;
|
this.errorCode = errorCode;
|
||||||
this.errorMessage = errorMessage;
|
this.errorMessage = errorMessage;
|
||||||
this.errorSetting = errorSetting;
|
this.errorSetting = errorSetting;
|
||||||
this.errorMarker = errorMarker;
|
this.errorMarker = errorMarker;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public int getHttp_code() {
|
||||||
|
return httpCode;
|
||||||
|
}
|
||||||
|
public void setHttp_code(int errorCode) {
|
||||||
|
this.httpCode = httpCode;
|
||||||
|
}
|
||||||
|
|
||||||
public int getError_code() {
|
public int getError_code() {
|
||||||
return errorCode;
|
return errorCode;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -31,6 +31,10 @@ public class NewUserModel {
|
|||||||
private String code;
|
private String code;
|
||||||
@JsonProperty("token")
|
@JsonProperty("token")
|
||||||
private String token;
|
private String token;
|
||||||
|
|
||||||
|
@JsonProperty("password")
|
||||||
|
private String password;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
public String getCountry() {
|
public String getCountry() {
|
||||||
if(country==null) return "";
|
if(country==null) return "";
|
||||||
|
|||||||
16
src/main/java/org/ccalm/jwt/models/SettingNameModel.java
Normal file
16
src/main/java/org/ccalm/jwt/models/SettingNameModel.java
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
package org.ccalm.jwt.models;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||||
|
import com.fasterxml.jackson.annotation.JsonAutoDetect;
|
||||||
|
import io.swagger.v3.oas.annotations.media.Schema;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
@JsonAutoDetect(fieldVisibility = JsonAutoDetect.Visibility.ANY)
|
||||||
|
@Schema(description = "Model for getting actions by name")
|
||||||
|
public class SettingNameModel {
|
||||||
|
|
||||||
|
@Schema(description = "Action name", example = "arm_")
|
||||||
|
@JsonProperty("action_name")
|
||||||
|
private String setting_name;
|
||||||
|
}
|
||||||
20
src/main/java/org/ccalm/jwt/models/VerificationModel.java
Normal file
20
src/main/java/org/ccalm/jwt/models/VerificationModel.java
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
package org.ccalm.jwt.models;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Getter;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
import lombok.Setter;
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
@Setter
|
||||||
|
@NoArgsConstructor
|
||||||
|
@AllArgsConstructor
|
||||||
|
public class VerificationModel {
|
||||||
|
@JsonProperty("email")
|
||||||
|
private String email;
|
||||||
|
@JsonProperty("code")
|
||||||
|
private String code;
|
||||||
|
@JsonProperty("token")
|
||||||
|
private String token;
|
||||||
|
}
|
||||||
@ -19,30 +19,34 @@ public class CustomException extends Exception {
|
|||||||
@Getter
|
@Getter
|
||||||
private boolean saveToLog = false;
|
private boolean saveToLog = false;
|
||||||
|
|
||||||
public CustomException(int errorCode, String errorMessage, String marker, boolean saveToLog) {
|
public CustomException(int httpCode, int errorCode, String errorMessage, String marker, boolean saveToLog) {
|
||||||
super(errorMessage);
|
super(errorMessage);
|
||||||
error = new ErrorResponseModel(errorCode, errorMessage, marker);
|
error = new ErrorResponseModel(httpCode, errorCode, errorMessage, marker);
|
||||||
this.saveToLog = saveToLog;
|
this.saveToLog = saveToLog;
|
||||||
}
|
}
|
||||||
|
|
||||||
public CustomException(int errorCode, String errorMessage, String errorSetting, String marker, boolean saveToLog) {
|
public CustomException(int httpCode, int errorCode, String errorMessage, String errorSetting, String marker, boolean saveToLog) {
|
||||||
super(errorMessage);
|
super(errorMessage);
|
||||||
error = new ErrorResponseModel(errorCode, errorMessage, errorSetting, marker);
|
error = new ErrorResponseModel(httpCode, errorCode, errorMessage, errorSetting, marker);
|
||||||
this.saveToLog = saveToLog;
|
this.saveToLog = saveToLog;
|
||||||
}
|
}
|
||||||
|
|
||||||
public CustomException(int errorCode, List<String> errorMessages, String marker, boolean saveToLog) {
|
public CustomException(int httpCode, int errorCode, List<String> errorMessages, String marker, boolean saveToLog) {
|
||||||
super(String.join(" ", errorMessages));
|
super(String.join(" ", errorMessages));
|
||||||
error = new ErrorResponseModel(errorCode, errorMessages, marker);
|
error = new ErrorResponseModel(httpCode, errorCode, errorMessages, marker);
|
||||||
this.saveToLog = saveToLog;
|
this.saveToLog = saveToLog;
|
||||||
}
|
}
|
||||||
|
|
||||||
public CustomException(int errorCode, List<String> errorMessages, List<String> errorSettings, String marker, boolean saveToLog) {
|
public CustomException(int httpCode, int errorCode, List<String> errorMessages, List<String> errorSettings, String marker, boolean saveToLog) {
|
||||||
super(String.join(" ", errorMessages));
|
super(String.join(" ", errorMessages));
|
||||||
error = new ErrorResponseModel(errorCode, errorMessages, errorSettings, marker);
|
error = new ErrorResponseModel(httpCode, errorCode, errorMessages, errorSettings, marker);
|
||||||
this.saveToLog = saveToLog;
|
this.saveToLog = saveToLog;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public int getHttpCode() {
|
||||||
|
return error.getHttp_code();
|
||||||
|
}
|
||||||
|
|
||||||
public int getErrorCode() {
|
public int getErrorCode() {
|
||||||
return error.getError_code();
|
return error.getError_code();
|
||||||
}
|
}
|
||||||
|
|||||||
Binary file not shown.
BIN
src/main/resources/keystore.p12
Normal file
BIN
src/main/resources/keystore.p12
Normal file
Binary file not shown.
@ -1,38 +1,67 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<configuration>
|
<configuration>
|
||||||
|
|
||||||
|
<!-- Ваш кастомный conversionRule для single-line исключений -->
|
||||||
|
<conversionRule conversionWord="exOneLine" converterClass="org.ccalm.dbms.SingleLineThrowableProxyConverter"/>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
<!-- Please check if the user has access to the directory from which the application is being executed -->
|
|
||||||
<property name="LOGS" value="logs" />
|
<property name="LOGS" value="logs" />
|
||||||
<springProperty scope="context" name="appName" source="spring.application.name"/>
|
<springProperty scope="context" name="appName" source="spring.application.name"/>
|
||||||
|
|
||||||
<appender name="FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
|
<appender name="FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
|
||||||
<file>${LOGS}/${appName}.log</file>
|
<file>${LOGS}/${appName}.log</file>
|
||||||
<encoder>
|
<encoder class="net.logstash.logback.encoder.LogstashEncoder">
|
||||||
<pattern>{"timestamp":"%d{yyyy-MM-dd'T'HH:mm:ss.SSS'Z'}","thread":"[%thread]","level":"%level","logger":"%logger{36}","marker":"%X{marker}","message":"%msg"}%n</pattern>
|
<!-- Кастомные имена полей -->
|
||||||
|
<fieldNames>
|
||||||
|
<timestamp>timestamp</timestamp> <!-- Без @ -->
|
||||||
|
<level>level</level>
|
||||||
|
<message>message</message>
|
||||||
|
<stack_trace>exception</stack_trace>
|
||||||
|
<version>[ignore]</version>
|
||||||
|
<threadName>[ignore]</threadName>
|
||||||
|
<loggerName>[ignore]</loggerName>
|
||||||
|
<levelValue>[ignore]</levelValue>
|
||||||
|
<mdc>[ignore]</mdc>
|
||||||
|
</fieldNames>
|
||||||
|
|
||||||
|
<!-- Формат timestamp -->
|
||||||
|
<timestampPattern>yyyy-MM-dd'T'HH:mm:ss.SSS'Z'</timestampPattern>
|
||||||
|
<timestampTimeZone>UTC</timestampTimeZone>
|
||||||
|
|
||||||
|
<!-- Включаем маркеры (tags для MarkerFactory) -->
|
||||||
|
<includeTags>true</includeTags>
|
||||||
|
|
||||||
|
<!-- Отключаем лишние данные -->
|
||||||
|
<includeCallerData>false</includeCallerData>
|
||||||
|
<includeContext>false</includeContext>
|
||||||
|
|
||||||
|
<!-- Single-line исключения -->
|
||||||
|
<throwableConverter class="net.logstash.logback.stacktrace.ShortenedThrowableConverter">
|
||||||
|
<maxDepthPerThrowable>1</maxDepthPerThrowable>
|
||||||
|
<maxLength>1024</maxLength>
|
||||||
|
<shortenedClassNameLength>20</shortenedClassNameLength>
|
||||||
|
<exclude>$$FastClassByCGLIB$$</exclude>
|
||||||
|
<exclude>$$EnhancerBySpringCGLIB$$</exclude>
|
||||||
|
</throwableConverter>
|
||||||
</encoder>
|
</encoder>
|
||||||
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
|
<rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
|
||||||
<fileNamePattern>${LOGS}/${appName}.%d{yyyy-MM-dd}.%i.log</fileNamePattern>
|
<fileNamePattern>${LOGS}/${appName}.%d{yyyy-MM-dd}.%i.log</fileNamePattern>
|
||||||
|
<maxFileSize>100MB</maxFileSize>
|
||||||
<maxHistory>30</maxHistory>
|
<maxHistory>30</maxHistory>
|
||||||
<timeBasedFileNamingAndTriggeringPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">
|
<totalSizeCap>3GB</totalSizeCap>
|
||||||
<maxFileSize>100MB</maxFileSize>
|
|
||||||
</timeBasedFileNamingAndTriggeringPolicy>
|
|
||||||
</rollingPolicy>
|
</rollingPolicy>
|
||||||
</appender>
|
</appender>
|
||||||
|
|
||||||
<appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender">
|
<appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender">
|
||||||
<encoder>
|
<encoder>
|
||||||
<pattern>%d{yyyy-MM-dd'T'HH:mm:ss.SSS'Z'} | %level | %logger{36} | %X{marker} | %msg%n</pattern>
|
<pattern>
|
||||||
|
%d{yyyy-MM-dd'T'HH:mm:ss.SSS'Z'} | %level | %logger{36} | %marker | %msg%n
|
||||||
|
</pattern>
|
||||||
</encoder>
|
</encoder>
|
||||||
</appender>
|
</appender>
|
||||||
|
|
||||||
<root level="info">
|
<root level="info">
|
||||||
<!--root level="warn"-->
|
|
||||||
<appender-ref ref="FILE" />
|
<appender-ref ref="FILE" />
|
||||||
<appender-ref ref="CONSOLE" />
|
<appender-ref ref="CONSOLE" />
|
||||||
</root>
|
</root>
|
||||||
|
|
||||||
|
|
||||||
</configuration>
|
</configuration>
|
||||||
Reference in New Issue
Block a user