Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
Adrian
/
EjemploDAE2020
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
9d3ca8fd
authored
Dec 21, 2020
by
Adrian
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
Añadido edición de detalles de usuario, falta comprobaciones de datos
parent
ada5d79e
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
65 additions
and
4 deletions
src/main/java/es/ujaen/dae/ujacoin/beans/ServicioRestAPI.java
src/main/java/es/ujaen/dae/ujacoin/beans/ServicioSeguridad.java
src/main/java/es/ujaen/dae/ujacoin/beans/ServicioUjaBankImpl.java
src/main/java/es/ujaen/dae/ujacoin/entidades/Cliente.java
src/main/java/es/ujaen/dae/ujacoin/interfaces/ServicioUjaBank.java
src/main/java/es/ujaen/dae/ujacoin/beans/ServicioRestAPI.java
View file @
9d3ca8fd
...
@@ -15,13 +15,12 @@ import java.util.List;
...
@@ -15,13 +15,12 @@ import java.util.List;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.http.HttpStatus
;
import
org.springframework.http.HttpStatus
;
import
org.springframework.http.ResponseEntity
;
import
org.springframework.http.ResponseEntity
;
import
org.springframework.security.core.Authentication
;
import
org.springframework.security.core.context.SecurityContextHolder
;
import
org.springframework.security.core.context.SecurityContextHolder
;
import
org.springframework.security.core.userdetails.UserDetails
;
import
org.springframework.web.bind.annotation.GetMapping
;
import
org.springframework.web.bind.annotation.GetMapping
;
import
org.springframework.web.bind.annotation.PathVariable
;
import
org.springframework.web.bind.annotation.PathVariable
;
import
org.springframework.web.bind.annotation.PutMapping
;
import
org.springframework.web.bind.annotation.RequestBody
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RequestParam
;
import
org.springframework.web.bind.annotation.RestController
;
import
org.springframework.web.bind.annotation.RestController
;
@RestController
@RestController
...
@@ -69,6 +68,32 @@ public class ServicioRestAPI {
...
@@ -69,6 +68,32 @@ public class ServicioRestAPI {
return
new
ResponseEntity
<>(
mapper
.
aClienteDTO
(
cliente
),
HttpStatus
.
OK
);
return
new
ResponseEntity
<>(
mapper
.
aClienteDTO
(
cliente
),
HttpStatus
.
OK
);
}
}
@PutMapping
(
"/clientes/{dni}"
)
public
ResponseEntity
<
ClienteDTO
>
actualizarDetalleCliente
(
@PathVariable
String
dni
,
@RequestBody
ClienteDTO
cliente
)
{
if
(
dni
!=
null
&&
""
.
equals
(
dni
))
{
return
new
ResponseEntity
<>(
HttpStatus
.
BAD_REQUEST
);
}
String
username
=
SecurityContextHolder
.
getContext
().
getAuthentication
().
getName
();
boolean
admin
=
SecurityContextHolder
.
getContext
().
getAuthentication
().
getAuthorities
()
.
stream
().
anyMatch
(
r
->
r
.
getAuthority
().
equals
(
"ROLE_ADMIN"
));
if
(!
admin
&&
!
username
.
equals
(
dni
))
{
return
new
ResponseEntity
<>(
HttpStatus
.
NOT_FOUND
);
}
if
(!
username
.
equals
(
cliente
.
getDni
())){
return
new
ResponseEntity
<>(
HttpStatus
.
FORBIDDEN
);
}
//Comprobar datos entrantes
ujaBank
.
actualizarCliente
(
mapper
.
deClienteDTO
(
cliente
));
return
new
ResponseEntity
<>(
HttpStatus
.
OK
);
}
@GetMapping
(
"/clientes/{dni}/cuentas/{num}"
)
@GetMapping
(
"/clientes/{dni}/cuentas/{num}"
)
public
ResponseEntity
<
CuentaDTO
>
detalleCuenta
(
@PathVariable
String
dni
,
@PathVariable
String
num
)
{
public
ResponseEntity
<
CuentaDTO
>
detalleCuenta
(
@PathVariable
String
dni
,
@PathVariable
String
num
)
{
...
...
src/main/java/es/ujaen/dae/ujacoin/beans/ServicioSeguridad.java
View file @
9d3ca8fd
...
@@ -14,7 +14,6 @@ import org.springframework.security.config.annotation.web.builders.HttpSecurity;
...
@@ -14,7 +14,6 @@ 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.EnableWebSecurity
;
import
org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter
;
import
org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter
;
import
org.springframework.security.crypto.password.NoOpPasswordEncoder
;
import
org.springframework.security.crypto.password.NoOpPasswordEncoder
;
import
org.springframework.security.crypto.password.PasswordEncoder
;
/**
/**
*
*
...
@@ -49,6 +48,9 @@ public class ServicioSeguridad extends WebSecurityConfigurerAdapter {
...
@@ -49,6 +48,9 @@ public class ServicioSeguridad extends WebSecurityConfigurerAdapter {
http
.
authorizeRequests
().
antMatchers
(
HttpMethod
.
DELETE
,
"/ujacoin/clientes/{dni:[\\d+]}/cuentas/{num:[\\d+]}"
).
hasRole
(
"ADMIN"
);
http
.
authorizeRequests
().
antMatchers
(
HttpMethod
.
DELETE
,
"/ujacoin/clientes/{dni:[\\d+]}/cuentas/{num:[\\d+]}"
).
hasRole
(
"ADMIN"
);
http
.
authorizeRequests
().
antMatchers
(
"/ujacoin/clientes/**"
).
hasAnyRole
(
"USER"
,
"ADMIN"
);
http
.
authorizeRequests
().
antMatchers
(
"/ujacoin/clientes/**"
).
hasAnyRole
(
"USER"
,
"ADMIN"
);
http
.
authorizeRequests
().
antMatchers
(
HttpMethod
.
POST
,
"/ujacoin/clientes/**"
).
hasAnyRole
(
"USER"
,
"ADMIN"
);
http
.
authorizeRequests
().
antMatchers
(
HttpMethod
.
PUT
,
"/ujacoin/clientes/**"
).
hasAnyRole
(
"USER"
,
"ADMIN"
);
http
.
authorizeRequests
().
antMatchers
(
HttpMethod
.
DELETE
,
"/ujacoin/clientes/**"
).
hasAnyRole
(
"USER"
,
"ADMIN"
);
http
.
authorizeRequests
().
antMatchers
(
"/ujacoin/enteros/**"
).
permitAll
();
http
.
authorizeRequests
().
antMatchers
(
"/ujacoin/enteros/**"
).
permitAll
();
...
...
src/main/java/es/ujaen/dae/ujacoin/beans/ServicioUjaBankImpl.java
View file @
9d3ca8fd
...
@@ -225,4 +225,19 @@ public class ServicioUjaBankImpl implements ServicioUjaBank {
...
@@ -225,4 +225,19 @@ public class ServicioUjaBankImpl implements ServicioUjaBank {
}
}
@Override
public
Cliente
actualizarCliente
(
Cliente
clienteNuevo
)
{
Cliente
clienteAntiguo
=
repoClientes
.
buscar
(
clienteNuevo
.
getDni
());
clienteAntiguo
.
setDireccion
(
clienteNuevo
.
getDireccion
());
clienteAntiguo
.
setEmail
(
clienteNuevo
.
getEmail
());
clienteAntiguo
.
setTelefono
(
clienteNuevo
.
getTelefono
());
repoClientes
.
actualizar
(
clienteAntiguo
);
return
clienteAntiguo
;
}
}
}
src/main/java/es/ujaen/dae/ujacoin/entidades/Cliente.java
View file @
9d3ca8fd
...
@@ -118,6 +118,18 @@ public class Cliente {
...
@@ -118,6 +118,18 @@ public class Cliente {
return
tarjetasAsociadas
;
return
tarjetasAsociadas
;
}
}
public
void
setDireccion
(
String
direccion
)
{
this
.
direccion
=
direccion
;
}
public
void
setTelefono
(
String
telefono
)
{
this
.
telefono
=
telefono
;
}
public
void
setEmail
(
String
email
)
{
this
.
email
=
email
;
}
/**
/**
* Comprueba si la clave introducida coincide con la guardada
* Comprueba si la clave introducida coincide con la guardada
*
*
...
...
src/main/java/es/ujaen/dae/ujacoin/interfaces/ServicioUjaBank.java
View file @
9d3ca8fd
...
@@ -122,4 +122,11 @@ public interface ServicioUjaBank {
...
@@ -122,4 +122,11 @@ public interface ServicioUjaBank {
*/
*/
public
void
borrarTarjeta
(
int
identificador
);
public
void
borrarTarjeta
(
int
identificador
);
/**
* Actualiza los datos personales de un cliente
* @param clienteNuevo Cliente para actualizar
* @return El cliente actualizado
*/
public
Cliente
actualizarCliente
(
Cliente
clienteNuevo
);
}
}
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