Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
Rubén Ramírez
/
MangAffinity
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
1ad6a309
authored
Feb 24, 2025
by
Rubén Ramírez
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
feat: [ServicioSeguridad]: Añadidas urls
parent
c1dbc3d3
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
32 additions
and
29 deletions
src/main/java/com/ujaen/tfg/mangaffinity/seguridad/ServicioSeguridad.java
src/main/java/com/ujaen/tfg/mangaffinity/seguridad/ServicioSeguridad.java
View file @
1ad6a309
...
...
@@ -20,37 +20,40 @@ public class ServicioSeguridad {
this
.
jwtUtil
=
jwtUtil
;
}
@Bean
public
SecurityFilterChain
securityFilterChain
(
HttpSecurity
http
)
throws
Exception
{
return
http
.
csrf
(
csrf
->
csrf
.
disable
())
.
sessionManagement
(
session
->
session
.
disable
())
.
httpBasic
(
httpBasic
->
httpBasic
.
realmName
(
"mangaffinity"
))
.
authorizeHttpRequests
(
request
->
request
.
requestMatchers
(
HttpMethod
.
POST
,
"/usuarios/{email}"
).
permitAll
()
.
requestMatchers
(
HttpMethod
.
POST
,
"/usuarios/"
).
permitAll
()
.
requestMatchers
(
HttpMethod
.
GET
,
"/recursos/titulo/**"
).
permitAll
()
.
requestMatchers
(
HttpMethod
.
GET
,
"/recursos/autor/**"
).
permitAll
()
.
requestMatchers
(
HttpMethod
.
GET
,
"/recursos/genero/**"
).
permitAll
()
.
requestMatchers
(
HttpMethod
.
GET
,
"/recursos/fecha"
).
permitAll
()
.
requestMatchers
(
HttpMethod
.
GET
,
"/recursos/{id}"
).
permitAll
()
.
requestMatchers
(
HttpMethod
.
GET
,
"/recursos"
).
hasAuthority
(
"ROLE_ADMIN"
)
.
requestMatchers
(
HttpMethod
.
POST
,
"/recursos/"
).
hasAuthority
(
"ROLE_ADMIN"
)
.
requestMatchers
(
HttpMethod
.
PUT
,
"/recursos/{id}"
).
hasAuthority
(
"ROLE_ADMIN"
)
.
requestMatchers
(
HttpMethod
.
DELETE
,
"/recursos/{id}"
).
hasAuthority
(
"ROLE_ADMIN"
)
.
requestMatchers
(
HttpMethod
.
POST
,
"/recursos/{id}/capitulos"
).
hasAuthority
(
"ROLE_ADMIN"
)
.
requestMatchers
(
HttpMethod
.
GET
,
"/recursos/{id}/capitulos"
).
permitAll
()
.
anyRequest
().
authenticated
()
)
.
addFilterBefore
(
new
JwtFilter
(
jwtUtil
),
UsernamePasswordAuthenticationFilter
.
class
)
.
build
();
@Bean
public
SecurityFilterChain
securityFilterChain
(
HttpSecurity
http
)
throws
Exception
{
return
http
.
csrf
(
csrf
->
csrf
.
disable
())
.
sessionManagement
(
session
->
session
.
disable
())
.
httpBasic
(
httpBasic
->
httpBasic
.
realmName
(
"mangaffinity"
))
.
authorizeHttpRequests
(
request
->
request
.
requestMatchers
(
HttpMethod
.
POST
,
"/usuarios/{email}"
).
permitAll
()
.
requestMatchers
(
HttpMethod
.
POST
,
"/usuarios/"
).
permitAll
()
.
requestMatchers
(
HttpMethod
.
GET
,
"/recursos/titulo/**"
).
permitAll
()
.
requestMatchers
(
HttpMethod
.
GET
,
"/recursos/autor/**"
).
permitAll
()
.
requestMatchers
(
HttpMethod
.
GET
,
"/recursos/genero/**"
).
permitAll
()
.
requestMatchers
(
HttpMethod
.
GET
,
"/recursos/fecha"
).
permitAll
()
.
requestMatchers
(
HttpMethod
.
GET
,
"/recursos/{id}"
).
permitAll
()
.
requestMatchers
(
HttpMethod
.
GET
,
"/recursos"
).
hasAuthority
(
"ROLE_ADMIN"
)
.
requestMatchers
(
HttpMethod
.
POST
,
"/recursos/"
).
hasAuthority
(
"ROLE_ADMIN"
)
.
requestMatchers
(
HttpMethod
.
PUT
,
"/recursos/{id}"
).
hasAuthority
(
"ROLE_ADMIN"
)
.
requestMatchers
(
HttpMethod
.
DELETE
,
"/recursos/{id}"
).
hasAuthority
(
"ROLE_ADMIN"
)
.
requestMatchers
(
HttpMethod
.
POST
,
"/recursos/{id}/capitulos"
).
hasAuthority
(
"ROLE_ADMIN"
)
.
requestMatchers
(
HttpMethod
.
GET
,
"/recursos/{id}/capitulos"
).
permitAll
()
// 🔹 Protección de las rutas de la biblioteca (solo usuarios autenticados)
.
requestMatchers
(
HttpMethod
.
POST
,
"/biblioteca/{usuarioId}/recursos/{recursoId}/categoria"
).
authenticated
()
.
requestMatchers
(
HttpMethod
.
GET
,
"/biblioteca/{usuarioId}/recursos/categoria/{categoria}"
).
authenticated
()
.
requestMatchers
(
HttpMethod
.
DELETE
,
"/biblioteca/{usuarioId}/recursos/{recursoId}"
).
authenticated
()
// ✅ Nueva regla
.
requestMatchers
(
HttpMethod
.
PUT
,
"/biblioteca/{usuarioId}/recursos/{recursoId}/categoria"
).
authenticated
()
// ✅ Nueva regla
.
anyRequest
().
authenticated
()
)
.
addFilterBefore
(
new
JwtFilter
(
jwtUtil
),
UsernamePasswordAuthenticationFilter
.
class
)
.
build
();
}
@Bean
public
PasswordEncoder
passwordEncoder
()
{
@Bean
public
PasswordEncoder
passwordEncoder
()
{
return
new
BCryptPasswordEncoder
();
}
}
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