Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
F
formulario-api
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
Denys Tito Urbano
formulario-api
Commits
b8a8936e
Commit
b8a8936e
authored
Dec 06, 2022
by
Mauro Paolo Josue Zuñiga Mallqui
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
changes
parent
d9f407d5
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
20 additions
and
10 deletions
+20
-10
CorsFilter.java
src/main/java/pe/so/api/formulario/filters/CorsFilter.java
+14
-9
PostgreSqlTabla.java
...ava/pe/so/api/formulario/postgresdao/PostgreSqlTabla.java
+6
-1
No files found.
src/main/java/pe/so/api/formulario/filters/CorsFilter.java
View file @
b8a8936e
...
...
@@ -9,6 +9,7 @@ import javax.servlet.http.HttpServletRequest;
import
javax.servlet.http.HttpServletResponse
;
import
javax.ws.rs.ext.Provider
;
import
java.io.IOException
;
import
java.sql.SQLException
;
import
java.util.Arrays
;
import
java.util.concurrent.atomic.AtomicReference
;
...
...
@@ -35,16 +36,20 @@ public class CorsFilter implements Filter{
response
.
setHeader
(
"Access-Control-Allow-Headers"
,
"x-requested-with, Content-Type, Authorization"
);
response
.
setHeader
(
"Access-Control-Allow-Credentials"
,
"true"
);
if
((
response
.
getHeader
(
"Access-Control-Allow-Origin"
).
equals
(
"*"
)
||
response
.
getHeader
(
"Access-Control-Allow-Origin"
).
contains
(
request
.
getRemoteHost
()))
&&
(
Arrays
.
asList
(
ExcelIds
).
contains
(
request
.
getHeader
(
"Authorization"
))
||
existeId
(
request
.
getHeader
(
"Authorization"
)))){
try
{
if
((
response
.
getHeader
(
"Access-Control-Allow-Origin"
).
equals
(
"*"
)
||
response
.
getHeader
(
"Access-Control-Allow-Origin"
).
contains
(
request
.
getRemoteHost
()))
&&
(
Arrays
.
asList
(
ExcelIds
).
contains
(
request
.
getHeader
(
"Authorization"
))
||
existeId
(
request
.
getHeader
(
"Authorization"
)))){
filterChain
.
doFilter
(
servletRequest
,
response
);
}
else
{
filterChain
.
doFilter
(
servletRequest
,
response
);
}
else
{
response
.
setContentType
(
"application/json"
);
response
.
setStatus
(
401
);
response
.
getWriter
().
write
(
"{\"mensaje\":\"No estas autorizado a usar este recurso.\",\"status\":false}"
);
response
.
setContentType
(
"application/json"
);
response
.
setStatus
(
401
);
response
.
getWriter
().
write
(
"{\"mensaje\":\"No estas autorizado a usar este recurso.\",\"status\":false}"
);
}
}
catch
(
SQLException
e
)
{
throw
new
RuntimeException
(
e
);
}
}
...
...
@@ -53,7 +58,7 @@ public class CorsFilter implements Filter{
public
void
destroy
(){
}
private
Boolean
existeId
(
String
id
){
private
Boolean
existeId
(
String
id
)
throws
SQLException
{
AtomicReference
<
Boolean
>
existe
=
new
AtomicReference
<>(
false
);
JSONArray
data
=
new
PostgreSqlTabla
().
tablaIds
(
new
JSONObject
().
put
(
"tabla"
,
"ac_encuesta_plc"
)).
getJSONArray
(
"data"
);
...
...
src/main/java/pe/so/api/formulario/postgresdao/PostgreSqlTabla.java
View file @
b8a8936e
...
...
@@ -6,12 +6,13 @@ import pe.so.api.formulario.dao.TablasDAO;
import
java.sql.Connection
;
import
java.sql.ResultSet
;
import
java.sql.SQLException
;
import
java.sql.Statement
;
public
class
PostgreSqlTabla
implements
TablasDAO
{
@Override
public
JSONObject
tablaIds
(
JSONObject
json
){
public
JSONObject
tablaIds
(
JSONObject
json
)
throws
SQLException
{
JSONArray
data
=
new
JSONArray
();
JSONObject
respuesta
=
new
JSONObject
();
Connection
conexion
=
null
;
...
...
@@ -50,6 +51,10 @@ public class PostgreSqlTabla implements TablasDAO{
}
catch
(
Exception
e
){
respuesta
.
put
(
"mensaje"
,
e
.
getMessage
());
return
respuesta
;
}
finally
{
if
(
conexion
!=
null
)
{
conexion
.
close
();
}
}
...
...
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