Se corrigen warnings

parent debb86f7
......@@ -22,26 +22,19 @@ dependencies {
implementation 'org.springframework.boot:spring-boot-starter-data-jpa' // Dependencia para la integración de JPA en Spring Boot
implementation 'org.springframework.boot:spring-boot-starter-validation' // Dependencia para la validación de datos en Spring Boot
implementation 'org.springframework.boot:spring-boot-starter-web' // Dependencia para crear aplicaciones web con Spring Boot
implementation 'org.springframework.boot:spring-boot-starter-websocket'
//implementation 'org.springframework.boot:spring-boot-starter-websocket'
implementation 'org.springframework.boot:spring-boot-starter-mail'
implementation 'org.json:json:20210307'
//implementation 'commons-fileupload:commons-fileupload:1.4' // Dependencia para el manejo de archivos en Java
implementation 'com.fasterxml.jackson.dataformat:jackson-dataformat-xml:2.12.5' // Dependencia para el formato XML en Jackson
implementation 'commons-io:commons-io:2.11.0'
implementation 'org.javassist:javassist:3.27.0-GA' // Dependencia para la manipulación de bytecode en Java
implementation 'org.mapstruct:mapstruct:1.4.2.Final'
implementation 'org.modelmapper:modelmapper:3.0.0'// Dependencia para la generación de mappers en Java
implementation 'org.springframework.boot:spring-boot-starter-security' // seguridad de Apis
implementation 'io.jsonwebtoken:jjwt-api:0.11.2'
implementation 'io.jsonwebtoken:jjwt-impl:0.11.2'
implementation 'io.jsonwebtoken:jjwt-jackson:0.11.2'
//
implementation 'org.springframework.boot:spring-boot-starter-oauth2-resource-server'
// Hibernate Oracle Dialect
//implementation 'org.hibernate.dialect:hibernate-oraclendialect:5.6.3.Final'
annotationProcessor 'org.mapstruct:mapstruct-processor:1.4.2.Final' // Procesador de anotaciones para MapStruct
compileOnly 'org.projectlombok:lombok' // Dependencia para generar automáticamente código repetitivo en Java
runtimeOnly 'com.oracle.database.jdbc:ojdbc8' // Dependencia para el controlador JDBC de Oracle
......
......@@ -60,49 +60,5 @@ public class JwtAuthenticationFilter extends OncePerRequestFilter {
filterChain.doFilter(request, response);
}
/*
private UsernamePasswordAuthenticationToken getAuthentication(String token) {
try {
if (tokenEsValido(token)) {
UserDetails userDetails = getUserDetailsFromToken(token);
UsernamePasswordAuthenticationToken authenticationToken = new UsernamePasswordAuthenticationToken(userDetails, null, null);
loggerToken.info("Token válido obtenido en el backend: {}", token);
return authenticationToken;
}
} catch (Exception e) {
}
return null;
}
private boolean tokenEsValido(String token) {
loggerToken.info("token de validación: {}", token);
UserDetails userDetails = getUserDetailsFromToken(token);
boolean isValid = JwtUtils.validateToken(token, userDetails);
loggerToken.info("Resultado de la validación del token: {}", isValid);
return isValid;
}
private UserDetails getUserDetailsFromToken(String token) {
try {
loggerToken.info("Extrayendo detalles del usuario del token: {}", token);
Claims claims = Jwts.parserBuilder()
.setSigningKey(SECRET_KEY)
.build()
.parseClaimsJws(token)
.getBody();
String username = claims.getSubject();
//return new CustomUserDetails(username, "", null);
return new CustomUserDetails(null);
} catch (Exception e) {
}
return null;
}
*/
}
......@@ -21,12 +21,12 @@ public class JwtUserDetailsService implements UserDetailsService {
private final DaoUzyTUsuario userRepository;
@Autowired
UzyTPerfilMapper perfilMapper;
private final UzyTPerfilMapper perfilMapper;
@Autowired
public JwtUserDetailsService(DaoUzyTUsuario userRepository) {
public JwtUserDetailsService(DaoUzyTUsuario userRepository, UzyTPerfilMapper perfilMapper) {
this.userRepository = userRepository;
this.perfilMapper = perfilMapper;
}
@Override
......
package ec.edu.espe.movilidad.MovilidadWS.Security;
import io.jsonwebtoken.Jwts;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.stereotype.Component;
import java.util.Date;
@Component
public class JwtUtils {
public static boolean validateToken(String token, UserDetails userDetails) {
if (token == null) {
System.out.println("Token nullo: " + token);
return false;
}
String username = extractUsername(token);
System.out.println("Token: " + token);
return username.equals(userDetails.getUsername()) && !isTokenExpired(token);
}
public static String extractUsername(String token) {
return Jwts.parserBuilder()
.build()
.parseClaimsJws(token)
.getBody()
.getSubject();
}
public static boolean isTokenExpired(String token) {
return Jwts.parserBuilder()
.build()
.parseClaimsJws(token)
.getBody()
.getExpiration()
.before(new Date());
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment