Integra panel admin en seguridad y corrige carga de usuarios con JWT2
Some checks failed
Deploy Spring Boot App / build-and-deploy (push) Has been cancelled
Some checks failed
Deploy Spring Boot App / build-and-deploy (push) Has been cancelled
This commit is contained in:
@@ -49,6 +49,7 @@ public class SecurityConfig {
|
|||||||
.requestMatchers(HttpMethod.POST, "/api/usuarios/registrar").permitAll()
|
.requestMatchers(HttpMethod.POST, "/api/usuarios/registrar").permitAll()
|
||||||
.requestMatchers("/api/usuarios/**").permitAll()
|
.requestMatchers("/api/usuarios/**").permitAll()
|
||||||
.requestMatchers("/favicon.ico", "/error", "/static/**", "/contador/**").permitAll()
|
.requestMatchers("/favicon.ico", "/error", "/static/**", "/contador/**").permitAll()
|
||||||
|
.requestMatchers("/panel", "/panel/**").permitAll()
|
||||||
.requestMatchers("/admin/**").hasAuthority("ADMIN")
|
.requestMatchers("/admin/**").hasAuthority("ADMIN")
|
||||||
.anyRequest().authenticated()
|
.anyRequest().authenticated()
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -0,0 +1,31 @@
|
|||||||
|
package com.example.fercoganbackend.configuration;
|
||||||
|
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
import org.springframework.core.io.ClassPathResource;
|
||||||
|
import org.springframework.core.io.Resource;
|
||||||
|
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
|
||||||
|
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
|
||||||
|
import org.springframework.web.servlet.resource.PathResourceResolver;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
@Configuration
|
||||||
|
public class SpaPanelConfig implements WebMvcConfigurer {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void addResourceHandlers(ResourceHandlerRegistry registry) {
|
||||||
|
registry.addResourceHandler("/panel/**")
|
||||||
|
.addResourceLocations("classpath:/static/panel/")
|
||||||
|
.resourceChain(true)
|
||||||
|
.addResolver(new PathResourceResolver() {
|
||||||
|
@Override
|
||||||
|
protected Resource getResource(String resourcePath, Resource location) throws IOException {
|
||||||
|
Resource requested = location.createRelative(resourcePath);
|
||||||
|
if (requested.exists() && requested.isReadable()) {
|
||||||
|
return requested;
|
||||||
|
}
|
||||||
|
return new ClassPathResource("/static/panel/index.html");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,5 +1,6 @@
|
|||||||
package com.example.fercoganbackend.entity;
|
package com.example.fercoganbackend.entity;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||||
import jakarta.persistence.*;
|
import jakarta.persistence.*;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
@@ -10,6 +11,7 @@ public class Usuario {
|
|||||||
private Long id;
|
private Long id;
|
||||||
|
|
||||||
private String username;
|
private String username;
|
||||||
|
@JsonProperty(access = JsonProperty.Access.WRITE_ONLY)
|
||||||
private String password;
|
private String password;
|
||||||
|
|
||||||
@Column(nullable = false)
|
@Column(nullable = false)
|
||||||
|
|||||||
@@ -38,13 +38,17 @@ public class UsuarioDetailsService implements UserDetailsService {
|
|||||||
logger.info("Usuario encontrado: {}, aprobado: {}", usuario.getUsername(), usuario.isAprobado());
|
logger.info("Usuario encontrado: {}, aprobado: {}", usuario.getUsername(), usuario.isAprobado());
|
||||||
logger.info("Roles del usuario: {}", usuario.getRoles());
|
logger.info("Roles del usuario: {}", usuario.getRoles());
|
||||||
|
|
||||||
|
var authorities = usuario.getRoles() == null
|
||||||
|
? List.<SimpleGrantedAuthority>of()
|
||||||
|
: usuario.getRoles().stream()
|
||||||
|
.map(r -> new SimpleGrantedAuthority(r.name()))
|
||||||
|
.toList();
|
||||||
|
|
||||||
return new org.springframework.security.core.userdetails.User(
|
return new org.springframework.security.core.userdetails.User(
|
||||||
usuario.getUsername(),
|
usuario.getUsername(),
|
||||||
usuario.getPassword(),
|
usuario.getPassword(),
|
||||||
usuario.isAprobado(), true, true, true,
|
usuario.isAprobado(), true, true, true,
|
||||||
usuario.getRoles().stream()
|
authorities
|
||||||
.map(r -> new SimpleGrantedAuthority(r.name()))
|
|
||||||
.toList()
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
0
src/main/resources/static/panel/.gitkeep
Normal file
0
src/main/resources/static/panel/.gitkeep
Normal file
Reference in New Issue
Block a user