Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
S
securityRemake
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
Juan Guevara Mayta
securityRemake
Commits
59f6dd99
Commit
59f6dd99
authored
Nov 02, 2023
by
Mauro Paolo Josue Zuñiga Mallqui
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[EDIT] CAMBIOS PARA WILDFLY
parent
0a66c985
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
49 additions
and
8 deletions
+49
-8
pom.xml
pom.xml
+7
-1
RequestsFilter.java
...com/mycompany/moduloseguridad/filters/RequestsFilter.java
+1
-1
LogOutServlet.java
...com/mycompany/moduloseguridad/servlets/LogOutServlet.java
+1
-1
LoginServlet.java
.../com/mycompany/moduloseguridad/servlets/LoginServlet.java
+1
-1
RedireccionarServlet.java
...ompany/moduloseguridad/servlets/RedireccionarServlet.java
+1
-1
UsuarioServlet.java
...om/mycompany/moduloseguridad/servlets/UsuarioServlet.java
+3
-3
HttpRequest.java
.../com/mycompany/moduloseguridad/utilities/HttpRequest.java
+35
-0
No files found.
pom.xml
View file @
59f6dd99
...
...
@@ -81,7 +81,13 @@
<artifactId>
mysql-connector-java
</artifactId>
<version>
5.1.44
</version>
</dependency>
<dependency>
<groupId>
com.squareup.okhttp3
</groupId>
<artifactId>
okhttp
</artifactId>
<version>
4.0.0
</version>
</dependency>
</dependencies>
<build>
...
...
src/main/java/com/mycompany/moduloseguridad/filters/RequestsFilter.java
View file @
59f6dd99
...
...
@@ -65,7 +65,7 @@ public class RequestsFilter implements Filter {
}
else
{
setError
(
response
);
}
respuesta
=
httpRequest
.
getRespuesta
(
RequestPath
.
VERIFICAR_LOGIN
,
HttpRequest
.
POST
,
new
JSONObject
(
"{}"
),
auth
);
respuesta
=
httpRequest
.
securityRequest
(
RequestPath
.
VERIFICAR_LOGIN
,
new
JSONObject
(
"{}"
),
auth
);
valid
=
new
JSONObject
(
respuesta
);
if
(
valid
.
getBoolean
(
"status"
))
{
JSONObject
menu
=
new
JSONObject
(
valid
.
getString
(
"menu"
));
//Obtiene el menu
...
...
src/main/java/com/mycompany/moduloseguridad/servlets/LogOutServlet.java
View file @
59f6dd99
...
...
@@ -28,7 +28,7 @@ public class LogOutServlet extends HttpServlet {
HttpSession
session
=
request
.
getSession
();
String
authorization
=
(
String
)
session
.
getAttribute
(
"Authorization"
);
HttpRequest
postRequest
=
new
HttpRequest
();
String
respuesta
=
postRequest
.
getRespuesta
(
RequestPath
.
LOG_OUT
,
HttpRequest
.
POS
T
,
new
JSONObject
(
"{}"
),
authorization
);
String
respuesta
=
postRequest
.
securityRequest
(
RequestPath
.
LOG_OU
T
,
new
JSONObject
(
"{}"
),
authorization
);
GeneralMethods
.
clearSession
(
request
,
response
);
request
.
getSession
().
removeAttribute
(
"codigo"
);
//
request
.
getSession
().
removeAttribute
(
"Authorization"
);
...
...
src/main/java/com/mycompany/moduloseguridad/servlets/LoginServlet.java
View file @
59f6dd99
...
...
@@ -35,7 +35,7 @@ public class LoginServlet extends HttpServlet {
JSONObject
respuesta
=
null
;
//Adquiere los datos de la respuesta del servidor
HttpRequest
httpRequest
=
new
HttpRequest
();
try
{
String
r
=
httpRequest
.
getRespuesta
(
RequestPath
.
LOGIN
,
HttpRequest
.
POST
,
obj
,
""
);
//Respuesta del server
String
r
=
httpRequest
.
securityRequest
(
RequestPath
.
LOGIN
,
obj
,
""
);
//Respuesta del server
respuesta
=
new
JSONObject
(
r
);
boolean
status
=
respuesta
.
getBoolean
(
"status"
);
responseHelper
.
setStatus
(
status
);
...
...
src/main/java/com/mycompany/moduloseguridad/servlets/RedireccionarServlet.java
View file @
59f6dd99
...
...
@@ -31,7 +31,7 @@ public class RedireccionarServlet extends HttpServlet {
if
(
auth
.
startsWith
(
"Bearer "
))
{
String
codigoProyecto
=
request
.
getParameter
(
"cp"
);
HttpRequest
httpRequest
=
new
HttpRequest
();
String
r
=
httpRequest
.
getRespuesta
(
RequestPath
.
ENVIAR_NUEVO_TOKEN
,
HttpRequest
.
POST
,
new
JSONObject
(
"{codigoProyecto:"
+
codigoProyecto
+
"}"
),
auth
);
String
r
=
httpRequest
.
securityRequest
(
RequestPath
.
ENVIAR_NUEVO_TOKEN
,
new
JSONObject
(
"{codigoProyecto:"
+
codigoProyecto
+
"}"
),
auth
);
JSONObject
respuesta
=
new
JSONObject
(
r
);
if
(
respuesta
.
getBoolean
(
"status"
))
{
HttpSession
session
=
request
.
getSession
();
...
...
src/main/java/com/mycompany/moduloseguridad/servlets/UsuarioServlet.java
View file @
59f6dd99
...
...
@@ -207,7 +207,7 @@ public class UsuarioServlet extends HttpServlet {
JSONObject
respuesta
=
null
;
JSONObject
obj
=
new
JSONObject
();
HttpRequest
httpRequest
=
new
HttpRequest
();
String
r
=
httpRequest
.
getRespuesta
(
RequestPath
.
listarTipoDocumento
,
HttpRequest
.
POST
,
obj
,
""
);
//Respuesta del server
String
r
=
httpRequest
.
securityRequest
(
RequestPath
.
listarTipoDocumento
,
obj
,
""
);
//Respuesta del server
respuesta
=
new
JSONObject
(
r
);
JSONArray
data
=
respuesta
.
getJSONArray
(
"data"
);
for
(
int
i
=
0
;
i
<
data
.
length
();
i
++)
{
...
...
@@ -360,7 +360,7 @@ public class UsuarioServlet extends HttpServlet {
.
put
(
"numeroDocumento"
,
numeroDocumento
)
.
put
(
"estado"
,
"1"
);
HttpRequest
httpRequest
=
new
HttpRequest
();
String
r
=
httpRequest
.
getRespuesta
(
RequestPath
.
listarPersonalPorTipoDocNumDoc
,
HttpRequest
.
POST
,
obj
,
""
);
//Respuesta del server
String
r
=
httpRequest
.
securityRequest
(
RequestPath
.
listarPersonalPorTipoDocNumDoc
,
obj
,
""
);
//Respuesta del server
respuesta
=
new
JSONObject
(
r
);
return
respuesta
;
}
...
...
@@ -370,7 +370,7 @@ public class UsuarioServlet extends HttpServlet {
JSONObject
obj
=
new
JSONObject
()
.
put
(
"tipoDocumento"
,
tipoDocumento
);
HttpRequest
httpRequest
=
new
HttpRequest
();
String
r
=
httpRequest
.
getRespuesta
(
RequestPath
.
listarPersonalPorCodigo
,
HttpRequest
.
POST
,
obj
,
""
);
//Respuesta del server
String
r
=
httpRequest
.
securityRequest
(
RequestPath
.
listarPersonalPorCodigo
,
obj
,
""
);
//Respuesta del server
respuesta
=
new
JSONObject
(
r
);
return
respuesta
;
}
...
...
src/main/java/com/mycompany/moduloseguridad/utilities/HttpRequest.java
View file @
59f6dd99
...
...
@@ -9,6 +9,7 @@ import java.net.MalformedURLException;
import
java.net.URL
;
import
java.nio.charset.StandardCharsets
;
import
okhttp3.*
;
import
org.json.JSONObject
;
public
final
class
HttpRequest
{
...
...
@@ -55,4 +56,37 @@ public final class HttpRequest {
conn
.
disconnect
();
return
respuesta
.
toString
();
}
public
String
securityRequest
(
String
path
,
JSONObject
obj
,
String
authorization
)
{
try
{
OkHttpClient
client
=
new
OkHttpClient
();
String
respuesta
=
""
;
URL
url
=
getConn
(
path
);
System
.
out
.
println
(
url
);
MediaType
JSON
=
MediaType
.
parse
(
"application/json; charset=utf-8"
);
RequestBody
body
=
RequestBody
.
create
(
JSON
,
obj
.
toString
());
Request
request
=
new
Request
.
Builder
()
.
url
(
url
)
.
header
(
"Authorization"
,
authorization
)
.
post
(
body
)
.
build
();
try
(
Response
response
=
client
.
newCall
(
request
).
execute
())
{
if
(
response
.
isSuccessful
())
{
assert
response
.
body
()
!=
null
;
respuesta
=
response
.
body
().
string
();
}
else
{
System
.
out
.
println
(
"Error: "
+
response
.
code
()
+
" - "
+
response
.
message
());
assert
response
.
body
()
!=
null
;
System
.
out
.
println
(
"Response: "
+
response
.
body
().
string
());
}
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
System
.
out
.
println
(
"Error: "
+
e
.
getMessage
());
}
return
respuesta
;
}
catch
(
Exception
ex
)
{
System
.
out
.
println
(
"Error : HttpRequest : "
+
ex
.
getMessage
());
return
null
;
}
}
}
\ No newline at end of file
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