Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
T
trismegisto-services
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Mauro Paolo Josue Zuñiga Mallqui
trismegisto-services
Commits
16329228
Commit
16329228
authored
Dec 21, 2023
by
Mauro Paolo Josue Zuñiga Mallqui
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[ADD] CHANGES
parent
6748b4bb
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
54 additions
and
22 deletions
+54
-22
.gitignore
.gitignore
+1
-0
AppApi.java
src/main/java/web/multitask/app/api/AppApi.java
+2
-3
JwtApi.java
src/main/java/web/multitask/app/api/JwtApi.java
+15
-0
SecurityConfig.java
src/main/java/web/multitask/app/config/SecurityConfig.java
+3
-4
JwtTokenFilter.java
src/main/java/web/multitask/app/filter/JwtTokenFilter.java
+1
-1
Role.java
src/main/java/web/multitask/app/model/Role.java
+8
-7
ProcedureMysql.java
src/main/java/web/multitask/app/mysql/ProcedureMysql.java
+23
-6
application.properties
src/main/resources/application.properties
+1
-1
app.war
target/app.war
+0
-0
No files found.
.gitignore
View file @
16329228
...
...
@@ -31,3 +31,4 @@ build/
### VS Code ###
.vscode/
/target/
src/main/java/web/multitask/app/api/AppApi.java
View file @
16329228
...
...
@@ -23,12 +23,11 @@ public class AppApi {
@PostMapping
(
"/procedure"
)
public
String
callProcedure
(
@RequestBody
String
body
)
{
JSONObject
json
=
new
JSONObject
(
body
);
if
(
json
.
has
(
"procedure"
))
{
try
{
JSONArray
params
=
json
.
isNull
(
"params"
)
?
new
JSONArray
()
:
json
.
getJSONArray
(
"params"
);
JSONObject
response
=
procedureMysql
.
ProcedureExecution
(
json
.
getString
(
"procedure"
),
params
.
toList
().
toArray
());
return
response
.
put
(
"status"
,
true
).
put
(
"message"
,
"Success"
).
toString
();
JSONObject
response
=
procedureMysql
.
ProcedureExecution
(
json
.
getString
(
"procedure"
),
json
.
getString
(
"database"
),
params
.
toList
().
toArray
());
return
response
.
toString
();
}
catch
(
Exception
e
)
{
return
new
JSONObject
().
put
(
"data"
,
new
JSONArray
()).
put
(
"message"
,
e
.
getMessage
()).
put
(
"status"
,
false
).
toString
();
}
...
...
src/main/java/web/multitask/app/api/JwtApi.java
View file @
16329228
...
...
@@ -9,6 +9,9 @@ import web.multitask.app.repository.UserRespository;
import
web.multitask.app.utils.JwtTokenUtil
;
import
java.util.Objects
;
import
org.springframework.web.bind.annotation.PostMapping
;
import
org.springframework.web.bind.annotation.RequestBody
;
@RestController
...
...
@@ -35,4 +38,15 @@ class JwtApi {
}
}
@PostMapping
(
"/validate"
)
public
String
validateToken
(
@RequestBody
String
token
)
{
JSONObject
json
=
new
JSONObject
(
token
);
if
(
jwtTokenUtil
.
validateToken
(
json
.
getString
(
"token"
)))
{
return
new
JSONObject
().
put
(
"message"
,
"Valid Token"
).
put
(
"status"
,
true
).
toString
();
}
else
{
return
new
JSONObject
().
put
(
"message"
,
"Invalid Token"
).
put
(
"status"
,
false
).
toString
();
}
}
}
\ No newline at end of file
src/main/java/web/multitask/app/config/SecurityConfig.java
View file @
16329228
...
...
@@ -5,6 +5,7 @@ import org.springframework.context.annotation.Configuration;
import
org.springframework.http.HttpMethod
;
import
org.springframework.security.authentication.AuthenticationManager
;
import
org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder
;
import
org.springframework.security.config.annotation.authentication.configuration.AuthenticationConfiguration
;
import
org.springframework.security.config.annotation.web.builders.HttpSecurity
;
import
org.springframework.security.config.annotation.web.configuration.EnableWebSecurity
;
import
org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter
;
...
...
@@ -16,7 +17,6 @@ import org.springframework.web.cors.CorsConfiguration;
import
org.springframework.web.cors.UrlBasedCorsConfigurationSource
;
import
org.springframework.web.filter.CorsFilter
;
import
org.springframework.web.filter.OncePerRequestFilter
;
import
web.multitask.app.filter.JwtTokenFilter
;
import
web.multitask.app.repository.UserRespository
;
import
web.multitask.app.utils.JwtTokenUtil
;
...
...
@@ -34,9 +34,8 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter {
}
@Bean
@Override
public
AuthenticationManager
authenticationManagerBean
()
throws
Exception
{
return
super
.
authenticationManagerBean
();
public
AuthenticationManager
authenticationManager
(
AuthenticationConfiguration
authenticationConfiguration
)
throws
Exception
{
return
authenticationConfiguration
.
getAuthenticationManager
();
}
@Override
...
...
src/main/java/web/multitask/app/filter/JwtTokenFilter.java
View file @
16329228
...
...
@@ -53,7 +53,7 @@ public class JwtTokenFilter extends OncePerRequestFilter {
UsernamePasswordAuthenticationToken
authentication
=
new
UsernamePasswordAuthenticationToken
(
userDetails
,
null
,
userDetails
.
getAuthorities
());
authentication
.
setDetails
(
new
WebAuthenticationDetailsSource
().
buildDetails
(
request
));
SecurityContextHolder
.
getContext
().
setAuthentication
(
authentication
);
response
.
setStatus
(
200
,
"OK"
);
response
.
setStatus
(
200
);
chain
.
doFilter
(
request
,
response
);
}
else
{
response
.
sendError
(
401
,
"Invalid Token"
);
...
...
src/main/java/web/multitask/app/model/Role.java
View file @
16329228
package
web
.
multitask
.
app
.
model
;
;
import
javax.persistence.*
;
import
lombok.Data
;
import
lombok.Getter
;
import
lombok.NoArgsConstructor
;
import
lombok.NonNull
;
import
lombok.Setter
;
import
javax.persistence.*
;
@Entity
@Table
(
name
=
"roles"
)
@Data
@NoArgsConstructor
@Getter
@Setter
@Entity
(
name
=
"roles"
)
public
class
Role
{
@NonNull
@Id
@GeneratedValue
(
strategy
=
GenerationType
.
AUTO
)
private
int
id
;
...
...
src/main/java/web/multitask/app/mysql/ProcedureMysql.java
View file @
16329228
...
...
@@ -7,7 +7,6 @@ import org.springframework.stereotype.Service;
import
java.util.List
;
import
java.util.Map
;
import
java.util.logging.Logger
;
@Service
public
class
ProcedureMysql
{
...
...
@@ -18,15 +17,34 @@ public class ProcedureMysql {
this
.
jdbcTemplate
=
jdbcTemplate
;
}
public
JSONObject
ProcedureExecution
(
String
query
,
Object
[]
params
)
{
public
JSONObject
ProcedureExecution
(
String
procedure
,
String
database
,
Object
[]
params
)
{
try
{
List
<
Map
<
String
,
Object
>>
list
=
jdbcTemplate
.
queryForList
(
query
,
params
);
StringBuilder
query
=
new
StringBuilder
(
"CALL "
+
database
+
"."
+
procedure
);
if
(
params
.
length
>
0
)
{
query
.
append
(
"("
);
for
(
int
i
=
0
;
i
<
params
.
length
;
i
++)
{
query
.
append
(
"?"
);
if
(
i
<
params
.
length
-
1
)
{
query
.
append
(
","
);
}
}
query
.
append
(
")"
);
}
String
checkProcedure
=
"SELECT COUNT(*) FROM information_schema.routines WHERE routine_schema = '"
+
database
+
"' AND routine_name = '"
+
procedure
+
"'"
;
List
<
Map
<
String
,
Object
>>
countProcedure
=
jdbcTemplate
.
queryForList
(
checkProcedure
);
if
(
countProcedure
.
get
(
0
).
get
(
"COUNT(*)"
).
toString
().
equals
(
"0"
))
{
return
new
JSONObject
().
put
(
"message"
,
"Procedure not found"
).
put
(
"status"
,
false
);
}
List
<
Map
<
String
,
Object
>>
list
=
jdbcTemplate
.
queryForList
(
query
.
toString
(),
params
);
JSONObject
result
=
new
JSONObject
();
result
.
put
(
"data"
,
list
);
return
result
;
}
catch
(
Exception
e
)
{
Logger
.
getLogger
(
"ProcedureMysql"
).
warning
(
e
.
getMessage
()
);
return
new
JSONObject
().
put
(
"data"
,
new
JSONObject
()).
put
(
"message"
,
e
.
getMessage
()).
put
(
"status"
,
false
);
}
return
null
;
}
}
\ No newline at end of file
src/main/resources/application.properties
View file @
16329228
...
...
@@ -2,7 +2,7 @@ spring.datasource.url=jdbc:mysql://13.59.147.125:3306/security
spring.datasource.username
=
server
spring.datasource.password
=
asd123
spring.datasource.driverClassName
=
com.mysql.cj.jdbc.Driver
server.port
=
808
0
server.port
=
808
1
server.address
=
0.0.0.0
spring.jpa.show-sql
=
true
app.jwtSecret
=
9a4f2c8d3b7a1e6f45c8a0b3f267d8b1d4e6f3c8a9d2b5f8e3a9c8b5f6v8a3d9
...
...
target/app.war
deleted
100644 → 0
View file @
6748b4bb
File deleted
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment