Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
D
DemoRest
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
Percy Quispe Huarcaya
DemoRest
Commits
95cd8819
Commit
95cd8819
authored
Apr 23, 2018
by
Percy Quispe
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Correcciones
parent
6e93dd29
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
65 additions
and
15 deletions
+65
-15
PersonaBean.java
src/java/demojsoncrud/beans/PersonaBean.java
+0
-0
RequestFilter.java
src/java/demojsoncrud/servlets/RequestFilter.java
+47
-4
general.js
web/js/general.js
+9
-1
consultaUbigeo.js
web/js/pages/consultaUbigeo.js
+0
-1
validate.js
web/js/pages/validate.js
+9
-9
No files found.
src/java/demojsoncrud/beans/PersonaBean.java
View file @
95cd8819
src/java/demojsoncrud/servlets/RequestFilter.java
View file @
95cd8819
...
...
@@ -4,6 +4,7 @@ import demojsoncrud.utilities.PostRequest;
import
java.io.IOException
;
import
java.io.PrintWriter
;
import
java.net.URLEncoder
;
import
java.util.List
;
import
javax.servlet.Filter
;
import
javax.servlet.FilterChain
;
import
javax.servlet.FilterConfig
;
...
...
@@ -16,11 +17,14 @@ import javax.servlet.ServletResponse;
import
javax.servlet.annotation.WebFilter
;
import
javax.servlet.http.HttpServletRequest
;
import
javax.servlet.http.HttpServletResponse
;
import
javax.ws.rs.WebApplicationException
;
import
javax.ws.rs.core.Response
;
import
org.json.JSONArray
;
import
org.json.JSONObject
;
@WebFilter
(
"/*"
)
public
class
RequestFilter
implements
Filter
,
ServletContextListener
{
private
final
String
BASE
=
"http://localhost:8080/proyecto-estandar/"
;
@Override
public
void
init
(
FilterConfig
filterConfig
)
throws
ServletException
{
...
...
@@ -35,14 +39,16 @@ public class RequestFilter implements Filter, ServletContextListener {
String
indexPath
=
"http://localhost:8080/proyecto-estandar/vistas/index.jsp"
;
String
index
=
"vistas/index.jsp"
;
String
urlRequested
=
"http://172.16.2.53:8080/security-rest/api/user/verificarLogin"
;
if
(
String
.
valueOf
(
request
.
getRequestURL
()).
contains
(
"http://localhost:8080/proyecto-estandar/"
))
{
System
.
out
.
println
(
"URI "
+
request
.
getRequestURI
());
if
(
String
.
valueOf
(
request
.
getRequestURL
()).
contains
(
BASE
))
{
String
login
=
request
.
getContextPath
()
+
"/vistas/index.jsp"
;
String
main
=
request
.
getContextPath
()
+
"/vistas/main.jsp"
;
String
plantilla
=
request
.
getContextPath
()
+
"/plantilla"
;
String
js
=
request
.
getContextPath
()
+
"/js"
;
String
url
=
String
.
valueOf
(
request
.
getRequestURL
());
if
(
url
.
contains
(
login
)
||
url
.
contains
(
plantilla
)
||
url
.
contains
(
js
)
||
url
.
contains
(
main
)
||
url
.
contains
(
".jsp"
))
{
if
(
url
.
contains
(
login
)
||
url
.
contains
(
plantilla
)
||
url
.
contains
(
js
)||
url
.
contains
(
"index.jsp"
)||
url
.
contains
(
"main.jsp"
)
||
url
.
contains
(
BASE
))
{
chain
.
doFilter
(
request
,
response
);
}
else
{
String
auth
=
request
.
getHeader
(
"Authorization"
);
...
...
@@ -50,6 +56,29 @@ public class RequestFilter implements Filter, ServletContextListener {
respuesta
=
postRequest
.
getRespueta
(
auth
);
JSONObject
valid
=
new
JSONObject
(
respuesta
);
if
(
valid
.
getBoolean
(
"status"
))
{
JSONObject
menu
=
new
JSONObject
(
valid
.
getString
(
"menu"
));
//Obtiene el menu
JSONArray
views
=
new
JSONArray
(
menu
.
get
(
"vistas"
).
toString
());
//Obtiene las vistas disponibles del usuario
List
<
Object
>
salida
=
views
.
toList
();
String
ruta
=
request
.
getRequestURI
();
int
indice
=
obtenerIndex
(
ruta
);
String
rutaJsp
=
ruta
.
substring
(
indice
,
ruta
.
length
());
boolean
acceso
=
false
;
for
(
Object
vista
:
views
){
System
.
out
.
println
(
"Vista : "
+
vista
+
"rutaJSP : "
+
rutaJsp
);
if
(
vista
.
toString
().
equalsIgnoreCase
(
rutaJsp
)){
acceso
=
true
;
}
}
if
(!
acceso
){
Response
.
ResponseBuilder
builder
=
null
;
response
.
setStatus
(
HttpServletResponse
.
SC_UNAUTHORIZED
);
response
.
sendError
(
401
);
builder
=
Response
.
status
(
Response
.
Status
.
UNAUTHORIZED
).
entity
(
response
);
throw
new
WebApplicationException
(
builder
.
build
());
}
// List<String> views = (List<String>) ;
chain
.
doFilter
(
request
,
response
);
}
else
{
response
.
setStatus
(
HttpServletResponse
.
SC_UNAUTHORIZED
);
...
...
@@ -61,6 +90,20 @@ public class RequestFilter implements Filter, ServletContextListener {
response
.
sendError
(
401
);
}
}
private
int
obtenerIndex
(
String
ruta
){
char
[]
c
=
ruta
.
toCharArray
();
int
salida
=
0
;
for
(
int
i
=
c
.
length
-
1
;
i
>=
0
;
i
--)
{
String
help
=
c
[
i
]+
""
;
if
(!
help
.
equals
(
"/"
)){
salida
=
i
;
}
else
{
break
;
}
}
return
salida
;
}
@Override
public
void
destroy
()
{
...
...
web/js/general.js
View file @
95cd8819
...
...
@@ -68,8 +68,16 @@ let getClosest = (elem, selector) => {
return
null
}
let
logOut
=
()
=>
{
document
.
querySelector
(
'#logOut'
).
addEventListener
(
'click'
,
(
e
)
=>
{
Cookies
.
clear
(
"menu"
);
Cookies
.
clear
(
"Authorization"
);
// location.reload();
window
.
location
.
href
=
'index.jsp'
})
}
logOut
();
//document.querySelector('#logOut').addEventListener('click', (e) => {
// Cookies.clear('Authorization')
// Cookies.clear('menu')
...
...
web/js/pages/consultaUbigeo.js
View file @
95cd8819
...
...
@@ -119,7 +119,6 @@ ubigeo
})
.
catch
(
err
=>
{
console
.
log
(
err
)
debugger
window
.
location
.
replace
(
"http://localhost:8080/proyecto-estandar/vistas/index.jsp"
);
//window.location.href("http://localhost:8080/proyecto-estandar/vistas/index.jsp");
...
...
web/js/pages/validate.js
View file @
95cd8819
/
//
* global Cookies */
//
((window, Cookies) => {
//
console.log(Cookies.get('Authorization'))
//
if (Cookies.get('Authorization') === undefined) {
//
window.location.href = "index.jsp"
//
} else {
//
console.log("Estas logueado")
//
}
//
})(window, Cookies);
/* global Cookies */
((
window
,
Cookies
)
=>
{
console
.
log
(
Cookies
.
get
(
'Authorization'
))
if
(
Cookies
.
get
(
'Authorization'
)
===
undefined
)
{
window
.
location
.
href
=
"index.jsp"
}
else
{
console
.
log
(
"Estas logueado"
)
}
})(
window
,
Cookies
);
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