!!!СВАГГЕР!!!

This commit is contained in:
Igor I
2025-01-31 19:51:24 +05:00
parent c374fb881e
commit e7d5085f94
17 changed files with 347 additions and 215 deletions

View File

@ -24,7 +24,10 @@ spring:
connection-timeout: 30000 connection-timeout: 30000
connection-test-query: SELECT 1 connection-test-query: SELECT 1
validation-timeout: 5000 validation-timeout: 5000
jpa:
properties:
hibernate:
dialect: org.hibernate.dialect.PostgreSQLDialect
redis: redis:
host: 192.168.6.25 host: 192.168.6.25
port: 6379 port: 6379
@ -58,3 +61,11 @@ logging:
com: com:
zaxxer: zaxxer:
hikari: DEBUG hikari: DEBUG
springdoc:
api-docs:
enabled: false
path: /api-docs
swagger-ui:
enabled: true
path: /api-docs-ui

View File

@ -10,7 +10,7 @@ issuer:
spring: spring:
application: application:
name: kz_mcp_jwt name: kz_istransit_jwt
datasource: datasource:
url: jdbc:postgresql://mcp.kz:5432/mcp url: jdbc:postgresql://mcp.kz:5432/mcp
username: igor username: igor
@ -24,6 +24,10 @@ spring:
connection-timeout: 30000 connection-timeout: 30000
connection-test-query: SELECT 1 connection-test-query: SELECT 1
validation-timeout: 30000 validation-timeout: 30000
jpa:
properties:
hibernate:
dialect: org.hibernate.dialect.PostgreSQLDialect
redis: redis:
host: 127.0.0.1 host: 127.0.0.1
port: 6379 port: 6379
@ -57,3 +61,11 @@ logging:
com: com:
zaxxer: zaxxer:
hikari: DEBUG hikari: DEBUG
springdoc:
api-docs:
enabled: true
path: /api-docs
swagger-ui:
enabled: true
path: /api-docs-ui

71
kz_istransit_test_jwt.yml Normal file
View File

@ -0,0 +1,71 @@
server:
port: 8082
ssl:
enabled: true
key-store: classpath:keystore.jks
key-store-password: MFNX344yh4
key-store-type: PKCS12
issuer:
name: istransit
spring:
application:
name: kz_istransit_jwt
datasource:
url: jdbc:postgresql://mcp.kz:5432/mcp
username: igor
password: VnzbUdcePSLtg22ktz13
driver-class-name: org.postgresql.Driver
hikari:
maximum-pool-size: 10
minimum-idle: 5
max-lifetime: 600000
idle-timeout: 60000
connection-timeout: 30000
connection-test-query: SELECT 1
validation-timeout: 30000
jpa:
properties:
hibernate:
dialect: org.hibernate.dialect.PostgreSQLDialect
redis:
host: 127.0.0.1
port: 6379
password: 9F3/NKWeOjd815vkadT2DcgVHf6fEpVQXw==
public:
key: MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA30j+pSoKFHSdSulIGzdFtg+z+ANJPOSVFJ6jvehj1sonOqQsI2rz539+FgIrsDZE8iydFAlQNxS8vqYtWiQSksAUId7aOY/eq7mFkGW+U5xIA2OPgIvN0uhW1Edm85jS7aAg/P/c+lLHnPzQIFdsgVrAh4esFvVS10Pj6TjJVprDj0jOraIw84GVt0gYXZTudcvZavWcmGV1mQJf0jDIHQsCRcMJAE2lzBIKpJGPPZke9xs25lm8feTFR0NNjDNvCG4dYAimyAH36UslXa/zIfRB/7r4AB9KPBFxGe8szK1EcXbJY+paq+TazZJ8Lo8nEmpehCdHUNdD9iWtiYRjNQIDAQAB
private:
key: MIIEvAIBADANBgkqhkiG9w0BAQEFAASCBKYwggSiAgEAAoIBAQDfSP6lKgoUdJ1K6UgbN0W2D7P4A0k85JUUnqO96GPWyic6pCwjavPnf34WAiuwNkTyLJ0UCVA3FLy+pi1aJBKSwBQh3to5j96ruYWQZb5TnEgDY4+Ai83S6FbUR2bzmNLtoCD8/9z6Usec/NAgV2yBWsCHh6wW9VLXQ+PpOMlWmsOPSM6tojDzgZW3SBhdlO51y9lq9ZyYZXWZAl/SMMgdCwJFwwkATaXMEgqkkY89mR73GzbmWbx95MVHQ02MM28Ibh1gCKbIAffpSyVdr/Mh9EH/uvgAH0o8EXEZ7yzMrURxdslj6lqr5NrNknwujycSal6EJ0dQ10P2Ja2JhGM1AgMBAAECggEAPWsLuIzOxv+owJFYpzvV7hV1sJPe0mQh6dEVQ0ioJc3naob8KSXjP1tfaFhigg77eg3xizBgozYOEPcO5IulnD4/i22MY2cCngPjDGwgJUmIuX3qXDaYgBouwCd/1yPDaV+xk0YiF60rgTA9Y5gInbBD40Pbf1kt106yY1WedDaMaogilC6nZwde7H6UQrjoxQ3fSyw9brH04Vma7awcaEYQ6C0NM4uMJFws9jnwDXkYh0QnPW5eIIf9gmr2a+FtKtqlQyZiCjrQOJuU2TQo9wgKiOkVRIfmivXbt5I1O7SkPPUl2mtQAjbZxtHqooLC6It9svO/4rRJY0egjvsGZQKBgQDwCTGhExOahz/UH0I58Ksq44Zz6c6wt7Pt8U2S9L4Sfgjt4Gxu5XcdgMchZHu+xQtONpd7HWO4d9zK1IIHgJ/4IBMA2Lcp7EglHsnuc9II31EU9uP6Ar3yD3UC3zP/lszQs7t3Tagpq3I0bUuSnKH+SMW+mKztg5Xiu4x72HeIGwKBgQDuIpryaOhCEuwN6VguTSStNJe6fxI1NlHLF0anacuT43MotsRXYWRKWdu2nkupB3SqY+Lxipibu8I5CkWoKV8pbGYSqW8YDSzxoSPocTrbkuai7mczMSBCtFZ3nDFx1J3O2IJZaBT4OA+HEVaj+rzeyEYrwACmtSAl+YBNXE4W7wKBgH4ohuIe0aXdQgnuJ/Ol74DKNueDUnQFCVedBOWhJqk3ft/vnW4nwpRKE98UHgnlLIz+Gl3F05ynuu8MBA+HZgyWZwaB4LrzCfQgm4dtbk3leYsoPCgx+r1XrGtG/uBt1NY4MOaCdUj5aDvv2dGD64xnmS8UtYbcKxIQ+sQ4wJJTAoGAVOcVo3Pvyw8ABn25qNhsSSzFJAMGNN6nDue/kxTPNm0Ts+Jl4lmg7jlXcqbBhwRXfiCa20901aF9v+R/rVMC0LwLMIAkUcjwyz2OleM4/uxDOrgRJ1lOjTnK0l5n6pPJp+PdpY7MWytxrdBquZA+Ipf5HMQZ91YAnkl0iyBr3xUCgYBNBIb0fVTlAf7KJ4urjOE+305oRmEU5eHK2KiAViPDj16BuPy/hE11BnZE5HT4AMfuAm6AmLdrdiyb2iROMrsEQ8AFsGaFsY/njXqV75nNWceLpqrMk1FcYmnAEv0X/RhvsPzv79RzEf9jyjZlQ1XMfBfuuwwjWaUTLBcQhGFOqQ==
access:
time: 600
refresh:
time: 43200
captcha:
key: PPExpv36jk4Vzda3NpYnXLfuHCLYXqaNrxlOH/Jr/1M=
time: 600
mail:
host: smtp.yandex.ru
port: 465
login: info@ccalm.org
password: fu2lpsoGPGiq1xlRm8ag
url:
reset: https://mcp.test/api/authorization/login/reset
main: https://mcp.test/
logging:
level:
com:
zaxxer:
hikari: DEBUG
springdoc:
api-docs:
enabled: true
path: /api-docs
swagger-ui:
enabled: true
path: /api-docs-ui

View File

@ -24,6 +24,10 @@ spring:
connection-timeout: 30000 connection-timeout: 30000
connection-test-query: SELECT 1 connection-test-query: SELECT 1
validation-timeout: 30000 validation-timeout: 30000
jpa:
properties:
hibernate:
dialect: org.hibernate.dialect.PostgreSQLDialect
redis: redis:
host: 127.0.0.1 host: 127.0.0.1
port: 6379 port: 6379
@ -57,3 +61,11 @@ logging:
com: com:
zaxxer: zaxxer:
hikari: DEBUG hikari: DEBUG
springdoc:
api-docs:
enabled: true
path: /api-docs
swagger-ui:
enabled: true
path: /api-docs-ui

View File

@ -26,6 +26,10 @@ spring:
connection-test-query: SELECT 1 connection-test-query: SELECT 1
validation-timeout: 5000 validation-timeout: 5000
validation-interval: 60000 validation-interval: 60000
jpa:
properties:
hibernate:
dialect: org.hibernate.dialect.PostgreSQLDialect
redis: redis:
host: 127.0.0.1 host: 127.0.0.1
port: 6379 port: 6379
@ -64,3 +68,11 @@ refresh:
# com: # com:
# zaxxer: # zaxxer:
# hikari: WARN # hikari: WARN
springdoc:
api-docs:
enabled: true
path: /api-docs
swagger-ui:
enabled: true
path: /api-docs-ui

66
pom.xml
View File

@ -5,7 +5,7 @@
<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.3.3</version> <version>3.4.2</version>
<relativePath/> <!-- lookup parent from repository --> <relativePath/> <!-- lookup parent from repository -->
</parent> </parent>
<groupId>org.ccalm</groupId> <groupId>org.ccalm</groupId>
@ -18,26 +18,46 @@
</properties> </properties>
<dependencies> <dependencies>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>2.0.16</version>
</dependency>
<dependency> <dependency>
<groupId>org.springframework.boot</groupId> <groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-redis</artifactId> <artifactId>spring-boot-starter-data-redis</artifactId>
<version>3.3.3</version> <exclusions>
<!--exclusion>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-to-slf4j</artifactId>
</exclusion-->
<exclusion>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-api</artifactId>
</exclusion>
<!--exclusion>
<groupId>org.slf4j</groupId>
<artifactId>jul-to-slf4j</artifactId>
</exclusion-->
</exclusions>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.springframework.boot</groupId> <groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId> <artifactId>spring-boot-starter-web</artifactId>
<version>3.3.3</version> </dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-logging</artifactId>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.springframework.boot</groupId> <groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId> <artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope> <scope>test</scope>
<version>3.3.3</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.springframework.boot</groupId> <groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId> <artifactId>spring-boot-starter-data-jpa</artifactId>
<version>3.3.3</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.postgresql</groupId> <groupId>org.postgresql</groupId>
@ -71,22 +91,28 @@
<groupId>redis.clients</groupId> <groupId>redis.clients</groupId>
<artifactId>jedis</artifactId> <artifactId>jedis</artifactId>
<version>3.7.0</version> <version>3.7.0</version>
<exclusions>
<exclusion>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</exclusion>
</exclusions>
</dependency> </dependency>
<dependency> <dependency>
<groupId>net.logicsquad</groupId> <groupId>net.logicsquad</groupId>
<artifactId>nanocaptcha</artifactId> <artifactId>nanocaptcha</artifactId>
<version>2.1</version> <version>2.1</version>
</dependency> </dependency>
<dependency> <!--dependency>
<groupId>ch.qos.logback</groupId> <groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId> <artifactId>logback-classic</artifactId>
<version>1.5.6</version> <version>1.5.16</version>
</dependency> </dependency-->
<dependency> <!--dependency>
<groupId>net.logstash.logback</groupId> <groupId>net.logstash.logback</groupId>
<artifactId>logstash-logback-encoder</artifactId> <artifactId>logstash-logback-encoder</artifactId>
<version>6.6</version> <!-- Замените на актуальную версию --> <version>6.6</version>
</dependency> </dependency-->
<dependency> <dependency>
<groupId>javax.mail</groupId> <groupId>javax.mail</groupId>
<artifactId>mail</artifactId> <artifactId>mail</artifactId>
@ -113,6 +139,24 @@
<version>1.5.0</version> <version>1.5.0</version>
</dependency> </dependency>
<dependency>
<groupId>org.springdoc</groupId>
<artifactId>springdoc-openapi-starter-webmvc-ui</artifactId>
<version>2.8.4</version>
</dependency>
<dependency>
<groupId>javax.annotation</groupId>
<artifactId>javax.annotation-api</artifactId>
<version>1.3.2</version>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.36</version>
<scope>provided</scope>
</dependency>
</dependencies> </dependencies>
<build> <build>

View File

@ -1,7 +1,7 @@
package org.ccalm.jwt; package org.ccalm.jwt;
import org.apache.logging.log4j.LogManager; import org.slf4j.Logger;
import org.apache.logging.log4j.Logger; import org.slf4j.LoggerFactory;
import org.springframework.boot.SpringApplication; import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.ComponentScan; import org.springframework.context.annotation.ComponentScan;
@ -10,7 +10,7 @@ import org.springframework.context.annotation.ComponentScan;
@ComponentScan(basePackages = {"org.ccalm.jwt"}) @ComponentScan(basePackages = {"org.ccalm.jwt"})
public class JwtApplication { public class JwtApplication {
private static final Logger logger = LogManager.getLogger(JwtApplication.class); private static final Logger logger = LoggerFactory.getLogger(JwtApplication.class);
public static void main(String[] args) { public static void main(String[] args) {
logger.info("Start JwtApplication"); logger.info("Start JwtApplication");

View File

@ -1,14 +1,16 @@
package org.ccalm.jwt; package org.ccalm.jwt;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.media.Content;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import com.warrenstrange.googleauth.GoogleAuthenticator; import com.warrenstrange.googleauth.GoogleAuthenticator;
import com.warrenstrange.googleauth.GoogleAuthenticatorKey; import com.warrenstrange.googleauth.GoogleAuthenticatorKey;
import org.ccalm.jwt.models.*; import org.ccalm.jwt.models.*;
import org.ccalm.jwt.tools.*; import org.ccalm.jwt.tools.*;
import com.zaxxer.hikari.HikariDataSource; import com.zaxxer.hikari.HikariDataSource;
import io.jsonwebtoken.*; import io.jsonwebtoken.*;
import io.jsonwebtoken.security.Keys;
import jakarta.servlet.ServletContext; import jakarta.servlet.ServletContext;
import jakarta.servlet.http.Cookie;
import jakarta.servlet.http.HttpServletRequest; import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse; import jakarta.servlet.http.HttpServletResponse;
import net.logicsquad.nanocaptcha.content.LatinContentProducer; import net.logicsquad.nanocaptcha.content.LatinContentProducer;
@ -20,10 +22,10 @@ import org.json.JSONArray;
import org.json.JSONException; import org.json.JSONException;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Value;
import org.springframework.core.io.ClassPathResource;
import org.springframework.dao.DataAccessException; import org.springframework.dao.DataAccessException;
import org.springframework.http.HttpHeaders; import org.springframework.http.HttpHeaders;
import org.springframework.http.ResponseCookie; import org.springframework.http.ResponseCookie;
import org.springframework.http.ResponseEntity;
import org.springframework.jdbc.BadSqlGrammarException; import org.springframework.jdbc.BadSqlGrammarException;
import org.springframework.stereotype.Controller; import org.springframework.stereotype.Controller;
import org.springframework.lang.Nullable; import org.springframework.lang.Nullable;
@ -36,16 +38,12 @@ import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate;
import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.Logger;
import org.apache.commons.text.RandomStringGenerator; import org.apache.commons.text.RandomStringGenerator;
import redis.clients.jedis.Jedis;
import java.net.URLEncoder; import java.net.URLEncoder;
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.security.KeyFactory; import java.security.KeyFactory;
import java.security.PrivateKey; import java.security.PrivateKey;
import java.security.PublicKey; import java.security.PublicKey;
import javax.crypto.SecretKey;
import javax.crypto.spec.SecretKeySpec;
import javax.imageio.ImageIO; import javax.imageio.ImageIO;
import javax.mail.MessagingException; import javax.mail.MessagingException;
import java.awt.*; import java.awt.*;
@ -53,14 +51,11 @@ import java.awt.image.BufferedImage;
import java.io.*; import java.io.*;
import java.security.spec.PKCS8EncodedKeySpec; import java.security.spec.PKCS8EncodedKeySpec;
import java.security.spec.X509EncodedKeySpec; import java.security.spec.X509EncodedKeySpec;
import java.sql.*;
import java.sql.Date; import java.sql.Date;
import java.time.Duration; import java.time.Duration;
import java.time.Instant; import java.time.Instant;
import java.util.*; import java.util.*;
import java.util.List; import java.util.List;
import java.util.jar.Attributes;
import java.util.jar.JarFile;
import java.util.regex.Pattern; import java.util.regex.Pattern;
import java.io.InputStream; import java.io.InputStream;
import java.util.Properties; import java.util.Properties;
@ -125,6 +120,7 @@ public class MainController implements ServletContextAware {
this.jdbcTemplate = jdbcTemplate; this.jdbcTemplate = jdbcTemplate;
} }
//---------------------------------------------------------------------------
public String createStrJSONError(int code, String message, String setting, String marker) { public String createStrJSONError(int code, String message, String setting, String marker) {
JSONObject json = new JSONObject(); JSONObject json = new JSONObject();
try { try {
@ -137,24 +133,24 @@ public class MainController implements ServletContextAware {
} }
return json.toString(); return json.toString();
} }
//---------------------------------------------------------------------------
public JSONObject createJSONError(int code, String message, String setting, String marker) { public JSONObject createJSONError(int code, String message, String setting, String marker) {
JSONObject json = new JSONObject(); JSONObject json = new JSONObject();
try { try {
json.put("error_code", code); json.put("error_code", code);
json.put("error_message", Arrays.asList(message)); json.put("error_message", Arrays.asList(message));
json.put("error_setting", Arrays.asList(setting)); json.put("error_setting", Arrays.asList(setting));
json.put("error_marker", Arrays.asList(setting)); json.put("error_marker", marker);
} catch (JSONException e) { } catch (JSONException e) {
logger.error(e); logger.error(e);
} }
return json; return json;
} }
//---------------------------------------------------------------------------
public String createHTMLError(int code, String message) { public String createHTMLError(int code, String message) {
return "<!DOCTYPE html><html><head><meta http-equiv=\"refresh\" content=\"0; url='" + this.url_main + "?msg=" + message + "'\" /></head><body></body></html>"; return "<!DOCTYPE html><html><head><meta http-equiv=\"refresh\" content=\"0; url='" + this.url_main + "?msg=" + message + "'\" /></head><body></body></html>";
} }
//---------------------------------------------------------------------------
public static int countOccurrences(String str, char symbol) { public static int countOccurrences(String str, char symbol) {
int count = 0; int count = 0;
@ -245,7 +241,6 @@ public class MainController implements ServletContextAware {
return true; return true;
} }
/** /**
* Create a Access Cookie * Create a Access Cookie
*/ */
@ -270,9 +265,10 @@ public class MainController implements ServletContextAware {
return true; return true;
} }
@RequestMapping(value = "/",method = {RequestMethod.POST,RequestMethod.GET},produces = "application/json;charset=utf-8") @Operation(summary = "Get API version(date) of build", description = "Returns the date and API name")
@RequestMapping(value = "/",method = RequestMethod.GET,produces = "application/json;charset=utf-8")
@ResponseBody @ResponseBody
public String index(Model model,@RequestParam(required=false,name="lng",defaultValue = "1") String language_id) { public ResponseEntity<String> index() {
JSONObject json = new JSONObject(); JSONObject json = new JSONObject();
try { try {
json.put("error_code",0); json.put("error_code",0);
@ -299,13 +295,10 @@ public class MainController implements ServletContextAware {
} catch (JSONException e) { } catch (JSONException e) {
throw new RuntimeException(e); throw new RuntimeException(e);
} }
return json.toString(); return ResponseEntity.ok(json.toString());
} }
/*
@RequestMapping(value = "/get_settings/",method = {RequestMethod.POST,RequestMethod.GET},produces = "application/json;charset=utf-8") @Operation(summary = "Get user settings from the database by their ID from JWT", description = "Get user settings from the database by their ID from JWT")
@ResponseBody
public String get_settings(Model model, @CookieValue(value = "jwt_a", defaultValue = "") String jwt_a,@RequestBody ActionName action_name, @CookieValue(value = "lng", defaultValue = "1") String language_id) {
*/
@RequestMapping(value = "/get_settings",method = {RequestMethod.POST,RequestMethod.GET},produces = "application/json;charset=utf-8") @RequestMapping(value = "/get_settings",method = {RequestMethod.POST,RequestMethod.GET},produces = "application/json;charset=utf-8")
@ResponseBody @ResponseBody
public String get_settings(@CookieValue(value = "jwt_a", defaultValue = "") String jwt_a, @RequestParam(required=false,name="lng",defaultValue = "1") String language_id) { public String get_settings(@CookieValue(value = "jwt_a", defaultValue = "") String jwt_a, @RequestParam(required=false,name="lng",defaultValue = "1") String language_id) {
@ -432,30 +425,44 @@ public class MainController implements ServletContextAware {
return json.toString(); return json.toString();
} }
@RequestMapping(value = "/access",method = {RequestMethod.POST,RequestMethod.GET},produces = "application/json;charset=utf-8") @Operation(
summary = "Get list of permissions",
description = "Get list of permissions for user by Access token",
responses = {
@ApiResponse(
responseCode = "200",
description = "Успешный ответ",
content = @Content(
mediaType = "application/json",
schema = @Schema(implementation = ApiResponseData.class)
)
)
}
)
@RequestMapping(value = "/access",method = {RequestMethod.POST},produces = "application/json;charset=utf-8")
@ResponseBody @ResponseBody
public String access(Model model, @CookieValue(value = "jwt_a", defaultValue = "") String jwt_a,@Nullable @RequestBody ActionName action_name,@CookieValue(value = "lng",defaultValue = "1") String language_id) { public <T> ApiResponseData<T> access(
Model model,
@CookieValue(value = "jwt_a", defaultValue = "") String jwt_a,
@Nullable @RequestBody ActionNameModel action_name,
@CookieValue(value = "lng",defaultValue = "1") String language_id
) {
Translation trt = new Translation(language_id,jdbcTemplate); Translation trt = new Translation(language_id,jdbcTemplate);
String result=createStrJSONError(10000,trt.trt("Request_not_processed"), (String)null, (String)null); ApiResponseData<List<String>> result = null;
try { try {
if(jwt_a.equals("") || countOccurrences(jwt_a, '.')!=2) if(jwt_a.equals("") || countOccurrences(jwt_a, '.')!=2)
{ {
result=createStrJSONError(10000,trt.trt("Please_log_in"), (String)null, (String)null); return ApiResponseData.error(10000, trt.trt("Please_log_in"),null,null);
return result;
} }
//Connection conn = getConnection();
//Проверяю подпись токена //Проверяю подпись токена
Jws<Claims> claims = null; Jws<Claims> claims = null;
//SecretKey key_a = new SecretKeySpec(Base64.getDecoder().decode(key_a_txt), "HmacSHA256");
try { try {
claims = Jwts.parserBuilder() claims = Jwts.parserBuilder()
.setSigningKey(getPublicKey()) //.setSigningKey(key_a) .setSigningKey(getPublicKey())
.build() .build()
.parseClaimsJws(jwt_a); .parseClaimsJws(jwt_a);
} catch (Exception e) { } catch (Exception e) {
return createStrJSONError(10000, trt.trt("JWT_token_verification_error"),(String)null,(String)null); return ApiResponseData.error(10000, trt.trt("JWT_token_verification_error"),null,null);
} }
String sql = """ String sql = """
select select
@ -474,24 +481,19 @@ public class MainController implements ServletContextAware {
if(action_name == null) if(action_name == null)
parameters.addValue("action_name", null); parameters.addValue("action_name", null);
else else
parameters.addValue("action_name", action_name.getActionName()); parameters.addValue("action_name", action_name.getAction_name());
List<String> ret = jdbcTemplate.query(sql, parameters, new DBTools.JsonRowMapper()); List<String> ret = jdbcTemplate.query(sql, parameters, new DBTools.JsonRowMapper());
JSONObject json = new JSONObject(); List<String> data = new ArrayList<>();
json.put("error_code",0); for (String s : ret) {
//json.put("error_message",""); data.add((new JSONObject(s)).getString("name"));
//json.put("error_marker",(String)null);
JSONArray data = new JSONArray();
for (int i = 0; i < ret.size(); i++) {
data.put((new JSONObject(ret.get(i))).getString("name"));
} }
json.put("data",data); result = ApiResponseData.success(data);
result = json.toString();
} catch (Exception e) { } catch (Exception e) {
String uuid = UUID.randomUUID().toString(); String uuid = UUID.randomUUID().toString();
logger.error(uuid,e); logger.error(uuid,e);
result=createStrJSONError(10000,trt.trt("Internal_Server_Error"), (String)null, uuid); return ApiResponseData.error(10000, trt.trt("Internal_Server_Error"),(String)null,uuid);
} }
return result; return (ApiResponseData<T>) result;
} }
@RequestMapping(value = "/captcha",method = {RequestMethod.POST,RequestMethod.GET},produces = "application/json;charset=utf-8") @RequestMapping(value = "/captcha",method = {RequestMethod.POST,RequestMethod.GET},produces = "application/json;charset=utf-8")
@ -748,7 +750,8 @@ public class MainController implements ServletContextAware {
return json.toString(); return json.toString();
} }
@RequestMapping(value = "/login",method = {RequestMethod.POST,RequestMethod.GET},produces = "application/json;charset=utf-8") @Operation(summary = "Login and get JWT token", description = "Login and get JWT token")
@RequestMapping(value = "/login",method = RequestMethod.POST,produces = "application/json;charset=utf-8")
@ResponseBody @ResponseBody
public String login(HttpServletResponse response, HttpServletRequest request, @RequestBody LoginModel loginModel, @CookieValue(value = "lng", defaultValue = "1") String language_id) { public String login(HttpServletResponse response, HttpServletRequest request, @RequestBody LoginModel loginModel, @CookieValue(value = "lng", defaultValue = "1") String language_id) {

View File

@ -1,16 +0,0 @@
package org.ccalm.jwt.models;
//import jakarta.persistence.Column;
import com.fasterxml.jackson.annotation.JsonProperty;
public class ActionName {
//@Column(name = "action_name", nullable = true)
@JsonProperty("action_name")
private String action_name;
public String getActionName() {
return action_name;
}
public void setActionName(String action_name) {
this.action_name = action_name;
}
}

View File

@ -0,0 +1,17 @@
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 ActionNameModel {
@Schema(description = "Action name", example = "arm_")
@JsonProperty("action_name")
private String action_name;
}

View File

@ -0,0 +1,87 @@
package org.ccalm.jwt.models;
import io.swagger.v3.oas.annotations.media.Schema;
import java.util.Arrays;
@Schema(
description = "Стандартный ответ API",
example = "{ \"error_code\": 0, \"error_message\": \"\", \"data\": [\"arm_accounting\", \"arm_carrier\", \"arm_hr\"] }"
)
public class ApiResponseData<T> {
@Schema(description = "Код ошибки", example = "0")
private int errorCode;
@Schema(description = "Сообщение об ошибке", example = "")
private String errorMessage;
@Schema(description = "Параметры для переводимого текста", example = "")
private String errorSetting;
@Schema(description = "Уникальный идентификатор для поиска в базе", example = "")
private String errorMarker;
@Schema(description = "Данные", example = "[\"arm_accounting\", \"arm_carrier\", \"arm_hr\"]")
private T data;
public ApiResponseData() {
}
public ApiResponseData(int errorCode, String errorMessage, String errorSetting, String errorMarker, T data) {
this.errorCode = errorCode;
this.errorMessage = errorMessage;
this.errorSetting = errorSetting;
this.errorMarker = errorMarker;
this.data = data;
}
public static <T> ApiResponseData<T> success(T data) {
return new ApiResponseData<>(0, "","","", data);
}
public static <T> ApiResponseData<T> error(int code, String message, String setting, String marker) {
return new ApiResponseData<>(code, message, setting, marker, null);
}
// Геттеры и сеттеры
public int getErrorCode() {
return errorCode;
}
public void setErrorCode(int errorCode) {
this.errorCode = errorCode;
}
public String getErrorMessage() {
return errorMessage;
}
public void setErrorMessage(String errorMessage) {
this.errorMessage = errorMessage;
}
public void setErrorSetting(String errorSetting) {
this.errorSetting = errorSetting;
}
public String getErrorSetting() {
return errorSetting;
}
public void setErrorMarker(String errorMarker) {
this.errorMarker = errorMarker;
}
public String getErrorMarker() {
return errorMarker;
}
public T getData() {
return data;
}
public void setData(T data) {
this.data = data;
}
}

View File

@ -1,14 +1,10 @@
package org.ccalm.jwt.models; package org.ccalm.jwt.models;
import lombok.Data;
import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.annotation.JsonProperty;
@Data
public class EmailModel { public class EmailModel {
@JsonProperty("email") @JsonProperty("email")
String email; private String email;
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
} }

View File

@ -1,7 +1,9 @@
package org.ccalm.jwt.models; package org.ccalm.jwt.models;
import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.Data;
@Data
public class ErrorModel { public class ErrorModel {
@JsonProperty("timestamp") @JsonProperty("timestamp")
private String timestamp; private String timestamp;

View File

@ -1,5 +1,8 @@
package org.ccalm.jwt.models; package org.ccalm.jwt.models;
import lombok.Data;
@Data
public class LoginModel { public class LoginModel {
//@JsonProperty("login") //@JsonProperty("login")
private String login; private String login;
@ -8,29 +11,4 @@ public class LoginModel {
//@JsonProperty("appid") //@JsonProperty("appid")
private String totp; private String totp;
private String appid; private String appid;
public String getLogin() {
return login;
}
public void setLogin(String login) {
this.login = login;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public String getTotp() { return totp; }
public void setTotp(String totp) {
this.totp = totp;
}
public String getAppid() {
return appid;
}
public void setAppid(String appid) {
this.appid = appid;
}
} }

View File

@ -1,25 +1,13 @@
package org.ccalm.jwt.models; package org.ccalm.jwt.models;
import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.Data;
@Data
public class RestoreModel { public class RestoreModel {
@JsonProperty("code") @JsonProperty("code")
String code; String code;
@JsonProperty("token") @JsonProperty("token")
String token; String token;
public String getCode() {
return code;
}
public void setCode(String code) {
this.code = code;
}
public String getToken() {
return token;
}
public void setToken(String token) {
this.token = token;
}
} }

View File

@ -1,28 +1,13 @@
package org.ccalm.jwt.models; package org.ccalm.jwt.models;
import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.Data;
@Data
public class SettingModel { public class SettingModel {
@JsonProperty("identifier") @JsonProperty("identifier")
private String identifier; private String identifier;
@JsonProperty("value") @JsonProperty("value")
private String value; private String value;
public String getIdentifier() {
return identifier;
}
public void setIdentifier(String identifier) {
this.identifier = identifier;
}
public String getValue() {
return value;
}
public void setValue(String value) {
this.value = value;
}
} }

View File

@ -1,7 +1,9 @@
package org.ccalm.jwt.models; package org.ccalm.jwt.models;
import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.Data;
@Data
public class UserModel { public class UserModel {
@JsonProperty("country_id") @JsonProperty("country_id")
private Long countryId; private Long countryId;
@ -21,76 +23,4 @@ public class UserModel {
private String email; private String email;
@JsonProperty("password") @JsonProperty("password")
private String password; private String password;
public Long getCountryId() {
return countryId;
}
public void setCountryId(Long countryId) {
this.countryId = countryId;
}
public String getCompanyName() {
return companyName;
}
public void setCompanyName(String companyName) {
this.companyName = companyName;
}
public String getPosition() {
return position;
}
public void setPosition(String position) {
this.position = position;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getSurname() {
return surname;
}
public void setSurname(String surname) {
this.surname = surname;
}
public String getPatronymic() {
return patronymic;
}
public void setPatronymic(String patronymic) {
this.patronymic = patronymic;
}
public String getPhone() {
return phone;
}
public void setPhone(String phone) {
this.phone = phone;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
} }